相关疑难解决方法(0)

有没有办法在 Flutter 上为 firestore 数据库生成模型类?

我目前正在手动执行此过程。这是一个示例数据类。有没有办法自动生成?

class RideModel {
  final String docId;
  final bool hasRequest;
  final String rideCollectionId;
  final String vehicleTypeId;
  final double corporationRate;
  final double driverRate;
  final double driverInsurance;
  final double passengerInsurance;
  final List startUpCharge;
  final double waitingCharge;
  final double normalCharge;

  RideModel({this.docId, this.hasRequest, this.rideCollectionId,this.vehicleTypeId, this.corporationRate, this.driverRate, this.driverInsurance, this.passengerInsurance, this.startUpCharge, this.waitingCharge, this.normalCharge});

  factory RideModel.fromFirestore(DocumentSnapshot doc) {
    var data = doc.data;

    return RideModel(
        docId: data['docId'],
        hasRequest: data['hasRequest'],
        rideCollectionId: data['rideCollectionId'],
        vehicleTypeId: data['tripDetails']['vehicleType']['vehicleTypeId'],
        corporationRate: data['tripDetails']['vehicleType']['corporation'].toDouble()??0.0,
        driverRate: data['tripDetails']['vehicleType']['driver'].toDouble()??0.0,
        driverInsurance: data['tripDetails']['vehicleType']['driverInsurance'].toDouble()??0.0,
        passengerInsurance: data['tripDetails']['vehicleType']['passengerInsurance'].toDouble()??0.0,
        normalCharge: data['tripDetails']['vehicleType']['normalCharge'].toDouble()??0.0,
        startUpCharge: data['tripDetails']['vehicleType']['startUpCharge']??[],
        waitingCharge: data['tripDetails']['vehicleType']['waitingCharge'].toDouble()??0.0);
  } …
Run Code Online (Sandbox Code Playgroud)

dart firebase flutter google-cloud-firestore

5
推荐指数
1
解决办法
6592
查看次数

在 Flutter 中从 Firebase 读取数组

我在 Firebase 中定义了一个具有不同字段类型的集合,例如字符串和字符串数组。

我可以DocumentSnapshot简单地通过调用来读取字符串:

String name = document['name'];
Run Code Online (Sandbox Code Playgroud)

但我怎样才能得到List<String>?通过调用

List<String> names1 = document['names'];
List<String> names2 = document['ingredients'].map((x) => x.toString())
Run Code Online (Sandbox Code Playgroud)

我相应地得到以下例外:

“List”类型不是“List”
类型的子类型“MappedListIterable”类型不是“List”类型的子类型

dart firebase flutter google-cloud-firestore

4
推荐指数
1
解决办法
1万
查看次数

Flutter firebase,List&lt;dynamic&gt; 不是 List&lt;String&gt; 类型

从 firestore 分配数据时

List<String> idList = snap.data['idList']

我收到错误

List<dynamic> is not of type List<String>

消防店里idList的看起来像这样

firestore 中的 idList 数组

types firebase flutter

0
推荐指数
1
解决办法
1427
查看次数

标签 统计

firebase ×3

flutter ×3

dart ×2

google-cloud-firestore ×2

types ×1