Skip to content
Snippets Groups Projects
Commit 4f221194 authored by Jingeun Lee's avatar Jingeun Lee
Browse files

6. 기능 추가

parent f1bbba59
No related branches found
No related tags found
No related merge requests found
...@@ -31,6 +31,17 @@ class MyAppState extends ChangeNotifier { ...@@ -31,6 +31,17 @@ 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 {
...@@ -39,6 +50,13 @@ class MyHomePage extends StatelessWidget { ...@@ -39,6 +50,13 @@ 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(
...@@ -46,6 +64,17 @@ class MyHomePage extends StatelessWidget { ...@@ -46,6 +64,17 @@ class MyHomePage extends StatelessWidget {
children: [ children: [
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'),
),
SizedBox(width: 10),
ElevatedButton( ElevatedButton(
onPressed: () { onPressed: () {
appState.getNext(); appState.getNext();
...@@ -54,6 +83,8 @@ class MyHomePage extends StatelessWidget { ...@@ -54,6 +83,8 @@ class MyHomePage extends StatelessWidget {
), ),
], ],
), ),
],
),
), ),
); );
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment