Gal?️

用于处理照片应用的易于使用的 Dart3 插件 ios photo amdroid photo

example

✨ 特点

  • 打开画廊
  • 保存视频
  • 保存图片
  • 处理权限
  • 处理错误
  • 大量文档和维基

?开始使用

添加依赖

您可以使用命令将 gal 作为依赖项添加,使用最新的稳定版本

$ flutter pub add gal

iOS

将以下键添加到您的 Info.plist 文件,位于 <project root>/ios/Runner/Info.plist

Android (API <29)

将以下键添加到您的 AndroidManifest 文件,位于 <project root>/android/app/src/main/AndroidManifest.xml

✅用法

从本地保存

//Save Image
await Gal.putImage('$filePath');

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

从互联网下载

$ 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);

处理权限

//Check Permission
await Gal.hasAccess();

//Request Access
await Gal.requestAccess();

?示例

这是一个最简单的示例。可以在 项目维基 中找到最佳实践和更详细的示例,以及 示例文件夹

import 'package:flutter/material.dart';
import 'package:gal/gal.dart';

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

class App extends StatelessWidget {
  const App({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        body: Center(
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              FilledButton.icon(
                onPressed: () async => Gal.open(),
                label: const Text('Open Gallery'),
                icon: const Icon(Icons.open_in_new),
              ),
              FilledButton.icon(
                onPressed: () async => Gal.putVideo('TODO: Change this text to video path'),
                label: const Text('Save Video'),
                icon: const Icon(Icons.video_file),
              ),
              FilledButton.icon(
                onPressed: () async => Gal.putImage('TODO: Change this text to image path'),
                label: const Text('Save Image'),
                icon: const Icon(Icons.image),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

?常见问题

  • 什么是最佳实践?

    请参阅项目维基中的 最佳实践

  • 我有一个问题。

    请先查看 维基。如果未能解决问题。您应该转到 讨论区。一旦您确定没有重复的问题,请通过问答形式提出。

?贡献

欢迎!随时创建 issue 或 PR。我们建议您阅读 这篇非常简短的指南

GitHub

查看 Github