How to resolve error of using ImagePicker in application?

Viewed 643

I used Image picker dependency in my application and after running the app it crashes again and again with the following error and I cannot figure it out. When I wrote this code and executed the code it was working fine but when I opened it the very next day on the android studio project for working it gave me this error, crashing as a result

Error:

E/AndroidRuntime(25794): FATAL EXCEPTION: main
E/AndroidRuntime(25794): Process: com.example.epicare, PID: 25794
E/AndroidRuntime(25794): java.lang.RuntimeException: Unable to get provider io.flutter.plugins.imagepicker.ImagePickerFileProvider: java.lang.ClassNotFoundException: Didn't find class "io.flutter.plugins.imagepicker.ImagePickerFileProvider" on path: DexPathList[[zip file "/data/app/~~ctdFkZiSgYYczoFMEcld0A==/com.example.epicare-FoeWCIGRe8BwvQyyoMdjww==/base.apk"],nativeLibraryDirectories=[/data/app/~~ctdFkZiSgYYczoFMEcld0A==/com.example.epicare-FoeWCIGRe8BwvQyyoMdjww==/lib/x86, /data/app/~~ctdFkZiSgYYczoFMEcld0A==/com.example.epicare-FoeWCIGRe8BwvQyyoMdjww==/base.apk!/lib/x86, /system/lib, /system_ext/lib, /product/lib]]
E/AndroidRuntime(25794):    at android.app.ActivityThread.installProvider(ActivityThread.java:7244)
E/AndroidRuntime(25794):    at android.app.ActivityThread.installContentProviders(ActivityThread.java:6780)
E/AndroidRuntime(25794):    at android.app.ActivityThread.handleBindApplication(ActivityThread.java:6697)
E/AndroidRuntime(25794):    at android.app.ActivityThread.access$1300(ActivityThread.java:237)
E/AndroidRuntime(25794):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1913)
E/AndroidRuntime(25794):    at android.os.Handler.dispatchMessage(Handler.java:106)
E/AndroidRuntime(25794):    at android.os.Looper.loop(Looper.java:223)
E/AndroidRuntime(25794):    at android.app.ActivityThread.main(ActivityThread.java:7656)
E/AndroidRuntime(25794):    at java.lang.reflect.Method.invoke(Native Method)
E/AndroidRuntime(25794):    at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
E/AndroidRuntime(25794):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:947)
E/AndroidRuntime(25794): Caused by: java.lang.ClassNotFoundException: Didn't find class "io.flutter.plugins.imagepicker.ImagePickerFileProvider" on path: DexPathList[[zip file "/data/app/~~ctdFkZiSgYYczoFMEcld0A==/com.example.epicare-FoeWCIGRe8BwvQyyoMdjww==/base.apk"],nativeLibraryDirectories=[/data/app/~~ctdFkZiSgYYczoFMEcld0A==/com.example.epicare-FoeWCIGRe8BwvQyyoMdjww==/lib/x86, /data/app/~~ctdFkZiSgYYczoFMEcld0A==/com.example.epicare-FoeWCIGRe8BwvQyyoMdjww==/base.apk!/lib/x86, /system/lib, /system_ext/lib, /product/lib]]
E/AndroidRuntime(25794):    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:207)
E/AndroidRuntime(25794):    at java.lang.ClassLoader.loadClass(ClassLoader.java:379)
E/AndroidRuntime(25794):    at java.lang.ClassLoader.loadClass(ClassLoader.java:312)
E/AndroidRuntime(25794):    at android.app.AppComponentFactory.instantiateProvider(AppComponentFactory.java:147)
E/AndroidRuntime(25794):    at androidx.core.app.CoreComponentFactory.instantiateProvider(CoreComponentFactory.java:60)
E/AndroidRuntime(25794):    at android.app.ActivityThread.installProvider(ActivityThread.java:7228)
E/AndroidRuntime(25794):    ... 10 more

My code for the app screen is this:

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

class ProfileScreen extends StatefulWidget {
  @override
  _ProfileScreenState createState() => _ProfileScreenState();
}

class _ProfileScreenState extends State<ProfileScreen> {
  PickedFile _imageFile;
  final ImagePicker _picker = ImagePicker();
  @override
  Widget build(BuildContext context) {
    //Size size = MediaQuery.of(context).size;
    return Scaffold(
      backgroundColor: Colors.white,
      appBar: AppBar(
        backgroundColor: const Color(0xffE5E0A1),
        elevation: 0,
        centerTitle: true,
        title: Text(
          "My Profile",
          style: TextStyle(
            fontSize: 15.0,
            color: Colors.black,
            fontFamily: 'Montserrat',
            fontWeight: FontWeight.normal,
          ),
        ),
        leading: IconButton(
          icon: Icon(
            Icons.arrow_back,
            color: Colors.black,
          ),
          onPressed: () {
            Navigator.push(
              context,
              MaterialPageRoute(
                builder: (context) {
                  return Homepage();
                },
              ),
            );
          },
        ),
      ),
      body: SingleChildScrollView(
        child: Column(
          children: <Widget>[
            SizedBox(
              height: 14,
            ),
            Center(
              child: Stack(
                alignment: Alignment.center,
                children: <Widget>[
                  CircleAvatar(
                    radius: 60,
                    backgroundImage: _imageFile == null
                        ? AssetImage("assets/images/avatar.jpg")
                        : FileImage(File(_imageFile.path)),
                  ),
                  Positioned(
                    bottom: 15.0,
                    right: 1.0,
                    child: MaterialButton(
                      onPressed: () {
                        showModalBottomSheet(
                          shape: RoundedRectangleBorder(
                            borderRadius: BorderRadius.only(
                              topRight: Radius.circular(17),
                              topLeft: Radius.circular(17),
                            ),
                          ),
                          context: context,
                          builder: ((builder) => bottomSheet()),
                        );
                      },
                      color: const Color(0xffd4d411),
                      textColor: Colors.white,
                      child: Icon(
                        Icons.add,
                        size: 28,
                      ),
                      padding: EdgeInsets.all(1),
                      shape: CircleBorder(),
                    ),
                  )
                ],
              ),
            )
          ],
        ),
      ),
    );
  }

  Widget bottomSheet() {
    return Container(
      height: 100.0,
      width: MediaQuery.of(context).size.width,
      margin: EdgeInsets.symmetric(horizontal: 20, vertical: 20),
      child: Column(
        children: <Widget>[
          Text(
            "Choose Profile Picture",
            style: TextStyle(
              fontFamily: 'Montserrat',
              fontSize: 18.0,
              fontWeight: FontWeight.w500,
            ),
          ),
          SizedBox(
            height: 20.0,
          ),
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: [
              FlatButton.icon(
                onPressed: () {
                  takePhoto(ImageSource.camera);
                },
                icon: Icon(Icons.camera),
                label: Text(
                  "Camera",
                  style: TextStyle(
                    fontFamily: 'Montserrat',
                    fontSize: 18.0,
                    fontWeight: FontWeight.w400,
                  ),
                ),
              ),
              FlatButton.icon(
                onPressed: () {
                  takePhoto(ImageSource.gallery);
                },
                icon: Icon(Icons.image),
                label: Text(
                  "Gallery",
                  style: TextStyle(
                    fontFamily: 'Montserrat',
                    fontSize: 18.0,
                    fontWeight: FontWeight.w400,
                  ),
                ),
              ),
            ],
          )
        ],
      ),
    );
  }

  void takePhoto(ImageSource source) async {
    final pickedFile = await _picker.getImage(
      source: source,
    );
    setState(() {
      _imageFile = pickedFile;
    });
  }
}

Dependency I have used in pubspec.yml are:

dependencies:
  image_picker: ^0.6.7+4

Kindly help me out as I am new to Flutter Thank you in advance!

0 Answers
Related