Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/9.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Google cloud firestore 扑动:保存到Firestore_Google Cloud Firestore_Flutter - Fatal编程技术网

Google cloud firestore 扑动:保存到Firestore

Google cloud firestore 扑动:保存到Firestore,google-cloud-firestore,flutter,Google Cloud Firestore,Flutter,我有一个名为\u sendToDatabaseWithArgs的方法,它接受一些参数并将它们保存到firestore数据库onTap。参数已经从第一个屏幕填充,该屏幕有一个表单并接受3个输入 问题是,当我执行onTap操作时,数据将不会保存到firestore。但是,当我保存程序时,数据会自动保存到数据库中 下面是应该处理此问题的类: import 'package:cloud_firestore/cloud_firestore.dart'; import 'package:flutter/ma

我有一个名为
\u sendToDatabaseWithArgs
的方法,它接受一些参数并将它们保存到firestore数据库onTap。参数已经从第一个屏幕填充,该屏幕有一个表单并接受3个输入

问题是,当我执行onTap操作时,数据将不会保存到firestore。但是,当我保存程序时,数据会自动保存到数据库中

下面是应该处理此问题的类:

import 'package:cloud_firestore/cloud_firestore.dart';
import 'package:flutter/material.dart';

import 'StoreData.dart';

class FeedBack extends StatelessWidget {
  final StoreData storeData;
  String feedBackHolder = "";

  FeedBack({Key key, @required this.storeData}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Navajo Inc Feedback"),
      ),
      body: new Container(
        padding: new EdgeInsets.all(15.0),
        child: new ListView(
          // crossAxisAlignment: CrossAxisAlignment.stretch,

          children: <Widget>[

            new RaisedButton(onPressed: _sendToDatabaseWithArgs(storeData.storeNumber, storeData.repName, storeData.repCell, storeData.transactionDate),

            child: const Text('RAISED BUTTON'),


            ),

            new GestureDetector(

              onTap: _sendToDatabaseWithArgs(storeData.storeNumber, storeData.repName, storeData.repCell, storeData.transactionDate),

              child: feedBackCardsImage(
                imagePath: 'assets/happy_face.png',
                CardTitle: 'Happy Customer',
                CardTag: 'Experience was excellent',

              ),
            ),

            new GestureDetector(
              onTap: _sendToDatabase,
              child: feedBackCardsImage(
                imagePath: 'assets/neutral_face.png',
                CardTitle: 'Neutral Customer',
                CardTag: 'Experience was satisfactory',
              ),
            ),
            new GestureDetector(
              onTap: _sendToDatabase,
              child: feedBackCardsImage(
                imagePath: 'assets/angry_face.png',
                CardTitle: 'Unsatisfied Customer',
                CardTag: 'Experience was unsatisfactory',
              ),
            ),
          ],
        ),
      ),
    );
  }



  _sendToDatabaseWithArgs(String storeNumber,repName,repCell, DateTime transactionDate) {




      Firestore.instance.runTransaction((Transaction transaction) async {
        CollectionReference reference = Firestore.instance.collection('Stores');

        await reference.add({
          "store Name": storeNumber,
          "Rep Name": repName,
          "Rep Cell": repCell,
          "Transaction Date": transactionDate,
        });
      });


  }






  _sendToDatabase() {

    Firestore.instance.runTransaction((Transaction transaction) async {
      CollectionReference reference = Firestore.instance.collection('Stores');

      await reference.add({
        "store Name": "${storeData.storeNumber}",
        "Rep Name": "${storeData.repName}",
        "Rep Cell": "${storeData.repCell}",
        "Transaction Date":"${storeData.transactionDate}",
      });
    });
  }


}







// feedback cardsImage widget / class

class feedBackCardsImage extends StatelessWidget {



  final String imagePath;
  final String CardTitle;
  final String CardTag;

  feedBackCardsImage({
    this.imagePath,
    this.CardTitle,
    this.CardTag,
  });

  @override
  Widget build(BuildContext context) {
    return new Container(
        child: new Card(
          child: new Padding(
            padding: new EdgeInsets.all(15.0),
            child: new Column(
              children: <Widget>[
                new SizedBox(
                  height: 184.0,
                  child: new Stack(
                    children: <Widget>[
                      new Positioned.fill(
                        child: new Image.asset(
                          imagePath,
                          //package: destination.assetPackage,
                          fit: BoxFit.contain,
                        ),
                      ),
                    ],
                  ),
                ),
                new Padding(padding: new EdgeInsets.all(7.0,),
                  child:  new Text(CardTitle, style: new TextStyle(fontSize: 14.0, fontWeight: FontWeight.w600, color: Colors.black87), ),
                ),
                new Padding(padding: new EdgeInsets.all(0.0,),
                  child:  new Text(CardTag, style: new TextStyle(fontSize: 12.0, fontWeight: FontWeight.w400, color: Colors.black54), ),
                ),
              ],
            ),
          ),
        ),




    );
  }
}
import'包:cloud_firestore/cloud_firestore.dart';
进口“包装:颤振/材料.省道”;
导入“StoreData.dart”;
类反馈扩展了无状态小部件{
最终存储数据存储数据;
字符串反馈保持器=”;
反馈({Key-Key,@required this.storeData}):super(Key:Key);
@凌驾
小部件构建(构建上下文){
返回脚手架(
appBar:appBar(
标题:文本(“纳瓦霍公司反馈”),
),
主体:新容器(
填充:新的边缘设置。全部(15.0),
子:新列表视图(
//crossAxisAlignment:crossAxisAlignment.stretch,
儿童:[
新建RaisedButton(按下时:\ U sendToDatabaseWithArgs(storeData.storeNumber、storeData.repName、storeData.repCell、storeData.transactionDate),
子项:常量文本('凸起的按钮'),
),
新手势检测器(
onTap:_发送到带有参数的数据库(storeData.storeNumber、storeData.repName、storeData.repCell、storeData.transactionDate),
儿童:反馈卡年龄(
imagePath:'assets/happy_face.png',
卡片标题:“快乐顾客”,
CardTag:“经验非常好”,
),
),
新手势检测器(
onTap:\u发送到数据库,
儿童:反馈卡年龄(
imagePath:'assets/neutral_face.png',
卡片标题:“中立客户”,
CardTag:“经验令人满意”,
),
),
新手势检测器(
onTap:\u发送到数据库,
儿童:反馈卡年龄(
imagePath:'assets/angry_face.png',
卡片标题:“不满意的客户”,
CardTag:“经验不令人满意”,
),
),
],
),
),
);
}
_sendToDatabaseWithArgs(字符串storeNumber、repName、repCell、DateTime transactionDate){
Firestore.instance.runTransaction((事务)异步{
CollectionReference=Firestore.instance.collection('Stores');
等待参考。添加({
“门店名称”:门店编号,
“代表姓名”:代表姓名,
“repCell”:repCell,
“交易日期”:交易日期,
});
});
}
_sendToDatabase(){
Firestore.instance.runTransaction((事务)异步{
CollectionReference=Firestore.instance.collection('Stores');
等待参考。添加({
“存储名称”:“${storeData.storeNumber}”,
“Rep Name”:“${storeData.repName}”,
“Rep Cell”:“${storeData.repCell}”,
“交易日期”:“${storeData.transactionDate}”,
});
});
}
}
//反馈卡图像小部件/类
类反馈CardSimage扩展了无状态小部件{
最终字符串图像路径;
最终字符串卡片标题;
最终字符串卡片标签;
反馈卡图像({
这个.imagePath,
这是我的名片,
这个.CardTag,
});
@凌驾
小部件构建(构建上下文){
退回新货柜(
孩子:新卡(
孩子:新的填充物(
填充:新的边缘设置。全部(15.0),
子:新列(
儿童:[
新尺寸盒子(
身高:184.0,
子:新堆栈(
儿童:[
新定位填充(
子:新建Image.asset(
imagePath,
//包装:destination.assetPackage,
适合:BoxFit.contain,
),
),
],
),
),
新填充(填充:新边集。全部(7.0,),
子项:新文本(卡片标题,样式:新文本样式(fontSize:14.0,fontWeight:fontWeight.w600,颜色:Colors.black87)),
),
新填充(填充:新边集。全部(0.0,),
子项:新文本(CardTag,样式:新文本样式(fontSize:12.0,fontWeight:fontWeight.w400,颜色:Colors.black54)),
),
],
),
),
),
);
}
}

如有任何见解,将不胜感激

直接创建一个新文档怎么样

  Future<void> _sendToDatabase() {
    return Firestore.instance.runTransaction((Transaction transactionHandler) {
      return Firestore.instance
          .collection(_entriesPath)
          .document()
          .setData({
    "store Name": "${storeData.storeNumber}",
    "Rep Name": "${storeData.repName}",
    "Rep Cell": "${storeData.repCell}",
    "Transaction Date":"${storeData.transactionDate}",
  });
    });
  }
Future\u sendToDatabase(){
返回Firestore.instance.runTransaction((事务transactionHandler){
返回Firestore.instance
.collection(_entriesPath)
.文件(
.setData({
“存储名称”:“${storeData.storeNumber}”,
“Rep Name”:“${storeData.repName}”,
“Rep Cell”:“${storeData.repCell}”,
“交易日期”:“${storeData.transactionDate}”,
});
});
}

直接创建一个新文档怎么样

  Future<void> _sendToDatabase() {
    return Firestore.instance.runTransaction((Transaction transactionHandler) {
      return Firestore.instance
          .collection(_entriesPath)
          .document()
          .setData({
    "store Name": "${storeData.storeNumber}",
    "Rep Name": "${storeData.repName}",
    "Rep Cell": "${storeData.repCell}",
    "Transaction Date":"${storeData.transactionDate}",
  });
    });
  }
Future\u sendToDatabase(){
返回Firestore.instance.runTransaction((事务transactionHandler){
返回Firestore.instance
.collection(_entriesPath)
.文件(
.setData({
“存储名称”:“${storeData.storeNumber}”,
“Rep Name”:“${storeData.repName}”,
“Rep Cell”:“${storeData.repCell}”,
“交易日期”:“${storeData.transactionDate}”,
});
});
}

我认为您的问题在于,flatter将调用
\u sendToDatabaseWithArgs
的结果分配给onTap,而不是在调用onTap时调用方法。这就是为什么在保存/热重新加载应用程序时,会看到它执行
\u sendToDatabaseWithArgs