FormBuilderCustomField(
attribute: "file",
validators: [
FormBuilderValidators.required(),
],
formField: FormField(
enabled: true,
builder: (FormFieldState<dynamic> field) {
return InputDecorator(
decoration: InputDecoration(
labelText: "Select option",
contentPadding:
EdgeInsets.only(top: 10.0, bottom: 0.0),
border: InputBorder.none,
),
child: Column(children: <Widget>[
RaisedButton(
onPressed: (){
_takePhoto(field);
},
child: Text("拍照"),
)
])
);
},
),
),
_takePhoto(FormFieldState<dynamic> field) async {
var image = await ImagePicker.pickImage(source: ImageSource.camera);
setState(() {
field.setValue(image);
});
}
Expanded(
child: RaisedButton(
padding: EdgeInsets.all(15.0),
child: Text('登录'),
color: Theme.of(context).primaryColor,
textColor: Colors.white,
onPressed: () {
print("*************111**************");
// print(_fbKey.currentState);
// print(_fbKey.currentState.value);
if (_fbKey.currentState.validate()) {
_fbKey.currentState.save();
loginAuthToken(_fbKey.currentState.value);
print(_fbKey.currentState.value);
saveToken("ABC");
}
}),
)
FormBuilder(
key: _fbKey, //设置GlobalKey,用于后面获取FormState
autovalidate: true, //开启自动校验
)
使用自定义FormBuilder上传图片与服务器交互