flutter: response after picking dropdown value

  dart, dio, php

I’m new to flutter. I have here my dropdown list where i’ve fetched data from my server.

 String _mySelection;

  final String url = "http://10.23.13.0/schoolproj/fetch.php";

  List data = List(); 

  Future<String> getSWData() async {
    var res = await http
        .get(Uri.encodeFull(url), headers: {"Accept": "application/json"});
    var resBody = json.decode(res.body);

    setState(() {
      data = resBody;
    });

And a Dropdown widget on my build.

 DropdownButton(
                   isExpanded: true,
                   items: data.map((item) {
                    return new DropdownMenuItem(
                      child: new Text(item['type']),
                      value: item['type'].toString(),
                    );
                  }).toList(),
                  onChanged: (newVal) {
                    setState(() {
                      _mySelection = newVal;
                    });
                  },
                  value: _mySelection,
                ),      

The code is working. What I want is to get the other attribute from my server which is the [‘description’] value. And post it below in my Dropdown widget. How would I do that? Thanks.

Source: Ask PHP

LEAVE A COMMENT