android - 如何获取函数输出的值,并在 flutter 中发送到 firebase?

标签 android firebase flutter google-cloud-firestore

我想将公司和电话类型发送到 Firebase,我使用了 plugin device_info获取信息, 但在 firebase 中,我得到空字段,如下图所示。

enter image description here

我的代码

import 'package:device_info/device_info.dart';
......
  String Modele ='';
  String brand ='';
  .......
  Future<void>_deviceDetails() async{
    final DeviceInfoPlugin deviceInfoPlugin = new DeviceInfoPlugin();
    try {
      var build = await deviceInfoPlugin.androidInfo;
      setState(() {
        brand = build.brand;
        Modele = build.model;
      });
    } on PlatformException {
      print('Failed to get platform version');
    }
  }
.........
 .......
                      RaisedButton(
                          onPressed: () async {
                              Map<String, dynamic> data = {
                                "marque":brand,
                                "Modele:" :Modele,
                           
                              };
                           
                          var myStoredData = await readData();
                                  FirebaseFirestore.instance
                                      .collection(myStoredData)
                                      .add(data);
                          },
                         
                   .........
            

最佳答案

您从未调用_deviceDetails

RaisedButton(
  onPressed: () async {
    await _deviceDetails(); // <------
    Map<String, dynamic> data = {
      "marque":brand,
      "Modele:" :Modele,                     
    };
    var myStoredData = await readData();
    FirebaseFirestore.instance
      .collection(myStoredData)
      .add(data);
  },

关于android - 如何获取函数输出的值,并在 flutter 中发送到 firebase?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/70436358/

相关文章:

android - 评估根项目 'audioplayers' 时出现问题。无法在 Flutter 项目中应用插件 [id 'kotlin-android']

flutter - 在Flutter Bloc监听器中调用setState

java - 相同的 XML,不同的行为

XML 中的 Android LinkMovementMethod?

android - 使用 Robolectric 和 Mockito 测试 CursorLoader

android - 我应该为我的应用程序使用 fragment 或 Activity 吗?

node.js - 从 firebase 返回响应的正确方法是 Google Cloud Pub/Sub 触发器

firebase - Firebase 本地缓存在浏览器中持续多长时间?

firebase - Firestore 中的 getDocuments() 和 snapshots() 有什么区别?

flutter - 如何处理行情?