Flutter: How to use the selected DropDownButton item to display a chart?

177 Views Asked by At

everyone. I'm trying to get to show a bar chart on the screen when the user selects a certain item from the Dropdown. I have a different file for data that is to be displayed in the chart. So what I'm asking is sort of an 'if else' condition i.e. if the user selects item A, chart A is displayed on the screen below the dropdown, and if he select item B, chart B is displayed. I'm attaching the code of my DropDownButton. Any help will be appreciated. I'm a beginner, so please pardon if this questions seems too basic. TIA.

     body: Center(
      child: Container(
          height: 500,
          width: 800,
          padding: EdgeInsets.all(20),
          child: Card(
              child: Padding(
            padding: const EdgeInsets.all(8.0),
            child: Column(
              children: <Widget>[
                Text(
                  "Select the duration:",
                  style: Theme.of(context).textTheme.bodyText2,
                ),
                Padding(
                  padding: EdgeInsets.all(5.0),
                  child: DropdownButton<String>(
                    items: [
                      DropdownMenuItem<String>(
                        value: "6 Months",
                        child: Center(
                          child: Text("6 Months"),
                        ),
                      ),
                      DropdownMenuItem<String>(
                        value: "12 Months",
                        child: Center(
                          child: Text("12 Months"),
                        ),
                      ),
                    ],
                    onChanged: (_value) => {
                      print(_value.toString()),
                      setState(() {
                        currentItemSelected = _value;
                      }),
                    },
                    value: currentItemSelected,
                    hint: Text("Select Months"),
                  ),
                ),
                Text(
                  "$currentItemSelected",
                ),
              ],
            ),
          )))),
0

There are 0 best solutions below