Skip to content

Dropdown Button not work with Future #54473

@MatheusHard

Description

@MatheusHard

════════ Exception caught by widgets library ═══════════════════════════════════════════════════════
The following assertion was thrown building _BodyBuilder:
type 'Future' is not a subtype of type 'List'

Code:
Calls DB:
Future getCidades () async {

var dbCidade = await db;
var res = await dbCidade.rawQuery("SELECT * FROM $tabelaCidade");
return res.toList();

}

getCitys () async {

var dbCidade = await db;
String sql = "SELECT * FROM $tabelaCidade";
List cidades = await dbCidade.rawQuery(sql);
return cidades;

}

Call in Statefull:
static _getCitys () async{
DBAvaliacoes db = new DBAvaliacoes();
List cidades = await db.getCitys();
}

Dropdown call:

List _cidades = _getCitys();

@OverRide
void initState (){
_dropdownMenuItems = buildDropdownMenuItems(_cidades);
_selectedCidade = _dropdownMenuItems[0].value;
super.initState();
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    f: material designflutter/packages/flutter/material repository.frameworkflutter/packages/flutter repository. See also f: labels.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions