Skip to content
Snippets Groups Projects
Commit 6fb245dc authored by 2ju0123's avatar 2ju0123
Browse files

codelab8

parent 31b917fb
Branches
No related tags found
No related merge requests found
......@@ -45,8 +45,6 @@ class MyAppState extends ChangeNotifier {
}
}
// ...
class MyHomePage extends StatefulWidget {
@override
State<MyHomePage> createState() => _MyHomePageState();
......@@ -64,7 +62,7 @@ class _MyHomePageState extends State<MyHomePage> {
page = GeneratorPage();
break;
case 1:
page = Placeholder();
page = FavoritesPage();
break;
default:
throw UnimplementedError('no widget for $selectedIndex');
......@@ -109,6 +107,34 @@ class _MyHomePageState extends State<MyHomePage> {
}
}
class FavoritesPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
var appState = context.watch<MyAppState>();
if (appState.favorites.isEmpty) {
return Center(
child: Text('No favorites yet.'),
);
}
return ListView(
children: [
Padding(
padding: const EdgeInsets.all(20),
child: Text('You have '
'${appState.favorites.length} favorites:'),
),
for (var pair in appState.favorites)
ListTile(
leading: Icon(Icons.favorite),
title: Text(pair.asLowerCase),
),
],
);
}
}
class GeneratorPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment