搜尋分類、套件與程式碼儲存庫

套件詳情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 項

原始碼儲存庫

使用此套件的專案