Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Image picker for Flutter not opening gallery in app release

Tags:

flutter

The gallery and the camera are correctly opened in debug (both with emulator and real device), the package asks for permissions (i set them up in the android manifest) and after accepting them the gallery opens. without warnings/errors. When I release the app with flutter build apk --release and test it on my phone (xiaomi redmi note 7) the image picker doesn't open the gallery. The button doesn't do anything and the app doesn't crash. I didn't try flutter build apk --debug but I bet it would work. As I said, I have the last version of image_picker, api 29, permissions and tried rebuilding with flutter clean. The package is basically working, but not in release mode. Any advice?

Image picker class

import 'dart:io';

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

class ImageUpload extends StatefulWidget {
  @override
  _ImageUploadState createState() => _ImageUploadState();
}

class _ImageUploadState extends State<ImageUpload> {
  File _image;
  Future getImage() async {
    var image = await ImagePicker.pickImage(source: ImageSource.gallery);

    setState(() {
      _image = image;
    });
  }

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

Android Manifest

  <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" />
  <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />
  <uses-permission android:name="android.permission.INTERNET" />
  <uses-permission android:name="android.permission.CAMERA" />
  <uses-permission android:name="android.permission.FLASHLIGHT" />
like image 594
Tenebra23 Avatar asked Sep 21 '25 06:09

Tenebra23


1 Answers

The solution in my case was to run flutter run --release (with the device connected) and the image picker worked fine. The app is automatically installed on your device but you can find the working apk usually there build\app\outputs\apk\release\app-release.apk (the console will print the path).

Thanks to the comment above for the hint.

like image 89
Tenebra23 Avatar answered Sep 23 '25 07:09

Tenebra23