Coder Social home page Coder Social logo

dola99 / gal Goto Github PK

View Code? Open in Web Editor NEW

This project forked from natsuk4ze/gal

0.0 0.0 0.0 65.67 MB

How to Save Image or Video to Photo Gallery in Flutter

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

License: BSD 3-Clause "New" or "Revised" License

Ruby 2.04% C++ 16.22% C 1.12% Java 24.22% Dart 35.48% Swift 16.03% CMake 4.89%

gal's Introduction

Logo

Gal

Dart3 plugin for saving image or video to photos gallery ios photos google photos microsoft photos

pub.dev »

Since pub points Maintainability CodeFactor Codacy Badge CI pub package

Please LIKE👍 and STAR⭐️ to support our volunteer efforts.

Support means that all functions have been tested manually or automatically whenever possible.

Android iOS macOS Windows Linux
Support SDK 21+ 11+ 11+ 10+ See: gal_linux
iOS Android
Example ios android

✨ Features

  • Open gallery
  • Save video
  • Save image
  • Save to album
  • Save with metadata
  • Handle permission
  • Handle errors
  • Lots of docs and wiki

🚀 Get started

Add dependency

You can use the command to add gal as a dependency with the latest stable version:

$ flutter pub add gal

iOS

Add the following keys to the ios/Runner/Info.plist:

  • <key>NSPhotoLibraryAddUsageDescription</key> Required
  • <key>NSPhotoLibraryUsageDescription</key> Required for ios < 14 or saving to album

You can copy from Info.plist in example.

Android

Add the following keys to the android/app/src/main/AndroidManifest.xml:

  • <uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" android:maxSdkVersion="29" /> Required for API <= 29
  • android:requestLegacyExternalStorage="true" Required for saving to the album in API 29

You can copy from AndroidManifest.xml from example.

🔴 Warning: Android emulators with API < 29 require SD card setup. Real devices don't.

macOS

Add the following keys to the macos/Runner/Info.plist:

  • <key>NSPhotoLibraryAddUsageDescription</key> Required
  • <key>NSPhotoLibraryUsageDescription</key> Required for saving to album

You can copy from Info.plist in example.

🔴 Warning: Flutter currently has a fatal problem for loading info.plist, and permissions are always denied or app crashing in some code editors.

Windows

Update Visual Studio to the latest version for using C++ 20.

💡 If you can't compile

Try downloading a latest Windows SDK:

  1. Open Visual Studio Installer
  2. Select Modify
  3. Select Windows SDK

Linux

Currently does not officially support Linux, but it can be added through a non-endorsed federated plugin. See: gal_linux

✅ Usage

Save from local

// Save Image (Supports two ways)
await Gal.putImage('$filePath');
await Gal.putImageBytes('$uint8List');

// Save Video
await Gal.putVideo('$filePath');

// Save to album
await Gal.putImage('$filePath', album: '$album')
...

Download from the Internet

$ flutter pub add dio
// Download Image
final imagePath = '${Directory.systemTemp.path}/image.jpg';
await Dio().download('$url',imagePath);
await Gal.putImage(imagePath);

// Download Video
final videoPath = '${Directory.systemTemp.path}/video.mp4';
await Dio().download('$url',videoPath);
await Gal.putVideo(videoPath);

Save from Camera

$ flutter pub add image_picker
// Shot and Save
final image = await ImagePicker.pickImage(source: ImageSource.camera);
await Gal.putImage(image.path);
$ flutter pub add camera
// Record and Save
...
final video = await controller.stopVideoRecording();
await Gal.putVideo(video.path);

Handle Permission

// Check for access premission
final hasAccess = await Gal.hasAccess();

// Request access premission
await Gal.requestAccess();

// ... for saving to album
final hasAccess = await Gal.hasAccess(toAlbum: true);
await Gal.requestAccess(toAlbum: true);

Handle Errors

// Save Image with try-catch
try {
  await Gal.putImage('$filePath');
} on GalException catch (e) {
  log(e.type.message);
}

// Exception Type
enum GalExceptionType {
  accessDenied,
  notEnoughSpace,
  notSupportedFormat,
  unexpected;

  String get message => switch (this) {
        accessDenied => 'Permission to access the gallery is denied.',
        notEnoughSpace => 'Not enough space for storage.',
        notSupportedFormat => 'Unsupported file formats.',
        unexpected => 'An unexpected error has occurred.',
      };
}

📝 Ducuments

If you write an article about Gal, let us know in discussion and we will post the URL of the article in the wiki or readme 🤝

💚 Trusted by huge projects

Although Gal has only been released for a short time, it is already trusted by huge projects.

and more...

gal's People

Contributors

dependabot[bot] avatar echoellet avatar molihuan avatar natsuk4ze avatar noob8boi avatar zazo032 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.