Get the button working.
This commit is contained in:
parent
1f797dbf6b
commit
0cd06931bb
@ -14,7 +14,7 @@ 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),
|
||||
@ -26,7 +26,13 @@ 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 {
|
||||
@ -37,8 +43,15 @@ class MyHomePage extends StatelessWidget {
|
||||
return Scaffold(
|
||||
body: Column(
|
||||
children: [
|
||||
Text('A random idea:'),
|
||||
Text('A random wordpair:'),
|
||||
Text(appState.current.asLowerCase),
|
||||
ElevatedButton(
|
||||
onPressed: () {
|
||||
appState.getNext();
|
||||
},
|
||||
child: Text('Next'),
|
||||
),
|
||||
|
||||
],
|
||||
),
|
||||
);
|
||||
|
Loading…
x
Reference in New Issue
Block a user