11.1 Implementing a vertical list
import 'package:flutter/material.dart' ;
class ListTileItem {
final String monthItem;
const ListTileItem ({
required this .monthItem,
});
}
class ListDataItems {
final List <String > monthItems = [
'January' ,
'February' ,
'March' ,
'April' ,
'May' ,
'June' ,
'July' ,
'August' ,
'September' ,
'October' ,
'November' ,
'December' ,
];
ListDataItems ();
}
void main () {
runApp (const MyApp ());
}
class MyApp extends StatelessWidget {
const MyApp ({Key ? key}) : super (key: key);
@override
Widget build (BuildContext context) {
const title = 'MyAwesome App' ;
return MaterialApp (
title: title,
home: Scaffold (
appBar: AppBar (
title: const Text (title),
),
body: MyListView (),
),
);
}
}
class MyListView extends StatelessWidget {
MyListView ();
final ListDataItems item = ListDataItems ();
@override
Widget build (BuildContext context) {
return ListView .builder (
itemCount: item.monthItems.length,
itemBuilder: (context, index) {
return ListTile (title: Text (item.monthItems[index]));
},
);
}
}