media_gal 0.0.8 copy "media_gal: ^0.0.8" to clipboard
media_gal: ^0.0.8 copied to clipboard

Fetch Image Media from Mobile App Gallery Android/IOS, comprises of png, jpg. This plugin comes with Sdk 32 and above support

Certainly! Below is a README.md template that you can customize for your Media Gallery Flutter package. This template includes sections like introduction, features, setup, usage, and contributions.


Media Gallery #

A Flutter package that allows you to easily access and display images from the device’s media gallery. It handles permissions, media access, and displaying the list of images in a user-friendly way.

Features #

  • Access Photos: Retrieve a list of images from the device's media gallery.
  • Permission Handling: Automatically requests permission to access media files (with appropriate handling for Android).
  • Toast Notifications: Provides user feedback via toast notifications when necessary actions are performed (like permissions).
  • Cross-platform: Works on both Android and iOS (based on your implementation and support).

Installation #

To use the Media Gallery package in your Flutter project, follow these steps:

  1. Add the following dependency to your pubspec.yaml file:

    dependencies:
      media_gal: ^1.0.0  # Replace with the actual version
    
  2. Run the following command to fetch the package:

    flutter pub get
    

Permissions #

To access the media files on Android and iOS, the package requires certain permissions.

Android #

  1. Add the following permissions to your AndroidManifest.xml (located in android/app/src/main/AndroidManifest.xml):

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

    For devices running Android 6.0 (API level 23) and above, you also need to request permissions at runtime. This is handled by the package automatically.

iOS #

For iOS, add the following keys to your Info.plist (located in ios/Runner/Info.plist):

<key>NSPhotoLibraryUsageDescription</key>
<string>We need access to your photos to display your media gallery</string>

Usage #

After installing the package and configuring the permissions, you can access the gallery and display images in your Flutter application.

Example: #

Here’s a simple example of how to use the Media Gallery package to access and display images:

import 'package:flutter/material.dart';
import 'package:media_gal/media_gal.dart';  // Replace with actual import

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Media Gallery Example',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MediaGalScreen(),
    );
  }
}

class MediaGalScreen extends StatefulWidget {
  @override
  _MediaGalState createState() => _MediaGalScreenState();
}

class _MediaGalScreenState extends State<MediaGalScreen> {
  List<MediaModel> _mediaFiles = List.empty(growable: true);

  @override
  void initState() {
    super.initState();
    _loadImages();
  }

  Future<void> _loadImages() async {
    try {
      // Assuming getImagesFromGallery is a method in the package
      List<Object?>? images = await MediaGal.loadMediaList();
      for (var mediaPathNam in path1??[]) {
        if (mediaPathNam is String?) {
          if (mediaPathNam != null && mediaPathNam.isNotEmpty) {
            this._mediaFiles.add(MediaModel.filePath(mediaPathNam));
          }
        }
      }
      setState(() {
        _imagePaths = images;
      });
    } catch (e) {
      print("Error fetching images: $e");
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text("Media Gallery")),
      body: _imagePaths.isEmpty
          ? Center(child: CircularProgressIndicator())
          : Expanded(
        child: _mediaList(_mediaFiles),
      ),
    );
  }

  Widget _mediaList(List<MediaModel> mediaList) {
    return ListView.builder(
      controller: _scrollController,
      scrollDirection: Axis.horizontal,
      itemCount: mediaList.length, // Number of items in the list
      itemBuilder: (context, index) {
        return _imagePreview(mediaList[index]);
      },
    );
  }



  Widget _mediaViewCard(MediaModel media) {
    return Padding(
      padding: const EdgeInsets.symmetric(horizontal: 2.0, vertical: 2),
      child: ConstrainedBox(constraints: BoxConstraints(
        maxWidth: MediaQuery.of(context).size.width,),
        child: Container(
          child: Card(
            elevation: 4.0,
            child: media.image(),
          ),
        ),
      ),
    );
  }
}

Key Features: #

  • Toast Notifications: You can show a toast message when the app successfully fetches media or when there is an error.

    MediaGal.showToast(msg: "Permissions granted!");  // Example usage
    
  • Permission Handling: If the user denies access to the gallery, your app will prompt them again to allow permissions, or show a suitable message using Toast.

Example of Using Toast: #

import 'package:media_gal/media_gal.dart';

// Show a toast message
MediaGal.showToast(msg: "This is a simple toast message");

// Fetch Media List
List<Object?>? path1 = await MediaGal.loadMediaList();

Contributions #

Contributions are welcome! If you'd like to contribute, please fork the repository, create a new branch, and submit a pull request with your changes.

How to contribute: #

  • Fork the repository.
  • Create a new branch (git checkout -b feature/your-feature-name).
  • Commit your changes (git commit -am 'Add new feature').
  • Push to the branch (git push origin feature/your-feature-name).
  • Create a new Pull Request.

License #

This package is licensed under the Apache License.


Media Gal #

DEPRECATION NOTICE:

Version 0.0.3 of this package is deprecated. Please upgrade to version 0.0.4 or later for continued support and bug fixes.

Final Notes: #

  • The exact method to fetch images from the gallery may vary depending on the package you're using or your custom implementation. Be sure to replace placeholder methods like MediaGallery.getImagesFromGallery() with the actual method from your package.
  • You can further expand on this by including examples of different ways to use the package (e.g., with custom sorting, image selection, etc.).

Let me know if you'd like any adjustments or additional details!

0
likes
120
points
45
downloads

Publisher

unverified uploader

Weekly Downloads

Fetch Image Media from Mobile App Gallery Android/IOS, comprises of png, jpg. This plugin comes with Sdk 32 and above support

Repository (GitHub)

Documentation

API reference

License

unknown (license)

Dependencies

device_info_plus, flutter, flutter_web_plugins, path_provider, permission_handler, plugin_platform_interface, web

More

Packages that depend on media_gal