I have my application defined, and I pass counter
variable as a constructor like below:
class AppThreePlusThree extends StatelessWidget {
@ove
You have to make your StatelessWidget
widget to StatefulWidget
because that is how layout rebuild when state of counter
variable changed(using setState()
). Your code should look like below,
class AppThreePlusThree extends StatefulWidget {
_AppThreePlusThreeState createState() => _AppThreePlusThreeState ();
}
class _AppThreePlusThreeState extends State<AppThreePlusThree> {
var counter = 265;
var counter2 = 265;
void changeVariableOnUI() {
setState(() => counter2 = 22);
}
@override
Widget build(BuildContext context) {
var game = new Game();
// Inside the build method you cannot (no need) use setState but outside the build() to update a variable value on the UI have to use setState
counter = 265; //I seriously doesnt have any idea how you are going to change or update your counter variable. something like this should work
return new GameRedux(
counter: counter,
child: new MaterialApp(
title: '3 + 3',
theme: new ThemeData(
primarySwatch: Colors.blue,
),
home: new Scaffold(
...
...
Text('$counter'),
Text('$counter2'),
InkWell(
child: Text("Tap here"),
onTap: changeVariableOnUI,
),
...