Thu
0
Q:

flutter future builder

 FutureBuilder<String>(
        future: _fetchNetworkCall, // async work
        builder: (BuildContext context, AsyncSnapshot<String> snapshot) {
           switch (snapshot.connectionState) {
             case ConnectionState.waiting: return Text('Loading....');
             default:
               if (snapshot.hasError)
                  return Text('Error: ${snapshot.error}');
               else
              return Text('Result: ${snapshot.data}');
            }
         },
        ),
3



FutureBuilder(
  future: _fetchListItems(),
  builder: (context, AsyncSnapshot snapshot) {
    if (!snapshot.hasData) {
      return Center(child: CircularProgressIndicator());
    } else {
      Container(
          child: ListView.builder(
              itemCount: snapshot.data.length,
              scrollDirection: Axis.horizontal,
              itemBuilder: (BuildContext context, int index) {
                return Text('${snapshot.data[index].title}');
              }));
    }
  });
0
Example of future function:Future getProjectDetails() async {  List<ProjectModel> projetcList = await someFutureCall();  return projetcList;    }
0
class ProjectModel {  String id;  String createdOn;  String lastModifiedOn;  String title;  String description;  ProjectModel({    this.id,    this.createdOn,    this.lastModifiedOn,    this.title,    this.description,  });}
0

New to Communities?

Join the community