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