I want to recover data from my table and put them in my dropdown.
I get an error message : _TypeError (type ‘Future’ is not a subtype of type ‘List’)
Thank you for your help
readData(table) async {
var connection = await db;
return await connection.query('SELECT nom_A FROM tab_A');
}
class DropdownMenuA extends StatefulWidget {
const DropdownMenuA({super.key});
//Modif
@override
State<DropdownMenuA> createState() => _DropdownMenuAState();
}
class _DropdownMenuAState extends State<DropdownMenuA> {
//String dropdownValueA = list1.first;
List<String> listA = readData(Tab_A);
@override
Widget build(BuildContext context) {
return DropdownMenu<String>(
initialSelection: listA.first,
onSelected: (String? value) {
// This is called when the user selects an item.
setState(() {
//dropdownValueA = value!;
});
},
dropdownMenuEntries: listA.map<DropdownMenuEntry<String>>((String value) {
return DropdownMenuEntry<String>(value: value, label: value);
}).toList(),
);
}
}
2
Answers
I think I have a problem with my request, your code is good :
I have this error : Exception has occurred. SqfliteFfiException (SqfliteFfiException(sqlite_error: 1, , SqliteException(1): while preparing statement, near "SELECT": syntax error, SQL logic error (code 1) Causing statement: SELECT * FROM SELECT * FROM tab_A }) DatabaseException(SqliteException(1): while preparing statement, near "SELECT": syntax error, SQL logic error (code 1) Causing statement: SELECT * FROM SELECT * FROM tab_A ) sql 'SELECT * FROM SELECT * FROM tab_A ' {details: {database: {path: E:ProjetsFluttertablesabc.dart_toolsqflite_common_ffidatabases
db_tablesabc, id: 1, readOnly: false, singleInstance: true}}})
If I put this request :
I have this error : Exception has occurred. _TypeError (type 'QueryResultSet' is not a subtype of type 'List')
Put
await
keyword for theFuture
call. Like:In order to use
await
keyword you must also use theasync
keyword as well like:And call this
fetchData()
function insideinitState()
function like:Final code looks like:
Kindly, let me know if it works.