diff --git a/lib/main.dart b/lib/main.dart index 739e020..ee2dc3d 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -17,7 +17,7 @@ class MyApp extends StatelessWidget { title: 'Namer App', theme: ThemeData( useMaterial3: true, - colorScheme: ColorScheme.fromSeed(seedColor: Colors.green), + colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepOrange), ), home: MyHomePage(), ), @@ -27,11 +27,21 @@ class MyApp extends StatelessWidget { class MyAppState extends ChangeNotifier { var current = WordPair.random(); + var favourites = []; void getNext() { current = WordPair.random(); notifyListeners(); } + + void toggleFavourites() { + if (favourites.contains(current)) { + favourites.remove(current); + } else { + favourites.add(current); + } + notifyListeners(); + } } class BigCard extends StatelessWidget { @@ -53,31 +63,94 @@ class BigCard extends StatelessWidget { color: theme.colorScheme.primary, child: Padding( padding: const EdgeInsets.all(20.0), - child: Text(pair.asLowerCase, style: style), + child: Text(pair.asLowerCase, + semanticsLabel: "${pair.first} ${pair.second}", style: style), ), ); } } +// ... + class MyHomePage extends StatelessWidget { @override Widget build(BuildContext context) { - var appState = context.watch(); - var pair = appState.current; - return Scaffold( - body: Column( + body: Row( children: [ - Text('A random idea:'), - BigCard(pair: pair), - ElevatedButton( - onPressed: () { - appState.getNext(); - }, - child: Text('Next'), + SafeArea( + child: NavigationRail( + extended: true, + destinations: [ + NavigationRailDestination( + icon: Icon(Icons.home), + label: Text('Home'), + ), + NavigationRailDestination( + icon: Icon(Icons.favorite), + label: Text('Favorites'), + ), + ], + selectedIndex: 0, + onDestinationSelected: (value) { + print('selected: $value'); + }, + ), + ), + Expanded( + child: Container( + color: Theme.of(context).colorScheme.primaryContainer, + child: GeneratorPage(), + ), ), ], ), ); } } + +class GeneratorPage extends StatelessWidget { + @override + Widget build(BuildContext context) { + var appState = context.watch(); + var pair = appState.current; + + IconData icon; + if (appState.favourites.contains(pair)) { + icon = Icons.favorite; + } else { + icon = Icons.favorite_border; + } + + return Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + BigCard(pair: pair), + SizedBox(height: 10), + Row( + mainAxisSize: MainAxisSize.min, + children: [ + ElevatedButton.icon( + onPressed: () { + appState.toggleFavourites(); + }, + icon: Icon(icon), + label: Text('Like'), + ), + SizedBox(width: 10), + ElevatedButton( + onPressed: () { + appState.getNext(); + }, + child: Text('Next'), + ), + ], + ), + ], + ), + ); + } +} + +// ...