Reputation: 6070
I am trying to create these fields in firestore using flutter but I can keep getting this error. I have seen another person has posted a similar question here but his solution preferred does not solve my question. Excerpt of my code is below
GestureDetector(
onTap: (){
return showDialog(
context: context,
builder: (context){
return Center(
child: Material(
child: Padding(
padding: EdgeInsets.only(left: 20, right: 20, top: 10),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10)
),
height: 160,
width: 250,
child: Column(
children: [
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10)
),
child: Form(
key: _mobiileKey,
autovalidate: _autoValidate,
child: TextFormField(
maxLines: 1,
autofocus: false,
keyboardType: TextInputType.phone,
onChanged: (value) {
mobile = value;
},
validator: validateMobile,
onSaved: (value) => mobile = value,
style: TextStyle(
color: Colors.black,
),
decoration: InputDecoration(
focusedBorder: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(4)),
borderSide: BorderSide(width: 1,color: Palette.mainColor),
),
border: OutlineInputBorder(),
labelText: 'Phone Number',
prefixIcon: Icon(Icons.phone_android,
color: Colors.black,),
labelStyle: TextStyle(
fontSize: 15,
color: Colors.black,
)
),
),
),
),
Padding(
padding: EdgeInsets.only(top: 10),
child: MaterialButton(
onPressed: validateAndSubmit(title, price, thumbnailUrl, mobile),
child: Text('PROCEED TO ORDER',
style: TextStyle(
fontSize: 15,
fontWeight: FontWeight.bold,
),
),
color: Color(0xff706695),
elevation: 0,
minWidth: 400,
height: 50,
textColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10)
),
),
),
],
),
),
)
)
);
}
);
print('Orders');
},
)
AND THIS IS THE validateAndSubmit function
validateAndSubmit (title, price, thumbnailUrl, mobile) async {
if (validateAndSave()){
setState(() {
loading = true;
});
try{
Navigator.pushReplacement(context,
MaterialPageRoute(builder: (context) => BottomNavScreen()));
User user = auth.currentUser;
await db.doc(widget.productId).set({
'uid': user.uid,
"Product Title": title,
"Product Price": price,
"Mobile Number": mobile,
"thumbnail": thumbnailUrl,
"Published Date": DateTime.now(),
}).then((value) => null);
} catch (e){
}
}
}
AND THIS IS THE ERROR MESSAGE
type 'Future' is not a subtype of type '() => void'
Any help is welcome.
Upvotes: 1
Views: 747
Reputation: 1771
change:
onPressed: validateAndSubmit(title, price, thumbnailUrl, mobile),
to:
onPressed:(){
validateAndSubmit(title, price, thumbnailUrl, mobile);
}
I think this may be the issue. onPressed needs a void
. Let me know if this works.
Upvotes: 2