pie_chart
pie_chart copied to clipboard
Update the maps value on setstate
this how i defined the pie chart map, when page load i want to set the values,0
Map<String, double> dataMap = {
"Income": 0,
"Expenditure": 0,
};
then on button press, i want update the chart value,
child: RaisedButton(
onPressed: () async {
setState(() {
Map<String, double> dataMap = {
"Income": 75,
"Expenditure": 25,
};
});
},
How to solve this issue?
@atta1234 You can simply assign a new map to dataMap on setstate. The pie chart would automatically update itself upon changing data map
onPressed: () async {
setState(() {
Map<String, double> dataMap = {
"Income": 75,
"Expenditure": 25,
};
this.dataMap=dataMap; // This line would cause your data map field variable to update
});
},