Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update ex10-1.md #53

Merged
merged 1 commit into from
Dec 16, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 14 additions & 43 deletions ch10/ex10-1.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,45 +7,38 @@ import 'package:flutter/material.dart';

class ListTileItem {
final String monthItem;

const ListTileItem({
required this.monthItem,
});
}

class ListDataItems {
final List<ListTileItem> monthItems = [
const ListTileItem(monthItem: 'January'),
const ListTileItem(monthItem: 'February'),
const ListTileItem(monthItem: 'March'),
const ListTileItem(monthItem: 'April'),
const ListTileItem(monthItem: 'May'),
const ListTileItem(monthItem: 'June'),
const ListTileItem(monthItem: 'July'),
const ListTileItem(monthItem: 'August'),
const ListTileItem(monthItem: 'September'),
const ListTileItem(monthItem: 'October'),
const ListTileItem(monthItem: 'November'),
const ListTileItem(monthItem: 'December'),
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(
Expand All @@ -58,40 +51,18 @@ class MyApp extends StatelessWidget {
}
}


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 MyListTile(item.monthItems[index]);
return ListTile(title: Text(item.monthItems[index]));
},
);
}
}

class MyListTile extends StatelessWidget {
const MyListTile(this.item);

final ListTileItem item;

@override
Widget build(BuildContext context) {
return ListTile(
title: Text(item.monthItem),
onTap: () {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
content: Text('You selected ${item.monthItem}'),
),
);
},
);
}
}
```