diff --git a/lib/main.dart b/lib/main.dart index 139467226a9de316215e9d5d9962bc2557a4cb66..b4643af08ca4f51b6275163a3b599bb5b987af85 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -32,6 +32,18 @@ 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,6 +52,14 @@ 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( @@ -48,7 +68,13 @@ class MyHomePage extends StatelessWidget { // 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'),), + ElevatedButton(onPressed: (){appState.getNext();}, child: Text('Next'),), + ], + ), ], ), ),