Home > OS >  Why I can't fetch data by Json on my Flutter App
Why I can't fetch data by Json on my Flutter App

Time:01-26

I wasn't get any data from fake Api : image

CodePudding user response:

  1. Make sure response.body is returning data.

  2. Avoid using ? in futures, otherwise snapshot could be empty the whole time when body is null. The ui will always show loading.

  3. To make your code look more simple:

Inside statefull widget:

late final Future<List<Data>> _futureData;

And in your initState:

@override    
void initState(){
   _futureData = provider.loadFutureData();
   super.initState();
}

Or if you don't are using provider:

@override    
void initState(){
   _futureData = loadDataFromFunction();
   super.initState();
}
  •  Tags:  
  • Related