Compare commits
2 Commits
1f797dbf6b
...
66e1f3a05b
Author | SHA1 | Date | |
---|---|---|---|
66e1f3a05b | |||
0cd06931bb |
@ -14,10 +14,10 @@ class MyApp extends StatelessWidget {
|
||||
return ChangeNotifierProvider(
|
||||
create: (context) => MyAppState(),
|
||||
child: MaterialApp(
|
||||
title: 'Namer App',
|
||||
title: 'Namer App (EXAMPLE PROJECT)',
|
||||
theme: ThemeData(
|
||||
useMaterial3: true,
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepOrange),
|
||||
colorScheme: ColorScheme.fromSeed(seedColor: Colors.purple),
|
||||
),
|
||||
home: MyHomePage(),
|
||||
),
|
||||
@ -26,21 +26,61 @@ class MyApp extends StatelessWidget {
|
||||
}
|
||||
|
||||
class MyAppState extends ChangeNotifier {
|
||||
var current = WordPair.random();
|
||||
var current = WordPair.random();// ...
|
||||
|
||||
// ↓ Add this.
|
||||
void getNext() {
|
||||
current = WordPair.random();
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
class MyHomePage extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var appState = context.watch<MyAppState>();
|
||||
var pair = appState.current;
|
||||
|
||||
return Scaffold(
|
||||
body: Column(
|
||||
children: [
|
||||
Text('A random idea:'),
|
||||
Text(appState.current.asLowerCase),
|
||||
Text('A random wordpair:'),
|
||||
BigCard(pair: pair),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
appState.getNext();
|
||||
},
|
||||
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(15.0),
|
||||
child: Text(pair.asLowerCase, style: style),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user