I am trying to do lay loading listview with live web service response in flutter can anyone help me? how to achieve this?
Asked
Active
Viewed 2,313 times
1 Answers
0
You should parse data in background.
Create a method to fetch data:
Future<List<Photo>> fetchPhotos(http.Client client) async {
final response =
await client.get('https://jsonplaceholder.typicode.com/photos');
// Use the compute function to run parsePhotos in a separate isolate
return compute(parsePhotos, response.body);
}
Add your fetch method in builder
of FutureBuilder.
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(title),
),
body: FutureBuilder<List<Photo>>(
future: fetchPhotos(http.Client()),
builder: (context, snapshot) {
if (snapshot.hasError) print(snapshot.error);
return snapshot.hasData
? PhotosList(photos: snapshot.data)
: Center(child: CircularProgressIndicator());
},
),
);
}
}
Look full example: https://flutter.io/cookbook/networking/background-parsing/

Rubens Melo
- 3,111
- 15
- 23
-
8He wants a lazy loading list – Rémi Rousselet Aug 24 '18 at 11:15
-
2Also see the documentation at https://github.com/flutter/flutter/blob/master/packages/flutter/lib/src/widgets/async.dart#L414 - this is not a good use of FutureBuilder – Jonah Williams Aug 24 '18 at 16:15
-
thank you all i am want lay load to need to recall web service again – pradip koravi Aug 27 '18 at 11:28