2
Scaffold(body: FutureBuilder(
      future: fetchTracks(),
      builder: (BuildContext context, AsyncSnapshot snapshot){

     if(snapshot.hasData)
     {
        ListView.builder(
    scrollDirection: Axis.vertical,
    itemExtent: 130.0,
    physics: AlwaysScrollableScrollPhysics(),
    shrinkWrap: true,
    itemCount: trackes.length,
    itemBuilder: (BuildContext context, int index) {
      print("test");
      return makeCard(snapshot.data[index]);
    },
  ).build(context);
     }
     else
     {
       return Center(child: new CircularProgressIndicator());
     }

    } ));

When i call this Scaffold Future build will call my future function fetchTracks() and get the data in snapshot but it is not entering into itemBuilder function. So futurebuilder return NULL. Please help me to solve .and Thank you in advance

Graycodder
  • 447
  • 5
  • 15

2 Answers2

5

You're missing a return before ListView.builder. If you don't return it, it won't build it.

Benjamin
  • 5,783
  • 4
  • 25
  • 49
0

FutureBuilder has different snapshot connectionstates which you must handle. Data on the stream is not available until ConnectionState equals done and hasData equals true.

_loadData(context)
 {
   showModalBottomSheet(
   context: context,
   builder: (BuildContext bc){ 
    return FutureBuilder(
    future: fetchTracks(),
    builder: (BuildContext context, AsyncSnapshot<List<MyClass>> snapshot){
        if (snapshot.connectionState!=ConnectionState.done)
        {
            return PleaseWaitWidget();
        }
        else if(snapshot.hasError)
        {
            DialogCaller.showErrorDialog(context,"future builder  has an error").then((value){});
        }
        else if (snapshot.connectionState==ConnectionState.done)
        {
          if(snapshot.hasData){ 

              List<Widget> list = snapshot.data.map((MyClass myClass){
                return Card(
        child:Wrap(children:<Widget>[
                  Row(children: [Text(myClass.field1)],),
               ]));}).toList();

              return list;
          }
        }
    });
   });
  }
Golden Lion
  • 3,840
  • 2
  • 26
  • 35