Search code examples
flutterflutter-http

(ERROR) A value of type 'Adhan' can't be returned from the method 'getAdhan' because it has a return type of 'Future<List<Adhan>?>'


this code is for fetching data from json api , there is just one error in the code , and this is the error :

error

 class RemoteService {
  Future<List<Adhan>?> getAdhan() async {
    var client = http.Client();

    var uri = Uri.parse("https://api.pray.zone/v2/times/today.json?city=paris");
    var response = await client.get(uri);
    if (response.statusCode == 200) {
      var json = response.body;
      return adhanFromJson(json);
    }
  }
}

I tried to search in the Internet and YouTube for any problem similar to my problem, I did not find anything to help me. how can i fix this error ?


Solution

  • Your function named adhanFromJson probably returns a Adhan, while getAdhan expects you to return a List<Adhan> or null.

    Either change the return type of getAdhan or return a List<Adhan>.