我需要一些帮助。我的任务是选择位置和地址并提交。但由于某些原因, _addPointKey.currentState.validate() 总是给出 false。
我有一个用于获取地址的 TextFormField、一个位置预览容器、一个用于打开 google_map_location_picker 的按钮,最后一个用于提交数据的按钮。所有这些字段都在带有 _addPointKey 键的表单内声明。
表单验证确实有效,即如果字段为空,它会以红色显示字段不能为空。但是,我在提交整个表单数据时仍然遇到一些问题。textFormField 变为 null。
我使用 google_map_location_picker 包来选择位置。有人可以帮忙吗?
提前致谢。
final GlobalKey<FormState> _addPointKey = GlobalKey<FormState>();
Map<String, dynamic> formData = {
"address": null,
};
Widget _addressField() {
return Container(
margin: EdgeInsets.symmetric(vertical: 10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
"Address of the Collection Center",
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 15,
color: Theme.of(context).primaryColor),
),
SizedBox(
height: 10,
),
TextFormField(
decoration: InputDecoration(
border: InputBorder.none,
fillColor: Color(0xfff3f3f4),
filled: true),
maxLines: 4,
validator: (String value) {
if (value.isEmpty) …Run Code Online (Sandbox Code Playgroud)