My Form data is not getting submitted or saved if body:Form is not used in flutter appplication.
If body:Form is used and not SingleChildScrollView my total form page or Widget which consists of 12 to 13 Text Items are not visible including the 'Upload' or Submit' Button.
Here is my code
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
}
And If I have used body:SingleChildScrollView my form Widget is scrolling and Upload or Submit button is visible but unable to save or store the Form data into firebase database.
If body:Form ( ) conatins only 5 items or less ,everything is working fine as I am seeing 'Upload' or 'submit' Button and able to submit the form data.
Please fix my issue.
Error: when scrollview is used and clicked on submitor upload button
E/flutter (29120): [ERROR:flutter/lib/ui/ui_dart_state.cc(166)] Unhandled Exception: NoSuchMethodError: The method 'validate' was called on null. E/flutter (29120): Receiver: null E/flutter (29120): Tried calling: validate() E/flutter (29120): #0 _UploadDataState.upload (package:scarves_store/UploadData.dart:587) E/flutter (29120): #1 _UploadDataState.build. (package:scarves_store/UploadData.dart:519) E/flutter (29120): #2 _InkResponseState._handleTap (package:flutter/src/material/ink_well.dart:992) E/flutter (29120): #3 _InkResponseState.build. (package:flutter/src/material/ink_well.dart:1098) E/flutter (29120): #4 GestureRecognizer.invokeCallback (package:flutter/src/gestures/recognizer.dart:184) E/flutter (29120): #5 TapGestureRecognizer.handleTapUp (package:flutter/src/gestures/tap.dart:524) E/flutter (29120): #6 BaseTapGestureRecognizer._checkUp (package:flutter/src/gestures/tap.dart:301) E/flutter (29120): #7 BaseTapGestureRecognizer.acceptGesture (package:flutter/src/gestures/tap.dart:256) E/flutter (29120): #8 GestureArenaManager.sweep (package:flutter/src/gestures/arena.dart:158) E/flutter (29120): #9 GestureBinding.handleEvent (package:flutter/src/gestures/binding.dart:224) E/flutter (29120): #10 GestureBinding.dispatchEvent (package:flutter/src/gestures/binding.dart:200) E/flutter (29120): #11 GestureBinding._handlePointerEvent (package:flutter/src/gestures/binding.dart:158) E/flutter (29120): #12 GestureBinding._flushPointerEventQueue (package:flutter/src/gestures/binding.dart:104) E/flutter (29120): #13 GestureBinding._handlePointerDataPacket (package:flutter/src/gestures/binding.dart:88) E/flutter (29120): #14 _rootRunUnary (dart:async/zone.dart:1206) E/flutter (29120): #15 _CustomZone.runUnary (dart:async/zone.dart:1100) E/flutter (29120): #16 _CustomZone.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):