ValueListenableBuilder
Like set state, it changes a widget every time a variable is updated
First, we will declare a variable of type ValueNotifier
which is a special type of class.
ValueNotifier<int> _counter = ValueNotifier<int>(0);
Now in the next step let’s see the widget code.
ValueListenableBuilder(
valueListenable: _counter,
builder: (context, value, child) {
return Text('$value', style: Theme.of(context).textTheme.headline4,);
},
)
To update the variable, you can do:
_varIndex.value++;
Last updated