Skip to content
Snippets Groups Projects
Commit 7f006f21 authored by RyuZU's avatar RyuZU
Browse files

6

parent 9ca23e4e
No related branches found
No related tags found
No related merge requests found
...@@ -32,6 +32,18 @@ class MyAppState extends ChangeNotifier { ...@@ -32,6 +32,18 @@ class MyAppState extends ChangeNotifier {
current = WordPair.random(); current = WordPair.random();
notifyListeners(); notifyListeners();
} }
var favorites = <WordPair>[];
void toggleFavorite(){
if(favorites.contains(current)){
favorites.remove(current);
}
else{
favorites.add(current);
notifyListeners();
}
}
} }
class MyHomePage extends StatelessWidget { class MyHomePage extends StatelessWidget {
...@@ -40,6 +52,14 @@ class MyHomePage extends StatelessWidget { ...@@ -40,6 +52,14 @@ class MyHomePage extends StatelessWidget {
var appState = context.watch<MyAppState>(); var appState = context.watch<MyAppState>();
var pair = appState.current; var pair = appState.current;
IconData icon;
if(appState.favorites.contains(pair)){
icon = Icons.favorite;
}
else{
icon = Icons.favorite_border;
}
return Scaffold( return Scaffold(
body: Center( body: Center(
child: Column( child: Column(
...@@ -48,9 +68,15 @@ class MyHomePage extends StatelessWidget { ...@@ -48,9 +68,15 @@ class MyHomePage extends StatelessWidget {
// Text('A random AWESOME idea:'), // Text('A random AWESOME idea:'),
BigCard(pair: pair), BigCard(pair: pair),
SizedBox(height: 10,), SizedBox(height: 10,),
Row(
mainAxisSize: MainAxisSize.min,
children: [
ElevatedButton.icon(onPressed: (){appState.toggleFavorite();}, icon:Icon(icon), label: Text('Like'),),
ElevatedButton(onPressed: (){appState.getNext();}, child: Text('Next'),), ElevatedButton(onPressed: (){appState.getNext();}, child: Text('Next'),),
], ],
), ),
],
),
), ),
); );
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment