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