Flutter 如何在Flatter中从listView中删除空项

Flutter 如何在Flatter中从listView中删除空项,flutter,flutter-layout,flutter-test,Flutter,Flutter Layout,Flutter Test,我正在尝试从firebase数据库检索数据,我可以将它们显示为列表项,用户可以选择一项 listview检索的项目与我在firebase集合中的项目一样多,根据过滤器,可能只有1或2个项目可以显示, ListView占用的空间与数据库中的项一样多 return StreamBuilder( stream: _firestore.collection('trips').snapshots(), builder: (BuildContext context, AsyncSnapshot<

我正在尝试从firebase数据库检索数据,我可以将它们显示为列表项,用户可以选择一项

listview检索的项目与我在firebase集合中的项目一样多,根据过滤器,可能只有1或2个项目可以显示, ListView占用的空间与数据库中的项一样多

return StreamBuilder(
  stream: _firestore.collection('trips').snapshots(),
  builder: (BuildContext context, AsyncSnapshot<QuerySnapshot> snapshot) {
    if (!snapshot.hasData) return Text('Loading...');

    return ListView(
      children: snapshot.data.documents.map((document) {
        return Padding(
          padding: const EdgeInsets.all(15.0),
          child: SingleChildScrollView(
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.stretch,
              children: <Widget>[
                Text(
                  document['time'].contains(ampm) &&checkMatchLocationsAndDestinations(document['currentLocation'], document['destination'], uInputCurrentLocation, uInputDestination)  ?'From : ' + document['currentLocation']:'x',
                  style: TextStyle(
                      fontWeight: FontWeight.w900, fontSize: 25.0),
                ),
                SizedBox(
                  height: 5.0,
                ),
                Text(

                  document['time'].contains(ampm) &&checkMatchLocationsAndDestinations(document['currentLocation'], document['destination'], uInputCurrentLocation, uInputDestination)  ?     'To : ' + document['destination']:'x',
                  style: TextStyle(
                      fontWeight: FontWeight.w900, fontSize: 20.0),
                ),
                SizedBox(
                  height: 25.0,
                ),
                Text( document['time'].contains(ampm)&&checkMatchLocationsAndDestinations(document['currentLocation'], document['destination'], uInputCurrentLocation, uInputDestination) ? 'Trip Time     : ' + document['time']:'x'),
                SizedBox(
                  height: 15.0,
                ),
                Text(document['time'].contains(ampm) &&checkMatchLocationsAndDestinations(document['currentLocation'], document['destination'], uInputCurrentLocation, uInputDestination) ? ' Trip Details : ' + document['details']:'x'),
                SizedBox(
                  height: 15.0,
                ),
                Text(document['time'].contains(ampm) &&checkMatchLocationsAndDestinations(document['currentLocation'], document['destination'], uInputCurrentLocation, uInputDestination) ? 'Driver Email  : ' + document['driverEmail']: 'x'),
                SizedBox(
                  height: 15.0,
                ),
                Text(document['time'].contains(ampm) &&checkMatchLocationsAndDestinations(document['currentLocation'], document['destination'], uInputCurrentLocation, uInputDestination) ? 'Trip Price      : ' + document['price'] + 'JD' :'x'),
                SizedBox(
                  height: 15.0,
                ),
                Text(document['time'].contains(ampm) &&checkMatchLocationsAndDestinations(document['currentLocation'], document['destination'], uInputCurrentLocation, uInputDestination) ? 'Avilable Seates : ' + document['avilableSeates'].toString()  :'x'),

                SizedBox(
                  height: 25.0,
                ),
                RoundedButton(
                  onPressed: document['time'].contains(ampm) &&checkMatchLocationsAndDestinations(document['currentLocation'], document['destination'], uInputCurrentLocation, uInputDestination) ?() {
                    print(userInputTime);

                    showDialog(
                        context: context,
                        builder: (BuildContext context) {
                      // return object of type Dialog
                      return AlertDialog(
                        // todo some style on text Trip info
                        // todo check if the user had already selected the same trip. or he have a trip on the way
                        title:   Text('Trip Selected'),
                        content:   Text(document['currentLocation'] + ' to ' +  document['destination'] +' At ' + document['time'] +' ?' ),
                        actions: <Widget>[
                          // usually buttons at the bottom of the dialog
                            FlatButton(
                            child:   Text('Yes'),
                            onPressed: () {
                              Navigator.of(context).pop();
                            },
                          ),
                          FlatButton(
                            child:   Text('No'),
                            onPressed: () {
                              Navigator.of(context).pop();
                            },
                          ),
                        ],
                      );
                    });



                  } : null,
                  title:document['time'].contains(ampm) &&checkMatchLocationsAndDestinations(document['currentLocation'], document['destination'], uInputCurrentLocation, uInputDestination) ? 'Select ' : 'No Trips Found !',
                  color: Colors.blueAccent,
返回StreamBuilder(
流:_firestore.collection('trips').snapshots(),
生成器:(BuildContext上下文,异步快照){
如果(!snapshot.hasData)返回文本('Loading…');
返回列表视图(
子项:snapshot.data.documents.map((文档){
返回填充(
填充:常数边集全部(15.0),
子:SingleChildScrollView(
子:列(
crossAxisAlignment:crossAxisAlignment.stretch,
儿童:[
正文(
文档['time']。包含(ampm)和检查匹配位置和目标(文档['currentLocation']、文档['destination']、uInputCurrentLocation、uInputDestination)?'From:'+文档['currentLocation']:'x',
样式:TextStyle(
fontWeight:fontWeight.w900,fontSize:25.0),
),
大小盒子(
身高:5.0,
),
正文(
文档['time']。包含(ampm)和检查匹配位置和目的地(文档['currentLocation']、文档['destination']、uInputCurrentLocation、uInputDestination)?'To:'+文档['destination']:'x',
样式:TextStyle(
fontWeight:fontWeight.w900,fontSize:20.0),
),
大小盒子(
身高:25.0,
),
文本(文档['time'].包含(ampm)&&checkMatchLocationsAndDestinations(文档['currentLocation']、文档['destination']、uInputCurrentLocation、uInputDestination)?“行程时间:”+文档['time']:'x'),
大小盒子(
身高:15.0,
),
文本(文档['time'].包含(ampm)&检查匹配位置和目的地(文档['currentLocation']、文档['destination']、uInputCurrentLocation、uInputDestination)?“行程详细信息:”+文档['Details']:'x'),
大小盒子(
身高:15.0,
),
文本(文档['time'].包含(ampm)&&checkMatchLocationsAndDestinations(文档['currentLocation']、文档['destination']、UIInputCurrentLocation、UIInputDestination)?“驱动程序电子邮件:”+文档['driverEmail']:“x”),
大小盒子(
身高:15.0,
),
文本(文档['time'].包含(ampm)&&CheckMatchLocations和Destinations(文档['currentLocation'],文档['destination'],uInputCurrentLocation,uInputDestination)?“行程价格:”+文档['Price']+'JD':'x'),
大小盒子(
身高:15.0,
),
文本(文档['time'].包含(ampm)&&checkMatchLocationsAndDestinations(文档['currentLocation']、文档['destination']、uInputCurrentLocation、uInputDestination)“‘Available Seates:'+文档['Availableseates']。toString():'x'),
大小盒子(
身高:25.0,
),
圆形按钮(
按下:文档['time']。包含(ampm)和检查匹配位置和目标(文档['currentLocation'],文档['destination'],UIInputCurrentLocation,UIInputDestination)?(){
打印(用户输入时间);
显示对话框(
上下文:上下文,
生成器:(BuildContext上下文){
//返回对话框类型的对象
返回警报对话框(
//todo文本行程信息上的某些样式
//todo检查用户是否已经选择了相同的行程。或者他正在途中
标题:文本(“选定行程”),
内容:文本(文档['currentLocation']+'到'+document['destination']+'在'+document['time']+'?'处的'+document['destination']+'),
行动:[
//通常是对话框底部的按钮
扁平按钮(
子项:文本('Yes'),
已按下:(){
Navigator.of(context.pop();
},
),
扁平按钮(
child:Text('No'),
已按下:(){
Navigator.of(context.pop();
},
),
],
);
});
}:null,
标题:文档['time']。包含(ampm)&检查匹配位置和目的地(文档['currentLocation']、文档['destination']、uInputCurrentLocation、uInputDestination)?“选择”:“未找到行程!”,
颜色:Colors.blueAccent,
//todo关闭计时行程 ), ], ), ), ); }).toList(),/''
);

您可以这样做:

/…在.map()中
snapshot.data.documents.map((文档){
如果(document==null)返回Wrap();
//映射逻辑的其余部分
}