小编May*_*ati的帖子

未处理的异常:NoSuchMethodError:在 null 上调用了方法“toDate”

我正在使用Firebase开发聊天应用程序。

一段时间以来我收到了这个错误 Unhandled Exception: NoSuchMethodError: The method 'toDate' was called on null.

Timestamp转换为DateTime使用时出现错误toDate()

出现错误一段时间,然后错误消失。

请考虑这个 GIF

这

这是 Firestore 数据类型 AS TimeStamp

在此输入图像描述

源代码

class ChatMessageModel {
  bool isSentByMe;
  String msg = '';

  ///SERVER TIME
  Timestamp time;
  DateTime localTime;
  String timeStamp;
  String fromUid;
  String toUid;

  ChatMessageModel._();

  ChatMessageModel.fromSnapshot(DocumentSnapshot snapshot) {
    this.isSentByMe =
        snapshot.data['from'] == LoginBloc.instance.firebaseUser.uid;
    this.msg = snapshot.data['msg'];
    this.timeStamp = snapshot.data['time'].toString();
    this.time = snapshot.data['time'];
    this.fromUid = snapshot.data['from'];
    this.toUid = snapshot.data['to'];
    this.localTime = this.time.toDate(); //ERROR
  } …
Run Code Online (Sandbox Code Playgroud)

dart flutter google-cloud-firestore

6
推荐指数
1
解决办法
3858
查看次数

将数字转换为Dart中的人类可读格式(例如1.5k,5m,1b)?

我正在开发与社交聊天相关的应用程序,我想将大数字转换为人类可读的格式(例如1500到1.5k),而且我还是Dart的新手。您的帮助将不胜感激。

dart flutter

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

标签 统计

dart ×2

flutter ×2

google-cloud-firestore ×1