media_saver 1.0.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 72

media_saver #

Pub

Quick and Simple save media file for Android and IOS

Features #

  • Implements native permission (Android)
  • Save image to Pictures for Android and IOS
  • Support save jpg/png/gif image
  • Support set image name, set image dir, set image suffix

Installation #

Add it to your pubspec.yaml file

dependencies:
   media_saver: <PLUGIN_VERSION>

Install it

pub get

Import it

import 'package:media_saver/media_saver.dart';

For iOS you need setting info.plist with

  Privacy - Photo Library Additions Usage Description

Usage #

    var response = await Dio().get(
      'https://flutter.dev/assets/flutter-lockup-c13da9c9303e26b8d5fc208d2a1fa20c1ef47eb021ecadf27046dea04c0cebf6.png',
      options: Options(responseType: ResponseType.bytes),
    );

    String path = await MediaSaver.saveImage(
      Uint8List.fromList(response.data),
      imageType: ImageType.PNG,
      fileName: 'saveFileName',
      directory: 'demo',
    );

License #

MIT @yk3372 @wsh794972562

1.0.0 #

  • android is Ready, IOS is developing

example/lib/main.dart

import 'dart:typed_data';

import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:media_saver/media_saver.dart';

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

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

class _MyAppState extends State<MyApp> {
  String _platformVersion = 'Unknown';
  String state;

  @override
  void initState() {
    super.initState();
  }

  void _saveImage() async {
    setState(() {
      state = 'begin download';
    });
    var response = await Dio().get(
      'https://flutter.dev/assets/flutter-lockup-c13da9c9303e26b8d5fc208d2a1fa20c1ef47eb021ecadf27046dea04c0cebf6.png',
      options: Options(responseType: ResponseType.bytes),
    );
    setState(() {
      state = 'download success, saving...';
    });

    bool path = await MediaSaver.saveImage(
      Uint8List.fromList(response.data),
      imageType: ImageType.JPG,
      fileName: 'saveFileName',
      directory: 'demo',
    );
    setState(() {
      state = 'savePath: $path';
    });
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('media saver'),
        ),
        body: Container(
          child: Column(
            children: <Widget>[
              Text(state ?? 'init'),
              GestureDetector(
                onTap: _saveImage,
                behavior: HitTestBehavior.opaque,
                child: Container(
                  width: 100,
                  height: 100,
                  color: Colors.redAccent,
                  alignment: Alignment.center,
                  child: Text(
                    '保存图片',
                    style: TextStyle(
                      color: Colors.white,
                    ),
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  media_saver: ^1.0.2

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:media_saver/media_saver.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
48
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
72
Learn more about scoring.

We analyzed this package on Jun 3, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.2
  • pana: 0.13.8-dev
  • Flutter: 1.17.1

Maintenance suggestions

The description is too long. (-10 points)

Search engines display only the first part of the description. Try to keep the value of the description field in your package's pubspec.yaml file between 60 and 180 characters.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.1.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.12
meta 1.1.8
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test