当前位置: 首页 > 知识库问答 >
问题:

如果在颤振应用程序中未使用body:Form,则不会提交或保存我的表单数据

牧宁
2023-03-14

如果在颤振应用程序中未使用body:Form,则不会提交或保存我的表单数据。

如果使用了body:Form而不是SingleChildScrollView,则由12到13个文本项组成的我的整个表单页面或小部件不可见,包括“上载”或“提交”按钮。

这是我的密码

  body: Form(
      key: formKey,
        child: Center(
        child: Column(
    children: <Widget>[
    SizedBox(height: 20,), //just for spacing
    Column(
    mainAxisAlignment: MainAxisAlignment.start,

    children: <Widget>[
    Padding(padding: EdgeInsets.only(top: 15)),
              Container(
                child: imageFile==null?
                FlatButton(
                    onPressed: (){
                      _showDialog();
                    },
                    child: Icon(Icons.add_a_photo,size: 80,color: Color(0xffff2fc3),)
                ):
                Image.file(imageFile,width: 200,height: 100,),
              ),

              SizedBox(height: 10,),
      Row(
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        children: <Widget>[
                  Expanded(
                    flex: 1,
                    child: Padding(
                      padding: const EdgeInsets.all(8.0),
                    child: Theme(
                      data: ThemeData(
                        hintColor: Colors.blue,
                      ),
                      child: TextFormField(
                        validator: (value){
                          if(value.isEmpty){
                            return "Please write  a";
                          }else {
                            a = value;
                          }
                        },

                        keyboardType: TextInputType.name,
                        autofocus: false,
                        decoration: InputDecoration(
                          labelText: 'A',
                        
                        ),
                        maxLength: 15,


                      ),
                    ),
                  ),
                  ),


                  Expanded(
                    flex: 1,
                    child: Padding(
                      padding: const EdgeInsets.all(8.0),
                      child: Theme(
                        data: ThemeData(
                          hintColor: Colors.blue,
                        ),

                        child: TextFormField(
                        validator: (value){
                          if(value.isEmpty){
                            return "Please write the b";
                          }else {
                            b= value;
                          }
                        },

                        keyboardType: TextInputType.name,
                        autofocus: false,
                        decoration: InputDecoration(
                          labelText: 'B',
                        
                        ),
                        maxLength: 15,


                        ),

                      ),
                  ),
                  ),
],
      ),




      Row(
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        children: <Widget>[
                  Expanded(
                    flex: 1,
                    child: Padding(
                      padding: const EdgeInsets.all(8.0),
                      child: Theme(
                        data: ThemeData(
                          hintColor: Colors.blue,
                        ),

                      child: TextFormField(
                        validator: (value){
                          if(value.isEmpty){
                            return "Please write the C";
                          }else {
                           c = value;
                          }
                        },

                        keyboardType: TextInputType.name,
                        autofocus: false,
                        decoration: InputDecoration(
                          labelText: 'C',
                     
                        ),
                        maxLength: 15,


                      ),

                      ),
                    ),
                  ),



                  Expanded(
                    flex: 1,
                    child: Padding(
                      padding: const EdgeInsets.all(8.0),
                      child: Theme(
                        data: ThemeData(
                          hintColor: Colors.blue,
                        ),

                        child: TextFormField(
                          validator: (value){
                            if(value.isEmpty){
                              return "Please write the D";
                            }else {
                              d = value;
                            }
                          },

                          keyboardType: TextInputType.name,
                          autofocus: false,
                          decoration: InputDecoration(
                            labelText: 'D',
                           
                          ),
                          maxLength: 15,


                        ),

                      ),
                    ),
                  ),
],
      ),


      Row(
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        children: <Widget>[
                  Expanded(
                    flex: 1,
                    child: Padding(
                      padding: const EdgeInsets.all(8.0),
                      child: Theme(
                        data: ThemeData(
                          hintColor: Colors.blue,
                        ),

                        child: TextFormField(
                          validator: (value){
                            if(value.isEmpty){
                              return "Please write the E";
                            }else {
                              e = value;
                            }
                          },

                          keyboardType: TextInputType.name,
                          autofocus: false,
                          decoration: InputDecoration(
                            labelText: 'E ',
                           
                          ),
                          maxLength: 15,


                        ),

                      ),
                    ),
                  ),

                  Expanded(
                    flex: 1,
                    child: Padding(
                      padding: const EdgeInsets.all(8.0),
                      child: Theme(
                        data: ThemeData(
                          hintColor: Colors.blue,
                        ),

                        child: TextFormField(
                          validator: (value){
                            if(value.isEmpty){
                              return "Please write the F";
                            }else {
                              f = value;
                            }
                          },

                          keyboardType: TextInputType.number,
                          autofocus: false,
                          decoration: InputDecoration(
                            labelText: 'F',
                      
                          ),
                          maxLength: 15,


                        ),

                      ),
                    ),
                  ),

        ],
      ),


      Row(
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        children: <Widget>[
                  Expanded(
                    flex: 1,
                    child: Padding(
                      padding: const EdgeInsets.all(8.0),
                      child: Theme(
                        data: ThemeData(
                          hintColor: Colors.blue,
                        ),

                        child: TextFormField(
                          validator: (value){
                            if(value.isEmpty){
                              return "Please write the G";
                            }else {
                             g = value;
                            }
                          },

                          keyboardType: TextInputType.name,
                          autofocus: false,
                          decoration: InputDecoration(
                            labelText: ' G ',
                           
                          ),
                          maxLength: 15,


                        ),

                      ),
                    ),
                  ),

                      Expanded(
                        flex: 1,
                        child: Padding(
                          padding: const EdgeInsets.all(8.0),
                          child: Theme(
                            data: ThemeData(
                              hintColor: Colors.blue,
                            ),

                            child: TextFormField(
                              validator: (value){
                                if(value.isEmpty){
                                  return "Please write H";
                                }else {
                                  h = value;
                                }
                              },

                              keyboardType: TextInputType.name,
                              autofocus: false,
                              decoration: InputDecoration(
                                labelText: ' H  ',
                           
                              ),
                              maxLength: 15,


                            ),

                          ),
                        ),
                      ),
        ],
      ),




      Row(
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        children: <Widget>[
                      Expanded(
                        flex: 1,
                    child: Padding(
                      padding: const EdgeInsets.all(8.0),
                      child: Theme(
                        data: ThemeData(
                          hintColor: Colors.blue,
                        ),

                        child: TextFormField(
                          validator: (value){
                            if(value.isEmpty){
                              return "Please write the I";
                            }else {
                              i = value;
                            }
                          },

                          keyboardType: TextInputType.number,
                          autofocus: false,
                          decoration: InputDecoration(
                            labelText: 'I',
                      
                        ),
                          maxLength: 15,


                        ),

                      ),
                    ),
                  ),





                  Expanded(
                    flex: 1,
                    child: Padding(
                      padding: const EdgeInsets.all(8.0),
                      child: Theme(
                        data: ThemeData(
                          hintColor: Colors.blue,
                        ),

                        child: TextFormField(
                          validator: (value){
                            if(value.isEmpty){
                              return "Please write J";
                            }else {
                              j = value;
                            }
                          },

                          keyboardType: TextInputType.name,
                          autofocus: false,
                          decoration: InputDecoration(
                            labelText: ' J ',
                         
                          ),
                          maxLength: 15,


                        ),

                      ),
                    ),
                  ),
        ],
      ),

    
      Row(
        mainAxisAlignment: MainAxisAlignment.spaceEvenly,
        children: <Widget>[
              Expanded(
                flex: 1,
                child: Padding(
                  padding: const EdgeInsets.all(8.0),
                  child: Theme(
                    data: ThemeData(
                      hintColor: Colors.blue,
                    ),

                    child: TextFormField(
                      validator: (value){
                        if(value.isEmpty){
                          return "Please write the K";
                        }else {
                          k = value;
                        }
                      },

                      keyboardType: TextInputType.name,
                      autofocus: false,
                      decoration: InputDecoration(
                        labelText: ' K ',
                   
                      ),
                      maxLength: 15,


                    ),

                  ),
                ),
              ),


                  SizedBox(width: 5,),



        ],
      ),






              RaisedButton(
                onPressed: (){

                  if(imageFile == null){
                    Fluttertoast.showToast(
                        msg: "Please select an image",
                        gravity: ToastGravity.CENTER,
                        toastLength: Toast.LENGTH_LONG,
                        timeInSecForIosWeb: 2
                    );
                  }else {
                    upload();
                  }

                },
                shape: RoundedRectangleBorder(
                  borderRadius: BorderRadius.circular(10),
                ),
                color: Color(0xffff2fc3),
                child: Text("Upload",style: TextStyle(fontSize: 18,color: Colors.blue),),
              )


    ],//Widget
    ),//Column

    ],Widget

        ),//column

    ),//Center

    ),//Form
   
   
    );Scaffold
  }

如果我使用了body:SingleChildScrollView,我的表单小部件正在滚动,上传或提交按钮可见,但无法将表单数据保存或存储到firebase数据库中。

如果body:Form()仅包含5项或更少,则一切正常,因为我看到了“上传”或“提交”按钮,并且能够提交表单数据。

请解决我的问题。

错误:使用scrollview并单击提交者上载按钮时

E/flatter(29120):[ERROR:flatter/lib/ui/ui\u dart\u state.cc(166)]未处理的异常:NoSuchMethodError:对null调用了方法“validate”。E/flatter(29120):接收器:null E/flatter(29120):尝试调用:validate()E/flatter(29120):#0 UploadDataState。上传(软件包:围巾存储/上传数据。dart:587)E/flatter(29120):#1上传数据状态。建筑(包装:围巾商店/上传数据。dart:519)E/颤振(29120):#2#_把手(包装:颤振/src/材料/墨水井。省道:992)E/颤振(29120):#3!。建筑(包装:flift/src/material/ink_well.省道:1098)E/flift(29120):#4手势识别器。invokeCallback(包:flatter/src/signatures/recognizer.dart:184)E/flatter(29120):#5个TapGestureCongnizer。手拍(套装:flift/src/signatures/tap.dart:524)E/flift(29120):#6 BaseTapgestureRecognitor_检查(软件包:flatter/src/signatures/tap.dart:301)E/flatter(29120):#7 BaseTapgestureRecognitor。接受手势(套装:flatter/src/signatures/tap.dart:256)E/flatter(29120):#8手势管理器。横扫(套装:颤振/src/手势/arena.dart:158)E/颤振(29120):#9手势绑定。handleEvent(套装:flatter/src/signatures/binding.dart:224)E/flatter(29120):#10个手势绑定。dispatchEvent(包:flatter/src/signatures/binding.dart:200)E/flatter(29120):#11手势绑定_手点事件(包装:flift/src/signatures/binding.dart:158)E/flift(29120):#12手势绑定_flushPointerEventQueue(包装:flatter/src/signatures/binding.dart:104)E/flatter(29120):#13手势绑定_handlePointerDataPacket(包:flatter/src/signities/binding.dart:88)E/flatter(29120):#14 RootRunnary(dart:async/zone.dart:1206)E/flatter(29120):#15 CustomZone。一元(dart:async/zone.dart:1100)E/flatter(29120):#16_自定义区域。runUnaryGuarded(dart:async/zone.dart:1005)E/flutter(29120):#17 invoke1(dart:ui/hooks.dart:267)E/flutter(29120):#18 dispatchPointerDataPacket(dart:ui/hooks.dart:176)E/flutter(29120):

共有1个答案

斜光耀
2023-03-14

请试试这个:

body: SingleChildScrollView(
  child: Center(
   child: Form(
    key: formKey,
    child: Column(
      mainAxisAlignment: MainAxisAlignment.start,
      children: <Widget>[
        SizedBox(height: 20,), //just for spacing
        .....// OTHER WIDGETS
      ],
     ),
    ),
  ),
),
 类似资料:
  • 问题内容: 我不确定我要去哪里。这个想法是在提交表单之前,输入字段之一通过ajax发送到服务器端验证器。如果响应为1,则输入有效且应提交表单。如果响应为0,则不应提交该表单。问题是我不知道如何在ajax请求函数中设置一个变量,以防止表单被提交。这就是我所拥有的: 问题答案: 问题在于请求是异步的,需要一段时间才能完成。因此,该函数会继续执行并在成功执行事件之前返回false。 为了解决这个问题,您

  • 我已经做了一个颤振应用。发布的apk大约为14MB。我搜索了一些方法来缩小这个范围,并发现了以下内容:https://flutter.io/android-release/#enabling-前卫 但我的问题是,我怎样才能知道我在步骤1中使用的所有附加库?是否有任何命令可以了解它们,或者只是我添加到? 我需要如何在这个文件?

  • 我试图在Flutter中创建一个API请求,但我得到以下错误作为响应 类型'列表 我试图创建第一个API,请让我知道,如果方法是好的 这是我的密码 这是我的示例API

  • 在尝试使用STOMP、websockets时,在用所需的STOMP/WebSocket细节更新pubspec后,面临着“包获取”的问题。我试过stomp、stompdart、websocket,但都不起作用。运行“Packages Get”时观察到的错误是“当前Dart SDK版本是2.1.0-Dev.4.0。Flutter-4EB879133A。 因为project_name依赖于stompda

  • 我只是按照这个页面的说明做了一个Flutter app,我在谷歌上搜索了如何更改应用程序的名称,找到了这个答案。但是我不能从清单文件中更改应用程序的名称。最初是。我将其更改为,它给出了错误 如何重置此错误并更改名称?