Home > Net >  Flutter - app doesn't access the camera after building
Flutter - app doesn't access the camera after building

Time:02-19

I have created a simple note app using Hive, the app works perfectly on the emulator but after building the app with flutter build apk --release and installing it on my android device I face this problem :

  • if I choose an image from the gallery everything works normally ✔️

  • When I try to pick an image from the camera then it doesn't work ✖️

  • After trying to access the camera then also accessing the gallery stop working ✖️.

This is a screenshot from my mobile : screenshot_from_app

this is the code where I'm accessing the camera and gallery :

 //Camera Functions
  //Phot from Camera
  getImageCamera() async {
    final pickedimage =
        await ImagePicker.platform.getImage(source: ImageSource.camera);
    if (pickedimage != null) {
      setState(() {
        _image = File(pickedimage.path);
      });

      Navigator.of(context).pop();
    }
  }
  //Photo From the gallery

  getImageGallery() async {
    final pickedimage =
        await ImagePicker.platform.getImage(source: ImageSource.gallery);
    if (pickedimage != null) {
      setState(() {
        _image = File(pickedimage.path);
      });

      Navigator.of(context).pop();
    }
  }

  //AlertDialog Appear when pressing add phot buttom
  showBottomSheet(context) {
    return showDialog(
      context: context,
      builder: (context) {
        return AlertDialog(
          title: const Text(
            "Choose photo from",
            style: TextStyle(fontWeight: FontWeight.bold),
          ),
          actions: [
            IconButton(
              onPressed: () async {
                await getImageCamera();
              },
              icon: const Icon(Icons.photo_camera),
            ),
            IconButton(
              onPressed: () async {
                await getImageGallery();
              },
              icon: const Icon(Icons.image),
            )
          ],
        );
      },
    );
  }
  //End Camera Function

CodePudding user response:

it seems you didn't add permissions read about this package and

Add this to pubspec.yaml File:

dependencies:
  permission_handler: ^9.1.0

CodePudding user response:

i fixed my problem by adding this permission

<uses-permission android:name="com.google.android.providers.gsf.permission.READ_GSERVICES" />

  • Related