Home > Back-end >  Unhandled Exception: MissingPluginException(No implementation found for method pickImage on channel
Unhandled Exception: MissingPluginException(No implementation found for method pickImage on channel

Time:06-29

I am using image_picker: ^0.8.5 3 to help me pick images from either camera or gallery. I used getx in implementing the logic and I have added android:requestLegacyExternalStorage="true" to the Android manifest file because my android version is 29 . The problem is I keep getting this disturbing error

Unhandled Exception: MissingPluginException(No implementation found for method pickImage on channel plugins.flutter.io/image_picker_android)

I have researched it and in doing that i came across

below are samples of my code

This is the logic for picking the images

import 'dart:io';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:image_picker/image_picker.dart';

class ImageController extends GetxController {
var selectedImagePath = ''.obs;
var selectedImageSize = ''.obs;

void getImage(ImageSource imageSource) async {
final pickedFile = await ImagePicker().pickImage(source: imageSource);
if (pickedFile != null) {
  selectedImagePath.value = pickedFile.path;
  selectedImageSize.value =
      ((File(selectedImagePath.value).lengthSync() / 1024 / 1024)
              .toStringAsFixed(2)  
          "Mb");
} else {
  selectedImagePath.value = '';
  selectedImageSize.value = '';

  Get.snackbar(
    "Please Select Image",
    "No Image Selected",
    snackPosition: SnackPosition.BOTTOM,
    backgroundColor: Colors.red,
    colorText: Colors.white,
    borderRadius: 10,
    margin: EdgeInsets.all(10),
    borderColor: Colors.red,
    borderWidth: 2,
    duration: Duration(seconds: 2),
    icon: Icon(
      Icons.error,
      color: Colors.white,
    ),
  );
}

} }

And I am picking the images using this code

                  GestureDetector(
                  onTap: () {
                    Get.bottomSheet(
                      Container(
                        height: currentOrientation == Orientation.portrait
                            ? screenHeight * 0.10
                            : screenHeight * 0.22,
                        width: double.infinity,
                        decoration: BoxDecoration(
                          color: ProjectColors.kPrimaryColor,
                          borderRadius: BorderRadius.only(
                            topLeft: Radius.circular(
                              currentOrientation == Orientation.portrait
                                  ? screenHeight * 0.02
                                  : screenHeight * 0.05,
                            ),
                            topRight: Radius.circular(
                              currentOrientation == Orientation.portrait
                                  ? screenHeight * 0.02
                                  : screenHeight * 0.05,
                            ),
                          ),
                        ),
                        child: Row(
                          mainAxisAlignment: MainAxisAlignment.center,
                          children: [
                            GestureDetector(
                              onTap: () {
                                imageController
                                    .getImage(ImageSource.camera);
                              },
                              child: Icon(
                                Icons.camera_alt_outlined,
                                color: ProjectColors.kWhiteColor,
                                size: currentOrientation ==
                                        Orientation.portrait
                                    ? screenHeight * 0.06
                                    : screenHeight * 0.15,
                              ),
                            ),
                            SizedBox(
                              width:
                                  currentOrientation == Orientation.portrait
                                      ? screenWidth * 0.20
                                      : screenWidth * 0.15,
                            ),
                            GestureDetector(
                              onTap: () {
                                imageController
                                    .getImage(ImageSource.gallery);
                              },
                              child: Icon(
                                Icons.image_outlined,
                                color: ProjectColors.kWhiteColor,
                                size: currentOrientation ==
                                        Orientation.portrait
                                    ? screenHeight * 0.06
                                    : screenHeight * 0.15,
                              ),
                            ),
                          ],
                        ),
                      ),
                    );
                  },
                  child: Obx(
                    () => imageController.selectedImagePath.value == ''
                        ? Container(
                            height:
                                currentOrientation == Orientation.portrait
                                    ? screenHeight * 0.20
                                    : screenHeight * 0.50,
                            width:
                                currentOrientation == Orientation.portrait
                                    ? screenWidth * 0.85
                                    : double.infinity,
                            color: Colors.white,
                            child: Icon(
                              Icons.add_box_sharp,
                              color: ProjectColors.kPrimaryColor,
                              size:
                                  currentOrientation == Orientation.portrait
                                      ? screenHeight * 0.06
                                      : screenHeight * 0.10,
                            ),
                          )
                        : Image.file(
                            File(imageController.selectedImagePath.value),
                            fit: BoxFit.cover,
                          ),
                  ),
                ),

And this is the error message I keep getting.

E/flutter ( 5139): [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: 
MissingPluginException(No implementation found for method pickImage on channel 
plugins.flutter.io/image_picker_android)
E/flutter ( 5139): #0      MethodChannel._invokeMethod 
(package:flutter/src/services/platform_channel.dart:165:7)
E/flutter ( 5139): <asynchronous suspension>
E/flutter ( 5139): #1      ImagePickerAndroid.getImage 
(package:image_picker_android/image_picker_android.dart:161:26)
E/flutter ( 5139): <asynchronous suspension>
E/flutter ( 5139): #2      ImageController.getImage 
(package:cede_mobile/controller/select_image.dart:11:24)
E/flutter ( 5139): <asynchronous suspension>
E/flutter ( 5139): 
E/flutter ( 5139): [ERROR:flutter/lib/ui/ui_dart_state.cc(198)] Unhandled Exception: 
MissingPluginException(No implementation found for method pickImage on channel 
plugins.flutter.io/image_picker_android)
E/flutter ( 5139): #0      MethodChannel._invokeMethod 
(package:flutter/src/services/platform_channel.dart:165:7)
E/flutter ( 5139): <asynchronous suspension>
E/flutter ( 5139): #1      ImagePickerAndroid.getImage 
(package:image_picker_android/image_picker_android.dart:161:26)
E/flutter ( 5139): <asynchronous suspension>
E/flutter ( 5139): #2      ImageController.getImage 
(package:cede_mobile/controller/select_image.dart:11:24)
E/flutter ( 5139): <asynchronous suspension>
E/flutter ( 5139): 

enter image description here

  • Related