diff --git a/lib/main.dart b/lib/main.dart index 831f8c3ee52bc3e2df019bbf3b1cce0e01098b20..ac9092a7340945b0127d51a36a24224a0c82b5fd 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -31,6 +31,17 @@ class MyAppState extends ChangeNotifier { current = WordPair.random(); notifyListeners(); } + + var favorites = <WordPair>[]; + + void toggleFavorite() { + if (favorites.contains(current)) { + favorites.remove(current); + } else { + favorites.add(current); + } + notifyListeners(); + } } class MyHomePage extends StatelessWidget { @@ -39,6 +50,13 @@ class MyHomePage extends StatelessWidget { var appState = context.watch<MyAppState>(); 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( @@ -46,11 +64,24 @@ class MyHomePage extends StatelessWidget { children: [ BigCard(pair: pair), SizedBox(height: 10), - ElevatedButton( - onPressed: () { - appState.getNext(); - }, - child: Text('Next'), + Row( + mainAxisSize: MainAxisSize.min, + children: [ + ElevatedButton.icon( + onPressed: () { + appState.toggleFavorite(); + }, + icon: Icon(icon), + label: Text('Like'), + ), + SizedBox(width: 10), + ElevatedButton( + onPressed: () { + appState.getNext(); + }, + child: Text('Next'), + ), + ], ), ], ),