Compare commits

...

2 Commits

View File

@ -64,7 +64,7 @@ class _MyHomePageState extends State<MyHomePage> {
page = GeneratorPage(); page = GeneratorPage();
break; break;
case 1: case 1:
page = Placeholder(); page = FavoritesPage();
break; break;
default: default:
throw UnimplementedError('no widget for $selectedIndex'); throw UnimplementedError('no widget for $selectedIndex');
@ -110,6 +110,38 @@ class _MyHomePageState extends State<MyHomePage> {
} }
} }
class FavoritesPage extends StatelessWidget {
const FavoritesPage({
super.key,
});
@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 { class GeneratorPage extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {