Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Flutter Flatter firestore流将所有条目返回为null_Flutter_Google Cloud Firestore - Fatal编程技术网

Flutter Flatter firestore流将所有条目返回为null

Flutter Flatter firestore流将所有条目返回为null,flutter,google-cloud-firestore,Flutter,Google Cloud Firestore,所以,我试图在firestore中获取此集合中的所有文档,但它们都返回为null。以下是我的代码和结果: 我的现场模型: class Spot { GeoPoint coordinates; bool covered; String excerpt; List<String> imgs; bool lighting; String name; bool public; Spot({ this.coordinates, this.cov

所以,我试图在firestore中获取此集合中的所有文档,但它们都返回为null。以下是我的代码和结果:

我的现场模型:

class Spot {
  GeoPoint coordinates;
  bool covered;
  String excerpt;
  List<String> imgs;
  bool lighting;
  String name;
  bool public;

  Spot({
    this.coordinates,
    this.covered,
    this.excerpt,
    this.imgs,
    this.lighting,
    this.name,
    this.public,
  });

  factory Spot.fromMap(Map data) {
    return new Spot(
      coordinates: data['coordinates'] ?? null,
      covered: data['coveres'] ?? false,
      excerpt: data['excerpt'] ?? '',
      imgs: (data['img'] as List ?? []).map((v) => v as String).toList(),
      lighting: data['lighting'] ?? false,
      name: data['name'] ?? '',
      public: data['public'] ?? false,
    );
  }
}
在这里,我正在设置我的流:

final FirebaseFirestore _db = FirebaseFirestore.instance;
 Stream<List<Spot>> streamSpots() {
    var ref = _db.collection('spots/DF/Brasília');
    return ref.snapshots().map((list) => list.docs.map((doc) {
          Spot.fromMap(doc.data());
        }).toList());
  }
我在这里调用我的流:

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MultiProvider(
      providers: [
        StreamProvider<List<Spot>>.value(
          value: DatabaseService().streamSpots(),
          initialData: [Spot()],
        )
      ],
      child: MaterialApp(
        title: 'Maparkour',
        debugShowCheckedModeBanner: false,
        theme: ThemeData(
          primarySwatch: Colors.blue,
        ),
        home: SplashScreen(),
      ),
    );
  }
}
到目前为止,我的firestore集合有14个条目,它们被正确返回,但每个条目都返回为null

下面是我的调试器中的图片:


你知道为什么吗?感谢您的帮助

在遍历list.docs时忘记返回值。您应该在流中添加一个arrow函数或return语句

返回ref.snapshots.maplist=>list.docs.mapdoc=>Spot.fromMapdoc.data.toList; 或

return ref.snapshots.maplist=>list.docs.mapdoc{return Spot.fromMapdoc.data;}.toList;
在遍历list.docs时忘记返回值。您应该在流中添加一个arrow函数或return语句

返回ref.snapshots.maplist=>list.docs.mapdoc=>Spot.fromMapdoc.data.toList; 或

return ref.snapshots.maplist=>list.docs.mapdoc{return Spot.fromMapdoc.data;}.toList;