相关疑难解决方法(0)

如何在Firestore中的现有阵列中添加或删除项目?

Firestore最近添加了新的新方法FieldValue.arrayUnion(value)和FieldValue.arrayRemove(value),但我在flutter cloud_firestore包中找不到实现。有什么办法可以达到这个结果?

Firestore addUpdate:https ://firebase.google.com/docs/firestore/manage-data/add-data#update_elements_in_an_array

dart flutter google-cloud-firestore

2
推荐指数
2
解决办法
2499
查看次数

List<dynamic> 不是 List<Option> 的子类型

我有一个带有questions集合的 Cloud Firebase 数据库。每个question都有一个 map 列表options。我正在使用 Flutter 并为questionand 提供以下类option

class Question {
  final String text;
  final List<Option> options; // I have tried changing this to List<dynamic> but it doesn't help
  final String reference;

  Question(this.text, this.options, this.reference);

  Question.fromMap(Map<String, dynamic> map, {this.reference}) : 
    text = map['text'],
    options = map['options']; // here the error happens

  Question.fromSnapshot(DocumentSnapshot snapshot)
     : this.fromMap(snapshot.data, reference: snapshot.documentID);
}
Run Code Online (Sandbox Code Playgroud)

option

class Option {
  final String text;
  final int votes; …
Run Code Online (Sandbox Code Playgroud)

dart firebase flutter google-cloud-firestore

2
推荐指数
1
解决办法
2810
查看次数

标签 统计

dart ×2

flutter ×2

google-cloud-firestore ×2

firebase ×1