diff --git a/namer_app/lib/main.dart b/namer_app/lib/main.dart index 0584d75..65cf4eb 100644 --- a/namer_app/lib/main.dart +++ b/namer_app/lib/main.dart @@ -26,13 +26,24 @@ class MyApp extends StatelessWidget { } class MyAppState extends ChangeNotifier { - var current = WordPair.random();// ... + var current = WordPair.random(); - // ↓ Add this. void getNext() { current = WordPair.random(); notifyListeners(); } + + var favorites = []; + + void toggleFavorite() { + if (favorites.contains(current)) { + favorites.remove(current); + } else { + favorites.add(current); + } + notifyListeners(); + print("Favorites are: ${favorites.toString()}"); + } } class MyHomePage extends StatelessWidget { @@ -41,6 +52,13 @@ class MyHomePage extends StatelessWidget { var appState = context.watch(); var pair = appState.current; + IconData icon; + if (appState.favorites.contains(pair)) { + icon = Icons.favorite; + } else { + icon = Icons.favorite_border; + } + return Scaffold( body: Center( child: Column( @@ -48,11 +66,26 @@ class MyHomePage extends StatelessWidget { children: [ BigCard(pair: pair), SizedBox(height: 10.0), // Just a spacer. - ElevatedButton( - onPressed: () { - appState.getNext(); - }, - child: Text('Next'), + Row( + mainAxisSize: MainAxisSize.min, + children: [ + ElevatedButton.icon( + onPressed: () { + appState.toggleFavorite(); + }, + icon: Icon(icon), + label: Text('Favorite'), + ), + + SizedBox(width: 10.0), + + ElevatedButton( + onPressed: () { + appState.getNext(); + }, + child: Text('Next'), + ), + ], ), ], ),