๐Ÿ“ธ camerapack

camerapack is a Flutter plugin that opens a native camera screen (iOS and Android), captures a photo using the front or back camera, and returns the image file path to Flutter. It also supports picking an image from the gallery.


Camera UI


๐Ÿš€ Features

  • ๐Ÿ“ท Open native camera screen (Android & iOS)
  • ๐Ÿ”„ Flip between front and back cameras
  • ๐Ÿ” Handle device orientation changes
  • ๐Ÿ“ Capture and return image file path
  • ๐Ÿ–ผ Pick image from gallery
  • ๐Ÿ”Œ Communication via platform channels

๐Ÿ“ฑ Platform Support

Platform Support
Android โœ…
iOS โœ…

๐Ÿ”ง Installation

Add the plugin to your pubspec.yaml:

dependencies:
  camerapack: ^0.0.3  # Replace with the latest version

Then run:

flutter pub get

๐Ÿ›  Usage

Import the package:

import 'package:camerapack/camerapack.dart';

๐Ÿ“ท Capture an Image

final camerapack = Camerapack();

String? imagePath = await camerapack.captureImage();
if (imagePath != null) {
  // Use the image path (e.g., display or upload)
}
String? imagePath = await camerapack.pickFromGallery();
if (imagePath != null) {
  // Use the image path
}

๐Ÿงช Full Flutter Example

import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:camerapack/camerapack.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String? imagePath;
  final _camerapack = Camerapack();

  Future<void> _capturePhoto() async {
    try {
      final path = await _camerapack.captureImage(isfront: true);
      if (mounted && path != null) {
        setState(() {
          imagePath = path;
        });
      }
    } on PlatformException catch (e) {
      debugPrint('Failed to capture image: $e');
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        body: Center(
          child: Padding(
            padding: const EdgeInsets.all(24.0),
            child: Column(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                TextButton(
                  onPressed: _capturePhoto,
                  child: const Text('Click Photo'),
                ),
                const SizedBox(height: 20),
                if (imagePath != null)
                  Image.file(
                    File(imagePath!),
                    width: 200,
                    height: 200,
                    fit: BoxFit.cover,
                  )
              ],
            ),
          ),
        ),
      ),
    );
  }
}

This will:

  • Launch the native camera screen (front camera)
  • Capture a photo
  • Return the file path
  • Display the captured image in the app

๐Ÿ“‚ iOS Configuration

To access the camera and photo library on iOS, add the following permissions to your ios/Runner/Info.plist:

<key>NSCameraUsageDescription</key>
<string>We need camera access to take photos</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>We need access to your photo library</string>

๐Ÿ’ก These keys provide user-facing explanations for why your app needs access. Make sure the descriptions match your appโ€™s functionality.


๐Ÿ“‚ Android Configuration

Make sure you have these permissions in your android/app/src/main/AndroidManifest.xml:

<uses-permission android:name="android.permission.CAMERA"/>
<uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>

Also, ensure your minSdkVersion is at least 21 in android/app/build.gradle:

defaultConfig {
    minSdkVersion 21
}

๐Ÿง‘โ€๐Ÿ’ป Contributing

Pull requests are welcome.
For major changes, please open an issue first to discuss what youโ€™d like to change.


๐Ÿ“„ License

This plugin is licensed under the Apache 2.0 License.