I am trying to add an image in flutter activity. The image is chosen from the gallery of my local mobile device. But as soon as I select the image the app crashes and it shows the following error:

java.lang.RuntimeException: Failure delivering result ResultInfo{who=null, request=69, result=0, data=null} to activity {com.example.MainActivity}: java.lang.IllegalStateException: Reply already submitted

I am using ImagePicker and cropPicker but it seems that imagepicker is not working perfectly. Once I select the image I want the image to be shown in the CircleAvatar but that is not happening. Following is my code:

class Signup extends StatefulWidget {
  @override
  _SignupState createState() => _SignupState();
}

class _SignupState extends State<Signup> {
    Widget build(BuildContext context) {
    return Scaffold(
      body: SafeArea(
        child: SizedBox(
          width: double.infinity,
          child: Padding(
            padding:
            EdgeInsets.symmetric(horizontal: getProportionateScreenWidth(20)),
            child: SingleChildScrollView(
              child: Column(
                children: [
                  SizedBox(height: SizeConfig.screenHeight * 0.04), // 4%
                  SizedBox(height: SizeConfig.screenHeight * 0.08),
                  Stack(
                      alignment: Alignment.bottomRight,
                      children: <Widget>[
                        CircleAvatar(
                          radius: 40,
                          child: _pickedImage == null ? Icon(Icons.person) : null,
                          backgroundImage: _pickedImage != null ? FileImage(_pickedImage) : null,
                        ),
                        Padding(
                          padding: EdgeInsets.all(0.0),
                          child: GestureDetector(
                              onTap: () {
                                _showPickOptionsDialog(context);
                              },
                              child: Icon(
                                Icons.camera_alt_outlined,
                              )
                          ),
                        ),
                      ]
                  ),
                ],
              ),
            ),
          ),
        ),
      ),
    );
  }

  _loadPicker(ImageSource source) async {
    File picked = await ImagePicker.pickImage(source: source);
    if (picked != null) {
      _cropImage(picked);
    }
    Navigator.pop(context);
  }

  _cropImage(File picked) async {
    File cropped = await ImageCropper.cropImage(
      androidUiSettings: AndroidUiSettings(
        statusBarColor: Colors.red,
        toolbarColor: Colors.red,
        toolbarTitle: "Crop Image",
        toolbarWidgetColor: Colors.white,
      ),
      sourcePath: picked.path,
      aspectRatioPresets: [
        CropAspectRatioPreset.original,
        CropAspectRatioPreset.ratio16x9,
        CropAspectRatioPreset.ratio4x3,
      ],
      maxWidth: 800,
    );
    if (cropped != null) {
      setState(() {
        _pickedImage = cropped;
      });
    }
  }

  void _showPickOptionsDialog(BuildContext context) {
    showDialog(context: context,
        builder: (context) => AlertDialog(
          content: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              ListTile(
                title: Text('Pick from Gallery'),
                onTap: (){
                  _loadPicker(ImageSource.gallery);
                },
              ),
              ListTile(
                title: Text('Take a Picture'),
                onTap: (){
                  _loadPicker(ImageSource.camera);
                },
              ),
            ],
          ),
        )
    );
  }
}

Can someone help me with this please?


Solution 1: Shubham Narkhede

You need to add the following code into your android manifest file

  <activity
   android:name="com.yalantis.ucrop.UCropActivity"
   android:screenOrientation="portrait"
   android:theme="@style/Theme.AppCompat.Light.NoActionBar"/>