I'm getting the error: type 'List<dynamic>' is not a subtype of type 'FutureOr<List<Donation>>'. I've checked the data type but but cant seem to find the cause of the error.
//getting the data from api call
Future<List<Donation>> _getDonationRecord() async {
var res = await CallApi().donationRecords();
var body = json.decode(res.body);
return body.map((p) => Donation.fromJson(p)).toList();
}
//Building the futurebuilder
FutureBuilder<List<Donation>>(
future: _getDonationRecord(),
builder: (context, snapshot) {
if (snapshot.hasData) {
List<Donation> data = snapshot.data;
return ListView.builder(
itemCount: data.length,
itemBuilder: (context, index) {
return ListTile(
leading: Icon(Icons.thumb_up,color: kPrimaryColor,) ,
title: Text(data[index].hospital,style: TextStyle(color: Colors.black),),
subtitle: Text(data[index].date,style: TextStyle(color: Colors.black),),
trailing: Text(data[index].donorDonatedLitre,style: TextStyle(color: Colors.black),),
);
});
} else if (snapshot.hasError) {
return Text("${snapshot.error}");
}
return Center(child: CircularProgressIndicator());
},
)