首页 > 解决方案 > 连接到 Firebase 时 Flutter 中的地图出现问题

问题描述

我有从我的云存储中获取数据的 Record3 类:

class Record3 {
  final String name;
  final int ref;
  final bool display;
  final DocumentReference reference;

  Record3.fromMap(Map<String, dynamic> map, {this.reference})
      : assert(map['name'] != null),
        assert(map['ref'] != null),
        assert(map['display'] != null),
        name = map['name'],
        ref = map['ref'];
        display = map['display'];


  Record3.fromSnapshot(DocumentSnapshot snapshot)
      : this.fromMap(snapshot.data(), reference: snapshot.reference);

  @override
  String toString() => "Record<$name:$ref:$display>";
}

我将该字段添加display到云 Firestore,现在我正在尝试将其添加到 record3 代码中。但是,线路存在问题display = map['display'];display抛出错误:

The name 'display' is already defined.
Try renaming one of the declarations.

map抛出错误:

Undefined name 'map'.
Try correcting the name to one that is defined, or defining the name.

我不太确定如何修复这些错误,因为两者都已定义,所以我觉得这与display在地图中添加和不更改变量有关?我不确定,所以任何帮助将不胜感激!

标签: flutterdart

解决方案


将显示分配之前的行更改为ref = map['ref'],用逗号而不是分号。


推荐阅读