I don't understand futures well in flutter and its been a persistent struggle through all my apps. This is one of those errors. When I remove the "[]" it shows "instance of 'Future'" and that's about it.
Class 'Future<dynamic>' has no instance method '[]'.
Receiver: Instance of 'Future<dynamic>'
Tried calling: [](0)
class ListOfEntries extends StatelessWidget{
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.vertical(bottom: Radius.circular(30))),
title: Text("Your entries"),
toolbarHeight: 50,
),
body: FutureBuilder<List>(
future: Database_().entries(),
builder: (context, snapshot) {
return snapshot.hasData ?
new ListView.builder(
padding: const EdgeInsets.all(10.0),
itemCount: snapshot.data.length,
itemBuilder: (context, i) {
return Column(
children: [
Text("${GetList()[i]}"),
],
);
},
)
: Center(
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
CircularProgressIndicator(),
Text(""),
Text("No entries yet:("),
],
)
);
}
),
);
}
GetList()async{
final list = await Database_().entries();
return list;
}
}
This is the function that returns the list.
Future<List<Entry_>> entries() async {
final Database db = await database;
final List<Map<String, dynamic>> maps = await db.query('[Journal Entries]');
return List.generate(maps.length, (i) {
return Entry_(
maps[i]["_entry"],
maps[i]["_date"],
);
});
}