Firebase 类型';方法渠道文件参考';不是类型为';文件参考';内铸
我正在使用firestore更新我的项目,这是我第一次遇到此类错误。 这对我来说很有意义,我使用firestore的时候,我的应用程序firestore的其他部分没有出现任何错误, 但在本部分中,我使用云函数创建文档并将其引用插入其他文档中。在我需要获取DocumentId但它告诉我此错误“类型'MethodChannelDocumentReference'不是类型转换中的'DocumentReference'类型的子类型”之后 我留下一些截图 这是我在云函数中的代码:Firebase 类型';方法渠道文件参考';不是类型为';文件参考';内铸,firebase,flutter,google-cloud-firestore,google-cloud-functions,Firebase,Flutter,Google Cloud Firestore,Google Cloud Functions,我正在使用firestore更新我的项目,这是我第一次遇到此类错误。 这对我来说很有意义,我使用firestore的时候,我的应用程序firestore的其他部分没有出现任何错误, 但在本部分中,我使用云函数创建文档并将其引用插入其他文档中。在我需要获取DocumentId但它告诉我此错误“类型'MethodChannelDocumentReference'不是类型转换中的'DocumentReference'类型的子类型”之后 我留下一些截图 这是我在云函数中的代码: exports.gen
exports.generateUserCode = functions.https.onCall(async (data, context) => {
const { uid } = data;
let coupon = shortid.generate();
let user = firestore.doc(`users/${uid}`);
try {
await firestore
.collection("coupons")
.doc(coupon)
.set({
owner: user,
type: 0,
value: 10,
isPercentage: false,
usersUsedIt: 0
});
await user.update({
coupon: {
reference: firestore.doc(`coupons/${coupon}`),
uses: 0
}
});
return {
status: true,
message: "codigo de invitacion generado",
code: coupon
};
} catch (e) {
console.log("error", e);
return {
status: false,
message: "algo salio mal",
code: null
};
}
});
这是颤振代码:
@override
Future<UserModel> getUser() async {
try {
final authUser = await _auth.currentUser();
if (authUser != null) {
final user = await _firestore.document('users/${authUser.uid}').get();
if (!user.data.containsKey('coupon') || user.data['coupon'] == null) {
final couponCode = await _generateCode(authUser.uid);
return UserModel.fromData(authUser, couponCode);
} else {
final coupon = Map<String, dynamic>.from(user.data['coupon']);
final couponRef = coupon['reference'] as DocumentReference;
return UserModel.fromData(authUser, couponRef.documentID);
}
}
return null;
} catch (e) {
log(e.toString(), error: e);
throw ServerException();
}
}
感谢您的帮助。关于堆栈溢出,请不要显示代码图片。最好将代码的文本复制到问题中,这样更易于阅读和搜索。
type 'MethodChannelDocumentReference' is not a subtype of type 'DocumentReference' in type cast