how do i create a fluttery image?

This code is very ambiguous, it’s very unclear where you are calling getImage and where you are setting the image.

I suppose you are not calling getImage() properly and not sure where you are using this if (pickedImage == null) return; it might be wrong.

Anyway, here’s a proper explanation it should work.

  • Declare your getImage method inside the Widget class.
Future<File> getImage(int type) async {
   PickedFile pickedImage = await ImagePicker().getImage(
      source: type == 1 ? ImageSource.camera : 
      ImageSource.gallery,
      imageQuality: 50
    );
    return pickedImage;
  }
  • Declare the File state variable in the sate class
File imageFile;
  • Have a Button for the selecting action of the image in your widget.
...
   IconButton(
     icon: Icon(Icons.gallery),
     onPressed: () {}
   )
...
  • call the getImage method and setState the result in the onPressed handler.
...
   IconButton(
     icon: Icon(Icons.gallery),
     onPressed: () async {
      final tmpFile = await getImage(1);
       
        setState(() {
          imageFile = tmpFile;
      });
   )
...

  • Display your file in a widget
 imageFile != null
           ?Image.file(
            imageFile,
            height: MediaQuery.of(context).size.height / 5,
          ): Text("Pick up the image"),

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top