skip to Main Content

I am working on a flutter app that calls an API to get all the servers from the backend. My backend is in the Laravel.
When I run the API in postman it gives me the correct result, but when I call the API in app it fetch the result but did not display in list on screen.!This is the error I am getting on running the APP](https://i.sstatic.net/7C5rlUeK.png)

Belwo is the code where the error is occuring in terminal on running the app.

This is the line of code where I am getting the error

This is the line of code where I am getting the error

I have tried to json decode the data, but it did not work.
I have also commented these code and then run the app, then the API call is not working.

2

Answers


  1. Ensure you’re using await with the asynchronous operation to guarantee the data is available before accessing it:

    Future<ApiResponse<App<String, dynamic>>> fetchData() async {
      // ... fetch data from API
    }
    
    void handleData() async {
      ApiResponse<App<String, dynamic>> apiResponse = await fetchData();
      App<String, dynamic> appData = apiResponse.data;
      // Use the appData here
    }
    

    Also i recomend to use Dio or Retrofit to call API’s

    Login or Signup to reply.
  2. Try using null safety type by replace

    ApiResponse<App<String, dynamic>> to ApiResponse<App<String, dynamic>>?

    and modify check condition by

    if (resp?.success ?? false) {
    
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search