Flutter FutureBuilder未检测到任何数据

Flutter FutureBuilder未检测到任何数据,flutter,Flutter,在响应中找不到数据时,我需要显示一条消息。没有数据时,我会得到如下[]的响应。未来为空时如何处理。我浏览了许多帖子并尝试过,但当我尝试它们时,会显示错误消息或显示数据\ future: _future, builder: (BuildContext context, AsyncSnapshot snapshot) { debugPrint("HAs data"); return ListView.builder( ite

在响应中找不到数据时,我需要显示一条消息。没有数据时,我会得到如下[]的响应。未来为空时如何处理。我浏览了许多帖子并尝试过,但当我尝试它们时,会显示错误消息或显示数据\

  future: _future,
    builder: (BuildContext context, AsyncSnapshot snapshot) {
        debugPrint("HAs data");
          return ListView.builder(
              itemExtent: 80,
              itemCount: myList.length,
              itemBuilder: (BuildContext context, int i) {
                return Card(
                  child: ListTile(
                    onTap: () {Navigator.push(context, MaterialPageRoute(builder: (context) =>DisplayReports(appointmentDetail:myList[i])));},
                    contentPadding: EdgeInsets.symmetric(
                        horizontal: 10.0, vertical:5.0),
                    leading: Container(
                      padding: EdgeInsets.only(right: 8.0),
                      decoration: new BoxDecoration(),
                      child: Icon(Icons.date_range,color: Colors.blueGrey,)
                    ),
                    title: Text(
                      myList[i].doctorName,
                      style: TextStyle(fontSize: 20.0,
                          color: Colors.black, fontWeight: FontWeight.bold),
                    ),
                    subtitle: Row(
                      children: <Widget>[
                        Text(
                          myList[i].apptDateTime != null ?
                          formatDate(DateTime.parse(myList[i].apptDateTime), [
                            dd, '/', M,'/',yyyy]) : " ",
                          overflow: TextOverflow.ellipsis,
                          maxLines: 1,
                          softWrap: false,
                          style: TextStyle(fontSize: 12, color: Colors.black54,),
                        ),                
                      ],
                    ),
                    trailing: IconButton(icon: Icon(Icons.more_vert),onPressed: (){},),
                  ),
                );
                return LinearProgressIndicator();
              });

    },

您可以通过检查列表中有多少元素来实现

我希望下面的代码对您有所帮助

future: _future,
    builder: (BuildContext context, AsyncSnapshot snapshot) {
        debugPrint("HAs data");
           // here check is length of data is 0 then return specific widget which you want to return as i demonstrate with text widget.
          if(myList.length==0){
             return Text("You have not data");
          }
          return ListView.builder(
              itemExtent: 80,
              itemCount: myList.length,
              itemBuilder: (BuildContext context, int i) { 

什么是myList?您在哪里使用snapshot?请添加与此相关的所有详细信息。myList是我从initState中加载的api中获得的列表,我在任何地方都没有使用过snapshot