Created
December 24, 2019 08:24
-
-
Save ksdme/0f27e4aabb480a6ef7efa0e62210f212 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
diff --git a/lib/main.dart b/lib/main.dart | |
index 2362ab4..3a8bad4 100644 | |
--- a/lib/main.dart | |
+++ b/lib/main.dart | |
@@ -4,6 +4,7 @@ import 'package:states_rebuilder/states_rebuilder.dart'; | |
void main() => runApp(MyApp()); | |
class CounterBloc { | |
+ int factor = 1; | |
int counter = 0; | |
static final instance = CounterBloc(); | |
} | |
@@ -41,6 +42,17 @@ class HomePage extends StatelessWidget { | |
child: Column( | |
mainAxisAlignment: MainAxisAlignment.center, | |
children: <Widget>[ | |
+ TextField( | |
+ decoration: InputDecoration( | |
+ border: InputBorder.none, | |
+ hintText: 'Increment factor', | |
+ ), | |
+ textAlign: TextAlign.center, | |
+ onChanged: (factor) => model.setState((state) { | |
+ state.factor = (factor?.isNotEmpty ?? false) ? | |
+ int.parse(factor) : 1; | |
+ }), | |
+ ), | |
Text( | |
'${model.state.counter}', | |
style: Theme.of(context).textTheme.display1, | |
@@ -49,7 +61,9 @@ class HomePage extends StatelessWidget { | |
), | |
), | |
floatingActionButton: FloatingActionButton( | |
- onPressed: () => model.setState((state) => state.counter++), | |
+ onPressed: () => model.setState((state) { | |
+ state.counter += state.factor; | |
+ }), | |
tooltip: 'Increment', | |
child: Icon(Icons.add), | |
), |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment