flutter - 使用 Flutter 异步将数据写入云 Firestore
问题描述
我正在尝试在我的颤振应用程序中使用异步将数据写入 Firestore 集合中。
我确实有这个代码,但它似乎不起作用。
import 'package:location/location.dart';
Location _locationService = new Location();
Future<void> setUserData() async {
Map<String, dynamic> userData = <String, dynamic>{
'email': this._emailController.text,
'password': this._passwordController.text,
'firstname': this._firstNameController.text,
'familyname': this._familyNameController.text,
'phonenumber': this._phoneNumberController.text,
'neighbourhood': this._neighbourhoodController.text,
'latitude': await _locationService.getLocation().latitude,
};
crudObj.addData(userData);
}
crudObj.addData 直接写入我的 Firestore 集合。
我究竟做错了什么 ?
解决方案
看起来您一开始还没有导入 cloud_firestore。
Future<void> setUserData() async {
Firestore.instance.collection(*name of collection*).document(*name of document*).setData(
{'email': this._emailController.text,
'password': this._passwordController.text,
'firstname': this._firstNameController.text,
'familyname': this._familyNameController.text,
'phonenumber': this._phoneNumberController.text,
'neighbourhood': this._neighbourhoodController.text,
'latitude': await _locationService.getLocation().latitude,});
}
我希望您将项目设置为连接到云 Firestore
推荐阅读
- javascript - 如何将字符串值更改为时间戳?Javascript React-Native
- python - 有谁知道这些字符在word文档(docx)的表格中是什么?
- node.js - 如何知道容器已启动并正在运行(Dockerode)?
- azure - ADOS 2020.1 流水线页面布局
- html - 如何以角度创建 HTML?
- codenameone - 代号一中的FTP协议
- django - 此代码如何将两个类相互链接?
- wazuh - 用于 Wazuh 集成的 SSL conf
- python - 如果在更多 N 秒内没有答案然后返回 None 怎么做(因为如果没有发送消息,它将是无限的)
- python - 我想从 Azure 继承迭代器 ItemPaged - ItemPaged[TableEntity] 到 Stream (Python) 获取流对象。是否可以?