【发布时间】:2021-02-06 18:38:20
【问题描述】:
我正在尝试使用颤振在 Firestore 中创建这些字段,但我会不断收到此错误。我看到另一个人在这里发布了类似的问题,但他首选的解决方案并不能解决我的问题。我的代码摘录如下
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');
},
)
这就是 validateAndSubmit 函数
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){
}
}
}
这是错误消息
类型 'Future' 不是类型 '() => void' 的子类型
欢迎任何帮助。
【问题讨论】:
标签: flutter dart google-cloud-firestore