'Method Exception found while using the image picker in flutter

I am getting a error in the image picker plugin. Have tried all the resources from stack overflow and am really stuck with this from past two days.

Whenevr I am trying to upload any file, the console is popping up errors and nothing is happening Have tried editing those gradle files and also those tried flutter clean after then have restared the app several times. But nothing happens

Error Log:

[ERROR:flutter/lib/ui/ui_dart_state.cc(177)] Unhandled Exception: MissingPluginException(No implementation found for method pickImage on channel plugins.flutter.io/image_picker)
E/flutter ( 9799): #0      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:157:7)
E/flutter ( 9799): <asynchronous suspension>
E/flutter ( 9799): #1      MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:332:12)
E/flutter ( 9799): #2      MethodChannelImagePicker.pickImagePath (package:image_picker_platform_interface/src/method_channel/method_channel_image_picker.dart:62:21)

My code:

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

class Upload extends StatefulWidget {
  @override
  _UploadState createState() => _UploadState();
}

class _UploadState extends State<Upload> {
  File _image;
  final picker = ImagePicker();

  Future getImage() async {
    final pickedFile = await picker.getImage(source: ImageSource.camera);

    setState(() {
      if (pickedFile != null) {
        _image = File(pickedFile.path);
      } else {
        print('No image selected.');
      }
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: _image == null ? Text('No image selected.') : Image.file(_image),
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: getImage,
        tooltip: 'Pick Image',
        child: Icon(Icons.add_a_photo),
      ),
    );
  }
}

other warnings:

Note: C:\Users\user\AppData\Local\Pub\Cache\hosted\pub.dartlang.org\firebase_core_web-0.1.1+2\android\src\main\java\io\flutter\plugins\firebase_core_web\FirebaseCoreWebPlugin.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: C:\Users\user\AppData\Local\Pub\Cache\hosted\pub.dartlang.org\firebase_core-0.4.5\android\src\main\java\io\flutter\plugins\firebase\core\FirebaseCorePlugin.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: Some input files use or override a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
Note: C:\Users\user\AppData\Local\Pub\Cache\hosted\pub.dartlang.org\firebase_auth-0.14.0+9\android\src\main\java\io\flutter\plugins\firebaseauth\FirebaseAuthPlugin.java uses or overrides a deprecated API.
Note: Recompile with -Xlint:deprecation for details.
C:\Users\user\AppData\Local\Pub\Cache\hosted\pub.dartlang.org\firebase_storage-3.1.6\android\src\main\java\io\flutter\plugins\firebase\storage\FirebaseStoragePlugin.java:31: warning: [deprecation] PluginRegistry in io.flutter.plugin.common has been deprecated


Solution 1:[1]

There might be an issue with the version of Image Picker. Use an older version and check.

Solution 2:[2]

use the latest version of Image_Picker

pickVideo and pickImage is deprecated, Use getVideo and getImage instead

and getVideo and getImage are not static methods so create an instance of ImagePicker and then try to call it

use this code

ImagePicker picker  = ImagePicker();
final pickedFile = await picker.pickVideo(source: ImageSource.gallery,);

if (pickedFile.path != null) {
 File pickedVideo = File(pickedFile.path);
}

Solution 3:[3]

In the new version you need to create an instance of the ImagePicker. Also the method is no longer "pickImage" but "getImage". The same with "pickVideo" is changed now to "getVideo". And last but not least, you need to use "PickedFile" in order to access it and you have to read the file by the async method "readAsBytes". So quite some changes in the new version. This is an example on how the code could look like.

ImagePicker _picker = new ImagePicker();
PickedFile file = await _picker.getVideo(source: ImageSource.camera);
Uint8List bytes = await file.readAsBytes();
String barcode = await scanner.scanBytes(bytes);

Solution 4:[4]

just stop the app and again rerun will work perfectly fine

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 jeugene
Solution 2
Solution 3 H.A.
Solution 4 Rizz wann