Skip to content

A Flutter app demonstrating the use of the image_picker package to select and capture images.

License

Notifications You must be signed in to change notification settings

mahmoodhamdi/flutter-image-picker-guide

Repository files navigation

Flutter Image Picker Guide ๐Ÿ“ธ

A simple and modularized Flutter app demonstrating how to use the image_picker package to pick images from the gallery or capture images from the camera.

๐ŸŒŸ Features

  • ๐Ÿ“ฑ Pick images from the gallery
  • ๐Ÿ“ท Capture images using the camera
  • ๐Ÿ–ผ๏ธ Display selected or captured images in the app
  • โš™๏ธ Modularized helper class for image picking

๐Ÿš€ Getting Started

Prerequisites

  • Flutter SDK
  • Android Studio / VS Code
  • Basic understanding of Flutter development

๐Ÿ“ฆ Installation

  1. Add the following dependency to your pubspec.yaml
dependencies:
  image_picker: <LATEST VERSION>
  1. Run:
flutter pub get

โš™๏ธ Configuration

๐Ÿค– Configuring Android

  1. Update the minimum Android SDK requirements in android/app/build.gradle
android {
    compileSdkVersion 34

    defaultConfig {
        minSdkVersion 21
        targetSdkVersion 34
    }
}
  1. Add the required permissions in 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"/>

๐Ÿ Configuring iOS

Add the following permissions to ios/Runner/Info.plist

<key>NSPhotoLibraryUsageDescription</key>
<string>We need access to your photo library to select images.</string>
<key>NSCameraUsageDescription</key>
<string>We need access to your camera to capture images.</string>

๐Ÿ’ก Usage

Initialization

  • The ImagePickerHelper class contains two methods to either select an image from the gallery or capture one from the camera.

Picking an Image from the Gallery

File? image = await ImagePickerHelper.pickImage();

Capturing an Image from the Camera

File? image = await ImagePickerHelper.captureImage();

Displaying the Image

image != null ? Image.file(image!) : Icon(Icons.image);

๐Ÿ› ๏ธ Project Structure

lib/
โ”œโ”€โ”€ app.dart                # MyApp widget with MaterialApp configuration
โ”œโ”€โ”€ home_page.dart          # UI for selecting or capturing images
โ”œโ”€โ”€ image_picker_helper.dart # Utility class for image selection and capture
โ””โ”€โ”€ main.dart               # Main entry point of the app

Core Components

  • ImagePickerHelper

    • A utility class that provides methods to pick images from the gallery or capture images using the camera.
  • MyHomePage

    • The main UI of the app that shows a button to either pick or capture an image, and displays the selected image.
  • MyApp

    • Configures the app and sets the home page MyHomePage as the default screen.

๐Ÿ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

๐Ÿค Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

โœจ Acknowledgments

  • Special thanks to the Flutter Image Picker package maintainers

Quote

"ู…ูŽู† ู‚ุงู„: ุณูุจู’ุญุงู†ูŽ ุงู„ู„ู‘ูŽู‡ู ูˆุจูุญูŽู…ู’ุฏูู‡ูุŒ ููŠ ูŠูŽูˆู…ู ู…ูุงุฆูŽุฉูŽ ู…ูŽุฑู‘ูŽุฉูุ› ุญูุทู‘ูŽุชู’ ุฎูŽุทุงูŠุงู‡ู ูˆุฅู†ู’ ูƒุงู†ูŽุชู’ ู…ูุซู’ู„ูŽ ุฒูŽุจูŽุฏู ุงู„ุจูŽุญู’ุฑู."

ุตุญูŠุญ ุงู„ุจุฎุงุฑูŠ