Firebase Getter';长度';被调用为空
当我打开选项卡时,有一秒钟,出现了这个错误。然后它消失了,我怎么解决这个问题? 我假设生成长度值需要时间Firebase Getter';长度';被调用为空,firebase,flutter,google-cloud-firestore,Firebase,Flutter,Google Cloud Firestore,当我打开选项卡时,有一秒钟,出现了这个错误。然后它消失了,我怎么解决这个问题? 我假设生成长度值需要时间 class rideList extends StatefulWidget { @override _rideListState createState() => _rideListState(); } class _rideListState extends State<rideList> { @override Widget build(BuildCo
class rideList extends StatefulWidget {
@override
_rideListState createState() => _rideListState();
}
class _rideListState extends State<rideList> {
@override
Widget build(BuildContext context) {
final rides = Provider.of<List<RideDetails>>(context);
int count = 0;
if (rides.length != null) {
return ListView.builder(
itemCount: rides.length,
itemBuilder: (context, index) {
print('Rides: ${rides.length}');
if (rides[index].limit == true) {
return RideTile(ride: rides[index]);
}
else if(rides[index].limit == false){
++count;
if(rides.length == count){
print('no rides');
return Center(child: Text('No rides posted yet. Be the first to post a ride!'));
}
else{
return SizedBox(height: 20.0,);
}
}
return SizedBox(height: 20.0,);
},
);
}
}
}
类rideList扩展StatefulWidget{
@凌驾
_rideListState createState()=>\u rideListState();
}
类_rideListState扩展状态{
@凌驾
小部件构建(构建上下文){
最终乘车=提供方(上下文);
整数计数=0;
if(rides.length!=null){
返回ListView.builder(
itemCount:rides.length,
itemBuilder:(上下文,索引){
打印('Rides:${Rides.length}');
如果(乘骑[索引]。限制==真){
返回车道(车道:车道[索引]);
}
else if(乘骑[index].limit==false){
++计数;
if(rides.length==计数){
打印(“禁止乘坐”);
返回中心(child:Text('还没有发布乘车信息。第一个发布乘车信息!');
}
否则{
返回大小框(高度:20.0,);
}
}
返回大小框(高度:20.0,);
},
);
}
}
}
如果
乘骑
它总是一个列表(),可以为空
您应该使用条件=>if(rides!=null)
而不是=>如果(rides.length!=null)
发生此错误是因为在调用属性length
之前,必须先检查rides
是否为null