diff --git a/lib/main.dart b/lib/main.dart index 0007bda4a3add93c90a2863380bd49efaac7fe03..3e22e69bf209648b3921ca9cb94bfa2a6e29ad3b 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -32,6 +32,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 { @@ -40,19 +51,39 @@ 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( mainAxisAlignment: MainAxisAlignment.center, children: [ - Text('A random AWESOME idea:'), 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'), + ), + ], ), ], ),