【问题标题】:How to store and use opening hour information in flutter firebase?如何在flutter firebase中存储和使用营业时间信息?
【发布时间】:2021-10-22 22:44:32
【问题描述】:

我正在颤振中构建一个应用程序,它需要在 firebase 中存储开放时间。我决定以这种格式存储数据:

0: [9,17], //Monday
1: Null, //Tuesday

Etc Etc. openingHours 字段是地图值的列表。键对应于日期,然后小时是值,如果打开则为整数列表,如果关闭则为空值。然而,我正在努力从 firebase 的 json 文件中获取列表并将其存储在颤振中的地图值列表中,在一个名为“业务”的类中,并类似地将数据上传到颤振。

业务对象如下所示:

    class Business{
  String businessId;
  String name;
  String photoUrl;
  Map<int, List<int>> openingHours;

  CommentModel({
    this.name,
    this.businessId,
    this.photoUrl,
    this.openingHours
  });

  CommentModel.fromJson(Map<String, dynamic> json) {
    name = json['name'];
    businessId = json['businessId'];
    photoUrl = json['photoUrl'];
    openingHours = json['openingHours'];
  }

  Map<String, dynamic> toJson() {
    final Map<String, dynamic> data = new Map<String, dynamic>();
    data['name'] = this.name;
    data['businessId'] = this.businessId;
    data['photoUrl'] = this.photoUrl;
    data['openingHours'] = this.openingHours;
    return data;
  }
}

我很清楚我离这个目标还很远,在我完全尝试将其实施到我目前在其他地方工作的设计中并造成一些不可逆转的损害之前,我将不胜感激任何帮助 XD。

【问题讨论】:

    标签: list firebase flutter dictionary google-cloud-firestore


    【解决方案1】:

    0: {"open": "7:00","close: "20:00"}

    1:空,

    2: {"open": "7:00","close: "20:00"}

    【讨论】:

    • 啊,谢谢,我该怎么做整个 toJson 和 fromJson 呢?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-11-07
    • 2021-03-05
    • 1970-01-01
    • 1970-01-01
    • 2011-11-09
    相关资源
    最近更新 更多