【问题标题】:Write data to cloud firestore with flutter async使用 Flutter 异步将数据写入云 Firestore
【发布时间】:2019-05-29 14:50:24
【问题描述】:

我正在尝试在我的 Flutter 应用中使用异步将数据写入 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 集合。

我做错了什么?

【问题讨论】:

    标签: flutter google-cloud-firestore


    【解决方案1】:

    看起来您一开始还没有导入 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,});
    

    }

    希望您将项目设置为连接到 Cloud Firestore

    【讨论】:

      猜你喜欢
      • 2020-03-04
      • 1970-01-01
      • 2020-07-28
      • 2018-07-25
      • 2021-01-22
      • 1970-01-01
      • 1970-01-01
      • 2020-04-06
      • 1970-01-01
      相关资源
      最近更新 更多