当Future.data中没有数据时,发出完美消息

时间:2019-09-03 12:00:48

标签: flutter

在下面的这段代码中,当list is empty为假时,我尝试显示snapshot.hasData消息

body: FutureBuilder(
  future: Provider.of<TicketRepliesTableDao>(context).find(ticketId: _ticket.id),
  builder: (context, snapshot) {
    if (snapshot.connectionState == ConnectionState.done) {
      if (snapshot.hasData) {
        final List<TicketRepliesTableData> ticketReplies = snapshot.data;
        if (ticketReplies.isNotEmpty) {

        }
      } else {
        return _loader(message: 'list is empty');
      }
    } else
      return CircularProgressIndicator();
  },
),

但是鉴于这一点,我仍然CircularProgressIndicator()始终没有任何数据并且ticketReplies为空

1 个答案:

答案 0 :(得分:1)

使用此逻辑更新您的builder

builder: (context, snapshot) {
  if (snapshot.connectionState == ConnectionState.done) {
    if (snapshot.hasData) {
      // show your data
      return Text(snapshot.data);
    } else {
      // show list is empty
      return Text("List is empty");
    }
  }
  // by default show loading bar
  return CircularProgressIndicator();
}