StreamBuilder snapshot is always ConnectionState.waiting

前端 未结 5 2015
故里飘歌
故里飘歌 2021-02-19 12:12

I thought I understood StreamBuilders but I have some doubts that are puzzling me.

I thought that a ConnectionState.waiting means that the connection with the stream is

5条回答
  •  借酒劲吻你
    2021-02-19 12:46

    I suggest you drop the if/else condition and use a switch to check for the ConnectionState.

    switch(snapshot.connectionState){
      case ConnectionState.waiting:
        return Center(child:CircularProgressIndicator());
        break;
      default:
        if(snapshot.hasError){
           // Handle errors
         }else if(!snapshot.hasData){
           // Handle no data
          }else {
           // Check for null
           var result = snapshot.data
           if(result!=null){
             //Handle the null value
           } else {
    
            }
          }
    
        break;
    
    
    }
    

提交回复
热议问题