ValueListenableBuilder in Flutter

class Engine{}
class Engine {ValueNotifier<int> incrementvalue = ValueNotifier(1);ValueNotifier<int> decrementValue = ValueNotifier(100);ValueNotifier<Color> color = ValueNotifier(Colors.black);}
void dispose() {incrementvalue.dispose();decrementValue.dispose();color.dispose();}
void increment() {
incrementvalue.value = incrementvalue.value + 1;
}
void decrement() {
decrementValue.value--;
}
void randomColor() {
color.value = Colors.primaries[Random().nextInt(Colors.primaries.length)];
}
@overridevoid initState() {_engine = Engine();super.initState();}
Container(color: Colors.red,width: double.infinity,height: 100,child: Center(child: ValueListenableBuilder<int>(valueListenable: _engine.incrementvalue,builder: (context, value, _) {return Text('INC $value');})),),
Container(height: 100,color: Colors.green,child: Center(child: ValueListenableBuilder<int>(valueListenable: _engine.decrementValue,builder: (context, value, _) {return Text('DEC $value');})),),
Container(height: 100,color: Colors.blue,child: Center(child: ValueListenableBuilder<int>(valueListenable: _engine.incrementvalue,builder: (context, value, _) {return ValueListenableBuilder<int>(valueListenable: _engine.decrementValue,builder: (context, value2, _) {return Text('INC : $value  / DEC : $value2');});})),),
ValueListenableBuilder<Color>( valueListenable: _engine.color,  builder: (context, color, _) => Container(     width: 200,      color: color,       child: ValueListenableBuilder<int>(              valueListenable: _engine.incrementvalue,              builder: (context, inc, _) =>                  ValueListenableBuilder(                       valueListenable: _engine.decrementValue,                       builder: (context, dec, _) => Column(                              mainAxisAlignment:                                    MainAxisAlignment.center,                                   children: [                                    Text('Increment $inc '),                                    SizedBox(                                    height: 50,                                ),                        Text('Decrement $dec '),               ],         ))),)),
floatingActionButton: Row(mainAxisAlignment: MainAxisAlignment.spaceEvenly,children: [FloatingActionButton(onPressed: _engine.increment,child: const Text("INC"),),FloatingActionButton(onPressed: _engine.decrement,child: Text("DEC"),),FloatingActionButton(onPressed: _engine.randomColor,child: Text("COLOR"),),FloatingActionButton(onPressed: () {_engine.increment();_engine.decrement();_engine.randomColor();},child: Text("ALL"),)],));
@override
void dispose() {
_engine.dispose();
super.dispose();
}

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store