Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Couldn't find constructor 'ImagePickerOptions'. ImagePickerOptions options = const ImagePickerOptions()

Tags:

flutter

dart

I recentely added the plugin image_picker: ^0.8.5+3 from flutter pub dev. I integrated it to my flutter codes. here is the code.

This code is supposed to capture image then the image will be used at the same page in the imgRabbitdflt1,

import 'dart:io';
import 'controller/scan_controller.dart';
import 'package:flutter/material.dart';
import 'package:grabbitapp/core/app_export.dart';
import 'package:image_picker/image_picker.dart';

class ScanScreen extends GetWidget<ScanController> {
  File? image;

  Future pickimage() async {

    final image = await ImagePicker().pickImage(source: ImageSource.camera);
    if (image == null) return;

    final imageTemporary = File(image.path);
    setState (() => this.image = imageTemporary);
    }
  
  @override
  Widget build(BuildContext context) {
    return SafeArea(
        child: Scaffold(
            backgroundColor: ColorConstant.whiteA700,
            body: Container(
                width: size.width,
                child: SingleChildScrollView(
                    child: Container(
                        decoration:
                            BoxDecoration(color: ColorConstant.whiteA700),
                        child: Column(
                            mainAxisSize: MainAxisSize.min,
                            crossAxisAlignment: CrossAxisAlignment.center,
                            mainAxisAlignment: MainAxisAlignment.end,
                            children: [
                              Container(
                                  width: double.infinity,
                                  margin: EdgeInsets.only(
                                      left: getHorizontalSize(10.00),
                                      top: getVerticalSize(135.00),
                                      right: getHorizontalSize(10.00)),
                                  decoration: BoxDecoration(
                                      color: ColorConstant.bluegray100,
                                      borderRadius: BorderRadius.circular(
                                          getHorizontalSize(15.00))),
                                  child: Column(
                                      mainAxisSize: MainAxisSize.min,
                                      crossAxisAlignment:
                                          CrossAxisAlignment.center,
                                      mainAxisAlignment: MainAxisAlignment.end,
                                      children: [
                                        Padding(
                                            padding: EdgeInsets.only(
                                                left: getHorizontalSize(5.00),
                                                top: getVerticalSize(50.00)),
                                            child:  image != null ? Image.file(image!) : Image.asset(
                                                ImageConstant.imgRabbitdflt1,
                                                height: getVerticalSize(236.00),
                                                width:
                                                    getHorizontalSize(320.00),
                                                fit: BoxFit.fill)),
                                        GestureDetector(
                                            onTap: () {
                                              onTapImgCameraicon();
                                            },
                                            child: Padding(
                                                padding: EdgeInsets.only(
                                                    left: getHorizontalSize(
                                                        10.00),
                                                    top: getVerticalSize(43.00),
                                                    right: getHorizontalSize(
                                                        10.00),
                                                    bottom:
                                                        getVerticalSize(27.29)),
                                                child: Image.asset(
                                                    ImageConstant.imgCameraicon,
                                                    height:
                                                        getVerticalSize(77.71),
                                                    width: getHorizontalSize(
                                                        82.93),
                                                    fit: BoxFit.fill)))
                                      ])),
                              Padding(
                                  padding: EdgeInsets.only(
                                      left: getHorizontalSize(10.00),
                                      top: getVerticalSize(135.10),
                                      right: getHorizontalSize(10.00),
                                      bottom: getVerticalSize(20.00)),
                                  child: GestureDetector(
                                      onTap: () {
                                        onTapBtnNext();
                                      },
                                      child: Container(
                                          alignment: Alignment.center,
                                          height: getVerticalSize(40.60),
                                          width: getHorizontalSize(267.48),
                                          decoration: AppDecoration
                                              .textstylemontserratromanmedium20,
                                          child: Text("lbl_next".tr,
                                              textAlign: TextAlign.center,
                                              style: AppStyle
                                                  .textstylemontserratromanmedium20
                                                  .copyWith(
                                                      fontSize: getFontSize(20),
                                                      letterSpacing: 1.20)))))
                            ]))))));
  }

  onTapImgCameraicon() async {
    await PermissionManager.askForPermission(Permission.camera);
    await PermissionManager.askForPermission(Permission.storage);
    List<String?>? imageList = [];
//TODO: Permission - use imageList for using selected images
    await FileManager().showModelSheetForImage(getImages: (value) async {
      imageList = value;
    });
  }

  onTapBtnNext() {
    Get.toNamed(AppRoutes.rabbitGeneratedInfoScreen);
  }
  
  void setState(File Function() param0) {}
}

But when I tried to run it, I got these errors,

/E:/src/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker_android-0.8.5+1/lib/image_picker_android.dart:174:5: Error: Type 'ImagePickerOptions' not found.
    ImagePickerOptions options = const ImagePickerOptions(),
    ^^^^^^^^^^^^^^^^^^
/E:/src/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker_android-0.8.5+1/lib/image_picker_android.dart:174:40: Error: Couldn't find constructor 'ImagePickerOptions'.
    ImagePickerOptions options = const ImagePickerOptions(),
                                       ^^^^^^^^^^^^^^^^^^
/E:/src/flutter/.pub-cache/hosted/pub.dartlang.org/image_picker_android-0.8.5+1/lib/image_picker_android.dart:174:5: Error: 'ImagePickerOptions' isn't a type.
    ImagePickerOptions options = const ImagePickerOptions(),
    ^^^^^^^^^^^^^^^^^^

DId I miss to import something or what are nmissing that led to these errors?

like image 548
John Michael Tan Avatar asked Feb 19 '26 19:02

John Michael Tan


2 Answers

I deleted the pubspec.lock, and ran the command flutter pub get.

like image 77
george mathu Avatar answered Feb 23 '26 10:02

george mathu


please clean your project and after run flutter pub get it will work and if still it is not working try to clear cache of your project it will work.

like image 37
Sumita Naiya Avatar answered Feb 23 '26 12:02

Sumita Naiya



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!