Home > Software design >  How do you get the values that the function outputs, to send to a firebase in a flutter?
How do you get the values that the function outputs, to send to a firebase in a flutter?

Time:12-22

I want to send the company and type of phone to Firebase and I used enter image description here

my code

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);
                          },
                         
                   .........
            

CodePudding user response:

You never call _deviceDetails

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