skip to Main Content

I try to use upload image from Flutter libary, but it doesn’t work. The codes just run to gallery and choose the image, but the image doesn’t show to the screen.

Please help me to make it work, from choosing the image and show the image result that I choose. Thanks

Image 1

Image 2

2

Answers


  1. You have to update the state of the screen for seeing the changes. If you are using stateful just simply use setState to do this.

    setState(() {
      uploadFile = File(image!.path);
    });
    
    Login or Signup to reply.
  2. I hope this answer will help you.

    static String? pickImage({bool useCamera = false, bool crop = true,
          CropAspectRatio ratio = const CropAspectRatio(
            ratioX: 1, ratioY: 1,
          )}) {
        ImagePicker().pickImage(source: useCamera ? ImageSource.camera : ImageSource.gallery, imageQuality: 60).then((pickedFile) {
          if (pickedFile == null || !File(pickedFile.path).existsSync()) {
            return Stream.error(Exception('No image picked!'));
          }
          if (crop) {
            ImageCropper().cropImage(sourcePath: pickedFile.path ?? '', aspectRatio: ratio, uiSettings: [
              AndroidUiSettings(
                  toolbarTitle: 'Cropper',
                  toolbarColor: AppStyles.primary500Color,
                  toolbarWidgetColor: Colors.white,
                  initAspectRatio: CropAspectRatioPreset.original,
                  lockAspectRatio: false),
              IOSUiSettings(
                title: 'Cropper',
              ),
            ]).then((value) {
              if (value != null) {
                croppedFile = value;
                // selectedPhotoStream.add(croppedFile);
                /// ** You are missing **
                setState((){
                  uploadFile = croppedFile.path;
                });  
                return croppedFile?.path;
              }
            });
          }
        });
        return croppedFile?.path;
      }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search