From 7b1f41b38fd50f2194ca736002404ecedb74b248 Mon Sep 17 00:00:00 2001 From: Dawn Rose <63545980+tastethedream@users.noreply.github.com> Date: Tue, 6 Dec 2022 15:12:27 +0000 Subject: [PATCH] Update ex10-1.md Code changed to reflect QC2 section 11.1 --- ch10/ex10-1.md | 57 +++++++++++++------------------------------------- 1 file changed, 14 insertions(+), 43 deletions(-) diff --git a/ch10/ex10-1.md b/ch10/ex10-1.md index c5ae2c9..bef3454 100644 --- a/ch10/ex10-1.md +++ b/ch10/ex10-1.md @@ -7,45 +7,38 @@ import 'package:flutter/material.dart'; class ListTileItem { final String monthItem; - const ListTileItem({ required this.monthItem, }); } class ListDataItems { - final List 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 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( @@ -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}'), - ), - ); - }, - ); - } -} ```