Skip to content

Latest commit

 

History

History
61 lines (50 loc) · 971 Bytes

ex13-1.md

File metadata and controls

61 lines (50 loc) · 971 Bytes

13.1 Refactoring Data

Example

import 'package:flutter/material.dart';

void main() {
    runApp(MyApp());
}

class MyData {
    final List<String> items = [
    'January',
    'February',
    'March',
    'April',
    'May',
    'June',
    'July',
    'August',
    'September',
    'October',
    'November',
    'December'
  ];

  MyData();
}

class MyApp extends StatelessWidget {
  MyApp({Key? key}) : super(key: key);
  final MyData data = MyData();


  @override
  Widget build(BuildContext context) {

    const title = 'MyAwesome App';
    List items = data.items;

    return MaterialApp(
      title: title,
      home: Scaffold(
        appBar: AppBar(
          title: const Text(title),
        ),
        body: ListView.builder(
          itemCount: items.length,
          itemBuilder: (context, index) {
            return ListTile(
              title: Text(items[index]),
            );
          },
        ),
      ),
    );
  }
}