我不知道這里有什么問題,但我在 [this.reference] 上遇到錯誤,它說“引數‘reference’由于其型別而不能具有‘null’值,但隱含的默認值為'空值'。” 當我添加必需時,它說“這里不能有修飾符‘必需’”
這是它的代碼:
import 'package:cloud_firestore/cloud_firestore.dart';
class Request {
final String type;
final String reason;
DocumentReference reference;
Request(this.reason, this.type, [this.reference]);
String get requestId {
return reference.id;
}
Map<String, dynamic> toMap() {
return {"type": type, "reason": reason};
}
}
uj5u.com熱心網友回復:
class Request {
final String type;
final String reason;
DocumentReference? reference;
Request(this.reason, this.type, [this.reference]);
String get requestId {
return reference!.id;
}
Map<String, dynamic> toMap() {
return {"type": type, "reason": reason};
}
}
猜測您正在運行 null-safety,您可能希望設定為DocumentReferencenullable
uj5u.com熱心網友回復:
你試過讓那些Nullable
final String? type;
final String? reason;
也嘗試給出默認初始值
Request(String reason = '',String type = '');
轉載請註明出處,本文鏈接:https://www.uj5u.com/qukuanlian/421003.html
標籤:
上一篇:顫動容器內的多個文本
