2

I tried to save image in image upload form using image picker, I used "OnSaved" but there are error said "The named Parameter OnSaved isnt defined. How can I solve this?

This is the code that i use :

onSaved: (val) => _image = val,

This is the complete code:

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),
                    )),

1 Answer 1

1

there is no onSaved property in the Center widget. You can use a button instead and utilize the onPressed property or any other approach that you prefer.

Sign up to request clarification or add additional context in comments.

2 Comments

It doesnt work, I've tried with FlatButton but onSave still isnt defined
as mentioned in my answer, onPressed property is to be used. there is no onSaved property in FlatButton widget. please refer to the Flutter docs for more info about widgets.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.