GithubHelp home page GithubHelp logo

berkaymazman / add_to_gallery Goto Github PK

View Code? Open in Web Editor NEW

This project forked from flowmobile/add_to_gallery

0.0 0.0 0.0 5.03 MB

Fluter Plugin. Saves a copy of images and videos to the Android Gallery and iOS Photos

Home Page: https://pub.dev/packages/add_to_gallery

License: Apache License 2.0

Ruby 4.91% Objective-C 2.99% Kotlin 37.73% Dart 28.02% Swift 26.36%

add_to_gallery's Introduction

Add to Gallery

Adds images and videos to the Android Gallery and iOS Photos

View example app

Installation

Add add_to_gallery as a dependency in your pubspec.yaml file.

Permissions

You need the following permissions in your app:

  • iOS
    • NSPhotoLibraryUsageDescription
    • This allows the plugin to use the PHPhotoLibrary APIs to add assets to the user's photo library.
  • Android

This plugin does not manage permissions for you. By excluding permissions from our plugin we have created a simple, reliable plugin.

We recommend using permission_handler to handle permissions.

Usage

There's only one method. It copies the source file to the gallery and returns the new file.

File file = await AddToGallery.addToGallery(
  originalFile: File('/Some/Media/Path.jpg'),
  albumName: 'My Awesome App',
  deleteOriginalFile: false,
);
print("Savd to gallery with Path: ${file.path}");

Using permission_handler, this may look like:

try {
  // iOS
  if (!await Permission.photos.request().isGranted) {
    throw ('Permission Required');
  }
  // Android (10 and below)
  if (!await Permission.storage.request().isGranted) {
    throw ('Permission Required');
  }
  // Add to the gallery
  File file = await AddToGallery.addToGallery(
    originalFile: File('/Some/Media/Path.jpg'),
    albumName: 'My Awesome App',
    deleteOriginalFile: true,
  );
  print("Savd to gallery with Path: ${file.path}");
} catch(e) {
  print("Error: $e");
}

Example app

The example app shows a few more edge-cases in action.

  • Uses permission_handler to request permissions
  • Uses image_picker to take photos with the camera
  • Copies assets to the gallery
  • Uses shared_preferences to save and read the file path locally
    • This shows that the assets are still accessible between reboots

Credits & Comparison

Add to Gallery is based on gallery_saver with some notable differences. Enough to warrant a new package rather than a pull-request. Generally speaking, I've simplified the API and unified the behaviour on iOS and Android. It also supports scoped storage on Android (which will be enforced with Android 11)

Big thanks to the Tecocraft LTD team for Android functionality on Android 10 and 11.

Feature gallery_saver
original package
add_to_gallery
this package
General Behaviour Android
  • ๐Ÿ”ฅ Source file is copied to the gallery
  • ๐Ÿ”ฅ The copy is not a tmp file
  • ๐Ÿ‘Ž The file path is not returned
  • ๐Ÿ‘Ž No way to find the new file path
iOS
  • ๐Ÿ”ฅ Source file is linked to the gallery
  • ๐Ÿ‘Ž If the source file is in a tmp directory it may be garbage collected
  • ๐Ÿ‘Ž The file path is not returned
  • ๐Ÿ”ฅ The original file path is correct
Android and iOS
  • ๐Ÿ”ฅ Source file is copied to the getApplicationDocumentsDirectory for persistence
  • ๐Ÿ”ฅ Your app has permission to access the file
  • ๐Ÿ”ฅ The new file path is returned
  • Automatically deletes sourceFile - defaults to false
Return Value Returns bool for the success of the operation Returns a File pointing to the new file in the gallery
Remote Files Automatically downloads files that start with http Does not download files that start with http
Album Name Optional with default values Is required
Image Manipulation Android
  • Rotates images according to EXIF data
  • Creates Thumbnails
iOS
  • Does not manipulate images
Does not manipulate images
Permissions Handled within the plugin. The first-call fails silently due to permissions race-condition Not handled within the plugin

An Important Note about Google photos

Google Photos has a built-in feature to remove exact duplicates. It can be confusing to see your media disappearing like this. I considered addressing this behaviour in the plugin, but decided against it. I expect plugin users to be creating unique images with the camera or other methods.

add_to_gallery's People

Contributors

jelenalecic avatar oodavid avatar berkaymazman avatar lecicdjuro avatar ailic88 avatar ened avatar jonasjuss avatar saad29 avatar thomasstoeckert avatar jochendev avatar sebasbad avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.