Skip to content
Snippets Groups Projects
Commit 98995d82 authored by ahnjuseong's avatar ahnjuseong
Browse files

6단계 완료

parent 4cdcdcd9
No related branches found
No related tags found
1 merge request!1Roll Packages from 611aea1657fb to 28d126c54c63 (1 revision) (#145690)
......@@ -27,11 +27,23 @@ class MyApp extends StatelessWidget {
class MyAppState extends ChangeNotifier {
var current = WordPair.random();
// ↓ Add this.
void getNext() {
current = WordPair.random();
notifyListeners();
}
// ↓ Add the code below.
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;
// ↓ Add this.
IconData icon;
if (appState.favorites.contains(pair)) {
icon = Icons.favorite;
} else {
icon = Icons.favorite_border;
}
return Scaffold(
body: Center(
child: Column(
......@@ -47,13 +67,28 @@ class MyHomePage extends StatelessWidget {
children: [
BigCard(pair: pair),
SizedBox(height: 10),
Row(
mainAxisSize: MainAxisSize.min,
children: [
// ↓ And this.
ElevatedButton.icon(
onPressed: () {
appState.toggleFavorite();
},
icon: Icon(icon),
label: Text('Like'),
),
SizedBox(width: 10),
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