I tried following the flutter doc from text but failed to show the data, I suspect the problem is in the futureBuilder, haven't implement try-catch yet as I'm not sure what to call.
Also when I use late Future futurePrayer; at the class declaration level, the data show but with call error. but if I use late Future with class type annotation the error disappears, but no data is shown.
Screenshot of the error I get:
Code - builder function:
FutureBuilder(
future: futurePrayer,
builder: (context, snapshot) {
if (snapshot.hasData) {
// TODO: fix NoSuchMethodError: 'call
// Dynamic call of object has no instance method 'call'.
return Text(snapshot.data.ashar());
} else if (snapshot.hasError) {
return Text('${snapshot.error}');
}
// By default, show a loading spinner.
return const CircularProgressIndicator();
}
),
ApiBaseHelper / getter
Future ApiBaseHelper() async {
final response = await http
.get(Uri.parse('https://api.myquran.com/v2/sholat/jadwal/1420/2025-01-05'));
if (response.statusCode == 200) {
// If the server did return a 200 OK response,
// then parse the JSON.
return Prayer.fromJson(jsonDecode(response.body) as Map);
} else {
// If the server did not return a 200 OK response,
// then throw an exception.
await ApiBaseHelper().catchError(print);
throw Exception('Failed to load album');
}
}
Prayer data class
// this class is not used yet
class PrayerResponse {
List? prayerTime;
PrayerResponse({
required this.prayerTime,
});
PrayerResponse.fromJson(Map json) {
prayerTime = json['data']['jadwal'];
}
}
class Prayer {
final int id;
final String lokasi;
final String daerah;
final String ashar;
Prayer(
{
required this.id,
required this.lokasi,
required this.daerah,
required this.ashar,
}
);
factory Prayer.fromJson(Map json) {
return Prayer(
id : json['data']['id'],
lokasi : json['data']['lokasi'],
daerah : json['data']['daerah'],
ashar : json['data']['jadwal']['ashar'],
);
}
}
