Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/flutter/10.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
Firebase 如何在按下提交按钮时验证颤振中的图像?_Firebase_Flutter - Fatal编程技术网

Firebase 如何在按下提交按钮时验证颤振中的图像?

Firebase 如何在按下提交按钮时验证颤振中的图像?,firebase,flutter,Firebase,Flutter,我的每个文本字段都得到验证。但是如果没有选择图像,我按submit。它在没有图像的情况下成功上载到firestore。但我想让它停止,以防图像为空。当我加载图像时,它会显示在buildGridView中。我想我需要在这里的某个地方应用逻辑。如果buildGridView为空。停下来什么的。我怎样才能做到这一点。谢谢 Widget AddPost() { return Form( key: _key, autovalidate: _v

我的每个文本字段都得到验证。但是如果没有选择图像,我按submit。它在没有图像的情况下成功上载到firestore。但我想让它停止,以防图像为空。当我加载图像时,它会显示在buildGridView中。我想我需要在这里的某个地方应用逻辑。如果buildGridView为空。停下来什么的。我怎样才能做到这一点。谢谢

    Widget AddPost() {
        return Form(
          key: _key,
          autovalidate: _validate,
          child: Padding(
              padding: const EdgeInsets.fromLTRB(0.0, 20.0, 0.0, 0.0),
              child: Column(
                children: <Widget>[
                  _getPropertyTypeDropDown(),
                  _getPropertyTypeDetailDropDown(),
    
                  UploadPropertyImages(),
                  Container(
                    margin: EdgeInsets.only(left: 7),
                    child: Column(
                      mainAxisAlignment: MainAxisAlignment.spaceAround,
                      children: <Widget>[
                          width: 200,
                          height: MediaQuery.of(context).size.height / 4,
                          //color: Colors.green,
                          child: buildGridView(),
                        ),
                        RaisedButton(
                          child: Text("Submit"),
                          onPressed: () async {
                            if (_key.currentState.validate()) {
                              _key.currentState.save();
                              Alert(
                                context: context,
                                style: alertStyle,
                                type: AlertType.info,
                                title: "YEY !!",
                                desc: "Your Ad will be displayed soon.",
                                buttons: [
                                  DialogButton(
                                    child: Text(
                                      "Thankyou",
                                      style: TextStyle(color: Colors.white, fontSize: 20),
                                    ),
                              //      onPressed: () => Navigator.pop(context),
                                    color: Color.fromRGBO(0, 179, 134, 1.0),
                                    radius: BorderRadius.circular(0.0),
                                  ),
                                ],
                              ).show();
                              await runMyFutureGetImagesReference();
                                Navigator.push(
                                    context,
                                    MaterialPageRoute(
                                        builder: (context) => RoleCheck()));
    
                            } else {
                              setState(() {
                                _validate = true;
                              });
                            }
                          },
                          textColor: Colors.black,
                          padding: EdgeInsets.fromLTRB(10, 10, 10, 10),
                          splashColor: Colors.grey,
                        ),
                      ],
                    ),
                  ),
    
                  //_showSubmitButton(),
                ],
              )),
        );
      }


  Widget buildGridView() {
    return GridView.count(
      crossAxisCount: 3,
      children: List.generate(images.length, (index) {
        Asset asset = images[index];
        print(asset.getByteData(quality: 100));
        return Padding(
          padding: EdgeInsets.all(8.0),
          child: ClipRRect(
            borderRadius: BorderRadius.all(Radius.circular(15)),
            child: Container(
              decoration: BoxDecoration(
                  border: Border.all(color: Colors.blueAccent, width: 2)),
              child: AssetThumb(
                asset: asset,
                width: 300,
                height: 300,
              ),
            ),
          ),
          //  ),
        );
      }),
    );
  }


  Widget UploadPropertyImages() {
    return Container(
        child: Center(
            child: Padding(
      padding: const EdgeInsets.fromLTRB(10, 10, 10, 10),
      child: Column(
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        children: <Widget>[
          NiceButton(
              width: 250,
              elevation: 8.0,
              radius: 52.0,
              text: "Select Images",
              background: Colors.blueAccent,
              onPressed: () async {
                List<Asset> asst = await loadAssets();
                if (asst.length == 0) {
                  showInSnackBar("No images selected");
                }
                // SizedBox(height: 10,);
                else {
                  showInSnackBar('Images Successfully loaded');
                }
              }),

        ],
      ),
    )));
  }

Widget build(BuildContext context) {
    return Scaffold(
//      backgroundColor: Colors.grey[600],
      key: _scaffoldKey,
      body: Container(

        padding: EdgeInsets.all(16.0),
        child: Form(
          child: ListView(
            shrinkWrap: true,
            children: <Widget>[
              Center(
                child: Text(
                  "Post New Ad",
                  style: TextStyle(fontSize: 30, fontWeight: FontWeight.bold),
                ),
              ),
              AddPost(),
              Padding(
                padding: EdgeInsets.fromLTRB(0, 0, 0, 16),
              ),
            ], //:TODO: implement upload pictures
          ),
        ),
      ),
    );
 }

Future<List<Asset>> loadAssets() async {
    List<Asset> resultList = List<Asset>();
    String error = "No error Detected";

    try {
      resultList = await MultiImagePicker.pickImages(
        maxImages: 10,
        enableCamera: true,
        selectedAssets: images,
        cupertinoOptions: CupertinoOptions(takePhotoIcon: "chat"),
        materialOptions: MaterialOptions(
          actionBarColor: "#abcdef",
          actionBarTitle: "Upload Image",
          allViewTitle: "All Photos",
          useDetailsView: false,
          selectCircleStrokeColor: "#000000",
        ),
      );

      print(resultList.length.toString() + "it is result list");
      /*  print((await resultList[0].getThumbByteData(122, 100)));
      print((await resultList[0].getByteData()));
      print((await resultList[0].metadata));*/
      print("loadAssets is called");
    } on Exception catch (e) {
      error = e.toString();
      print(error.toString() + "on catch of load assest");
    }
Widget AddPost(){
报税表(
键:_键,
自动验证:_验证,
孩子:填充(
填充:从LTRB(0.0,20.0,0.0,0.0)开始的常数边设置,
子:列(
儿童:[
_getPropertyTypeDropDown(),
_getPropertyTypeDetailDropDown(),
UploadPropertyImages(),
容器(
页边距:仅限边集(左:7),
子:列(
mainAxisAlignment:mainAxisAlignment.spaceAround,
儿童:[
宽度:200,
高度:MediaQuery.of(context).size.height/4,
//颜色:颜色。绿色,
子级:buildGridView(),
),
升起的按钮(
儿童:文本(“提交”),
onPressed:()异步{
if(_key.currentState.validate()){
_key.currentState.save();
警觉的(
上下文:上下文,
风格:alertStyle,
类型:AlertType.info,
标题:“耶!!”,
描述:“您的广告很快就会显示出来。”,
按钮:[
对话框按钮(
子:文本(
“谢谢”,
样式:TextStyle(颜色:Colors.white,字体大小:20),
),
//onPressed:()=>Navigator.pop(上下文),
颜色:颜色。来自RGBO(0,179,134,1.0),
半径:边界半径。圆形(0.0),
),
],
).show();
等待runMyFutureGetImagesReference();
导航器。推(
上下文
材料路线(
生成器:(context)=>RoleCheck());
}否则{
设置状态(){
_验证=真;
});
}
},
textColor:Colors.black,
填充:从LTRB(10,10,10,10)开始的边缘设置,
颜色:颜色。灰色,
),
],
),
),
//_showSubmitButton(),
],
)),
);
}
Widget buildGridView(){
返回GridView.count(
交叉轴计数:3,
子项:List.generate(images.length,(index){
资产=图像[索引];
打印(asset.getByteData(质量:100));
返回填充(
填充:边缘设置。全部(8.0),
孩子:ClipRRect(
borderRadius:borderRadius.all(半径.圆形(15)),
子:容器(
装饰:盒子装饰(
边框:border.all(颜色:Colors.blueAccent,宽度:2)),
子女:阿塞特姆(
资产:资产,,
宽度:300,
身高:300,
),
),
),
//  ),
);
}),
);
}
Widget UploadPropertyImages(){
返回容器(
儿童:中心(
孩子:填充(
填充:从LTRB(10,10,10,10)开始的常数边集,
子:列(
mainAxisAlignment:mainAxisAlignment.space,
儿童:[
纽扣(
宽度:250,
标高:8.0,
半径:52.0,
文本:“选择图像”,
背景:Colors.blueAccent,
onPressed:()异步{
列表助理=等待加载资产();
如果(关联长度==0){
ShowInNackBar(“未选择图像”);
}
//尺寸箱(高度:10,);
否则{
ShowInNackBar(“已成功加载图像”);
}
}),
],
),
)));
}
小部件构建(构建上下文){
返回脚手架(
//背景颜色:颜色。灰色[600],
钥匙:_scaffoldKey,
主体:容器(
填充:所有边缘设置(16.0),
孩子:表格(
子:ListView(
收缩膜:对,
儿童:[
居中(
子:文本(
“发布新广告”,
样式:TextStyle(fontSize:30,fontWeight:fontWeight.bold),
),
),
AddPost(),
填充物(
填充:来自LTRB(0,0,0,16)的边插入集,
),
],/:TODO:实现图片上传
),
),
),
);
}
Future loadAssets()异步{
List resultList=List();
String error=“未检测到错误”;
试一试{
结果列表=等待MultiImagePicker.pickImages(
最高限额:10,
启用摄像头:正确,
所选资产:图像,
杯具选择:
ImagePickerFormField(  
  child: Container(  
    height: 40,  
  child: Center(child: Text("Select Photo")),  
  width: double.infinity,  
  decoration: BoxDecoration(  
        borderRadius: BorderRadius.all(Radius.circular(8)),  
  border: Border.all(  
            color: Theme.of(context).disabledColor, width: 1)),  
  ),  
  previewEnabled: true,  
  autovalidate: true,  
  context: context,  
  onSaved: (File value) {  
    print("on saved called");  
  },  
  validator: (File value) {  
    if (value == null)  
      return "Please select a photo!";  
 else return null;  },  
  initialValue: null, //File("some source")  
)