I used Checkbox to update some data. The sharing data method is Consumer<T>
. The problem is that Checkbox can work ok on changing state, but the checking animation is missing. I have located the problem, if I used notifyListeners()
to notify the Data changed, then the animation of Checkbox is missing.
The Widget code just like below:
bool _value = false;
@override
Widget build(BuildContext context) {
// TODO: implement build
return Row(
children: <Widget>[
Checkbox(
activeColor: Colors.green,
value: _value,
onChanged: (value) {
setState(() {
_value = value;
widget.updateEnergy(); //The problem is Here!!!!!
});
},
),
Text("foodName",
style: TextStyle(color: Colors.blue,
fontSize: 13, fontWeight: FontWeight.w300),
),
Spacer(),
],
);
}
If I used the widget.updateEnergy();
to update the data in onChanged()
, the animation is missing. The updateEnergy() as below:
void updateCurrentEnergy(){
_currentEnergyCount.setValue(_getCurrentEnergyCount(), _dailyTargetEnergy.unit);
notifyListeners();
}
The key is "notifyListeners()", if removed the invoke, the animation is return.
I hope your help, how can get the animation of checkbox. Thank you!
Aucun commentaire:
Enregistrer un commentaire