搜索分类、插件与代码仓

插件详情v2.3.2

gallery_saver

将网络或临时文件中的图片和视频保存到外部存储。图片和视频在 Android 相册和 iOS 相册中均可见。

AndroidiOS
近 30 天下载
3720
喜欢数
489
Pub 分数
130

安装插件

flutter pub add gallery_saver

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

Gallery Saver 是一个 Flutter 包,可将网络 URL 或临时文件中的图像和视频保存到设备的外部存储中。保存的媒体在 Android 上会显示在原生相册中,在 iOS 上则显示在照片应用中。它简化了本地持久化多媒体内容的过程,确保与系统级相册库兼容。非常适合需要让用户直接将共享或下载的内容保存到设备媒体集合的应用。

适合场景

  • 从URL保存下载的图片
  • 保留用户生成的媒体
  • 将内容分享到设备图库
  • 与图像/视频查看器集成
  • 启用离线访问媒体
  • 支持社交媒体分享

主要特点

  • 保存图片和视频
  • 适用于 Android 和 iOS
  • 在原生相册/照片中可见
  • 支持网络和临时文件源
  • 用于保存媒体的简单 API
  • 保持媒体元数据

适合对象

  • 媒体共享应用
  • 照片查看器应用程序
  • 内容下载器
  • 社交媒体集成
  • 需要离线媒体访问的应用
  • 用户生成内容平台

使用建议

  • 需要在 Android 上具有适当的权限
  • 可能需要运行时权限请求
  • 文件大小限制取决于设备存储
  • iOS 要求在 Info.plist 中提供适当的隐私描述
  • 不适用于大规模媒体处理
  • 对专辑组织的控制有限

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Gallery Saver for Flutter

Saves images and videos from network or temporary file to external storage. Both images and videos will be visible in Android Gallery and iOS Photos.

NOTE: If you want to save network image or video link, it has to contain 'http/https' prefix.

Installation

First, add gallery_saver as a dependency in your pubspec.yaml file.

iOS

Add the following keys to your Info.plist file, located in <project root>/ios/Runner/Info.plist:

  • NSPhotoLibraryUsageDescription - describe why your app needs permission for the photo library. This is called Privacy - Photo Library Usage Description in the visual editor.
Android
  • android.permission.WRITE_EXTERNAL_STORAGE - Permission for usage of external storage
Example
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:gallery_saver/gallery_saver.dart';
import 'package:image_picker/image_picker.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String firstButtonText = 'Take photo';
  String secondButtonText = 'Record video';
  double textSize = 20;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        home: Scaffold(
      body: Container(
        color: Colors.white,
        child: Column(
          children: <Widget>[
            Flexible(
              flex: 1,
              child: Container(
                child: SizedBox.expand(
                  child: RaisedButton(
                    color: Colors.blue,
                    onPressed: _takePhoto,
                    child: Text(firstButtonText,
                        style:
                            TextStyle(fontSize: textSize, color: Colors.white)),
                  ),
                ),
              ),
            ),
            Flexible(
              child: Container(
                  child: SizedBox.expand(
                child: RaisedButton(
                  color: Colors.white,
                  onPressed: _recordVideo,
                  child: Text(secondButtonText,
                      style: TextStyle(
                          fontSize: textSize, color: Colors.blueGrey)),
                ),
              )),
              flex: 1,
            )
          ],
        ),
      ),
    ));
  }

  void _takePhoto() async {
    ImagePicker.pickImage(source: ImageSource.camera)
        .then((File recordedImage) {
      if (recordedImage != null && recordedImage.path != null) {
        setState(() {
          firstButtonText = 'saving in progress...';
        });
        GallerySaver.saveImage(recordedImage.path).then((String path) {
          setState(() {
            firstButtonText = 'image saved!';
          });
        });
      }
    });
  }

  void _recordVideo() async {
    ImagePicker.pickVideo(source: ImageSource.camera)
        .then((File recordedVideo) {
      if (recordedVideo != null && recordedVideo.path != null) {
        setState(() {
          secondButtonText = 'saving in progress...';
        });
        GallerySaver.saveVideo(recordedVideo.path).then((String path) {
          setState(() {
            secondButtonText = 'video saved!';
          });
        });
      }
    });
  }
  void _saveNetworkVideo() async {
    String path =
        'https://sample-videos.com/video123/mp4/720/big_buck_bunny_720p_1mb.mp4';
    GallerySaver.saveVideo(path).then((bool success) {
      setState(() {
        print('Video is saved');
      });
    });
  }

  void _saveNetworkImage() async {
    String path =
        'https://image.shutterstock.com/image-photo/montreal-canada-july-11-2019-600w-1450023539.jpg';
    GallerySaver.saveImage(path).then((bool success) {
      setState(() {
        print('Image is saved');
      });
    });
  }
}

所属分类

依赖

依赖清单 3 项

源码仓库

使用此插件的项目