![](/img/trans.png)
[英]Flutter image upload when I select image from galery using image picker it will send using flutter and laravel REST API
[英]How to upload image in Flutter using Image Picker
我尝试使用图像选择器将图像保存为图像上传表单,我使用了“ OnSaved”,但出现错误消息“未定义命名参数OnSaved。如何解决此问题?
这是我使用的代码:
onSaved: (val) => _image = val,
这是完整的代码:
import 'dart:io';
import 'package:image_picker/image_picker.dart';
class NewPostScreen extends StatefulWidget {
@override
_NewPostScreen createState() => _NewPostScreen();
}
class _NewPostScreen extends State<NewPostScreen> {
File _image;
Future getImageFromGallery() async {
var image = await ImagePicker.pickImage(source: ImageSource.gallery);
setState(() {
_image = image;
});
}
@override
Widget build(BuildContext context) {
// TODO: implement build
return Container(
child: Scaffold(
key: _scaffoldkey,
appBar: AppBar(
backgroundColor: Colors.blue,
title: new Text("Create Post"),
),
resizeToAvoidBottomPadding: false,
body: SingleChildScrollView(
padding: new EdgeInsets.all(8.0),
child: Form(
key: _formkey,
child: Column(
children: <Widget>[
new TextFormField(
decoration: new InputDecoration(
/*hintText: "Tujuan",*/
labelText: "Tujuan"),
onSaved: (String val) => destination = val,
),
Padding(
padding: const EdgeInsets.all(15.0),
child: Center(
child: _image == null
? Text('Upload Foto')
: Image.file(_image),
onSaved: (val) => _image = val,
),
),
SizedBox(
width: 100.0,
height: 100.0,
child: RaisedButton(
onPressed: getImageFromGallery,
child: Icon(Icons.add_a_photo),
)),
Center
小部件中没有onSaved
属性。 您可以改用按钮,并使用onPressed
属性或您喜欢的任何其他方法。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.