pie_chart icon indicating copy to clipboard operation
pie_chart copied to clipboard

Update the maps value on setstate

Open atta1234 opened this issue 4 years ago • 1 comments

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 avatar Feb 21 '21 20:02 atta1234

@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
                                      
                                      });
                                    },

apgapg avatar Feb 22 '21 07:02 apgapg