I want to put my listview inside a dropdownbottom

Try below answer hope its help to you. you can refer my answer here and here also for data comes from API and display it into dropdown.

Declare variables:

String? sid;
  List data = [];
  var urls = "https://parallelum.com.br/fipe/api/v1/carros/marcas";

Your API call function:

Future fetchData() async {
    var result = await http.get(Uri.parse(urls), headers: {
      'Content-Type': 'application/json',
      'Accept': 'application/json',
    });
    var jsonData = json.decode(result.body);

    setState(() {
      data = jsonData;
    });
    return jsonData;
  }

call your API fetchData() inside initState()

@override
  void initState() {
    fetchData();
    super.initState();
  }

Your Dropdown Widget:

Container(
                width: 200,
                child: InputDecorator(
                  decoration: InputDecoration(
                    border: OutlineInputBorder(),
                  ),
                  child: DropdownButtonHideUnderline(
                    child: DropdownButton(
                      isDense: true,
                      isExpanded: true,
                      value: sid,
                      hint: Text("Select Data",
                          style: TextStyle(color: Colors.black)),
                      items: data.map((list) {
                        return DropdownMenuItem(
                          child: Text(list['nome']),
                          value: list['codigo'].toString(),
                        );
                      }).toList(),
                      onChanged: (value) {
                        setState(() {
                          sid = value as String?;
                        });
                      },
                    ),
                  ),
                ),
              ),

Your result Screen for DropdownButton ->
enter image description here

Your result Screen for Dropdown -> img

Leave a Comment