首页 > 解决方案 > 我在 Firestore 中有数据,并提交了值,但其中一些显示为 null

问题描述

我在firestore中有一个集合,我正在将数据从firestore获取到我的应用程序,并将纬度和经度转换为地址,它可以与其他文档一起使用,但是其中一个文档向我显示该字段为空的错误,但它有一个值,如你所见

在此处输入图像描述

我在 Firestore 中总是遇到这个问题,所以有时我删除了文档并重新创建了它,但是每次都这样做很累,我的 Firestore 有什么问题?谁能帮我这个?

这是转换纬度和经度的方法

 Future<String> gymLocation ;
   @override
  void initState() {

 gymLocation = translate.getAddressFromLatLng(widget.gym.gym_region_lat_long.latitude,widget.gym.gym_region_lat_long.longitude);



Future<String> getAddressFromLatLng(double lat , double long) async {
 String stringAddress='';
 try {
  List<Placemark> p = await geolocator.placemarkFromCoordinates(lat, 
  long);
 final coordinates = new Coordinates(lat, long);
 var address = await 
Geocoder.local.findAddressesFromCoordinates(coordinates);
var first = address.first;
Placemark place = p[0];
final cor2 = await Geocoder.local.findAddressesFromQuery(place.name);
var ad2 = cor2.first;

stringAddress = first.addressLine;

  print(stringAddress +' current address');
  print('${first.featureName} ,\n${first.addressLine}');
  print('${ad2.coordinates}');
 //  return string_address;
} catch (e) {
print(e);
}
return stringAddress;
 }

这是在文本小部件中显示地址的方法

gymAddressContainter(gym_model gym) {
return FutureBuilder<String>(
future: gymLocation,
builder:(context, snapshot)
{
 if (snapshot.hasError) {
 return Center(child: Text('No data'));
 }
 else if (snapshot.hasData) {
   return Container(
    padding: EdgeInsets.all(8.0),
    child: Column(
      children: <Widget>[
        adressText(
            widget.gym.gym_address['g_phone'].toString(), Icons.phone,
            Colors.green),
        adressText(widget.gym.gym_address['g_email'], Icons.email,
            Colors.amber),
        adressText(widget.gym.gym_address['g_website'], Icons.public,
            Colors.blue),
        adressText(snapshot.data, Icons.location_on, Colors.pink)
      ],
     )
    );
  }
  else return Center(child:CircularProgressIndicator());
}

  );
  }

这就是我将文档从 firrestore 映射到 dart 的方式

 gym_model.map(dynamic obj){
 this.gym_name = obj['gym_name'];
 this.gym_region = obj['gym_region'];
 this.gphoto= obj['gphoto'];
  this.gym_region_lat_long = obj['gym_region_lat_long'];
  this.gym_city_point = obj['gym_city_point'];

 this.gym_address['g_email']= obj['gym_address']['g_email'];
 this.gym_address['g_phone'] =obj['gym_address']['g_phone'];
 this.gym_address['g_website'] = obj['gym_address']['g_website'];

其他文件工作正常,但仅适用于这个健身房 Rashad 体育俱乐部,它具有价值..

在 Firestore 中总是有问题,当我创建一个集合并创建文档并为每个文档放置值时,一些文档显示为 null,并给我这个消息错误

PlatformException(失败,失败,空)

标签: firebaseflutterdartgoogle-cloud-firestore

解决方案


推荐阅读