Skip to content
Snippets Groups Projects
Commit e16ba582 authored by kim hakjun's avatar kim hakjun
Browse files

5 stage

parent 2df27b61
No related branches found
No related tags found
No related merge requests found
...@@ -17,7 +17,7 @@ class MyApp extends StatelessWidget { ...@@ -17,7 +17,7 @@ class MyApp extends StatelessWidget {
title: 'Namer App', title: 'Namer App',
theme: ThemeData( theme: ThemeData(
useMaterial3: true, useMaterial3: true,
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepOrange), colorScheme: ColorScheme.fromSeed(seedColor: Color.fromARGB(255, 218, 235, 241)),
), ),
home: MyHomePage(), home: MyHomePage(),
), ),
...@@ -28,34 +28,77 @@ class MyApp extends StatelessWidget { ...@@ -28,34 +28,77 @@ class MyApp extends StatelessWidget {
class MyAppState extends ChangeNotifier { class MyAppState extends ChangeNotifier {
var current = WordPair.random(); var current = WordPair.random();
// ↓ Add this.
void getNext() { void getNext() {
current = WordPair.random(); current = WordPair.random();
notifyListeners(); 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 { class MyHomePage extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var appState = context.watch<MyAppState>(); var appState = context.watch<MyAppState>();
var pair = appState.current;
return Scaffold( return Scaffold(
body: Column( body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [ children: [
Text('A random AWESOME idea:'), BigCard(pair: pair),
Text(appState.current.asLowerCase), SizedBox(height: 10),
// ↓ Add this.
ElevatedButton( ElevatedButton(
onPressed: () { onPressed: () {
appState.getNext(); // ← This instead of print(). appState.getNext();
}, },
child: Text('Next'), child: Text('Next'),
), ),
], ],
), ),
),
);
}
}
class BigCard extends StatelessWidget {
const BigCard({
super.key,
required this.pair,
});
final WordPair pair;
@override
Widget build(BuildContext context) {
final theme = Theme.of(context);
final style = theme.textTheme.displayMedium!.copyWith(
color: theme.colorScheme.onPrimary,
);
return Card(
color: theme.colorScheme.primary,
child: Padding(
padding: const EdgeInsets.all(20),
// ↓ Make the following change.
child: Text(
pair.asLowerCase,
style: style,
semanticsLabel: "${pair.first} ${pair.second}",
),
),
); );
} }
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment