r_album 0.1.0

  • Readme
  • Changelog
  • Example
  • Installing
  • 75

r_album #

pub package

中文

A Flutter Plugin about image or video file save in album ,support Android and IOS.

How to Use #

  • 1.add this in pubspec.yaml.
dependencies:
  r_album: lastVersion

  • 2.import it
import 'package:r_album/r_album.dart';
  • 3.create a new album.
await RAlbum.createAlbum("your album name");
  • 4.save image or video file in album, use it.
await RAlbum.saveAlbum("your album name",["file1","file2",...]);

0.1.0 #

  • init project.

example/lib/main.dart

import 'dart:io';

import 'package:flutter/material.dart';
import 'package:image_picker/image_picker.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:r_album/r_album.dart';
import 'package:r_album_example/video_widget.dart';

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

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

class _MyAppState extends State<MyApp> {
  File _file;
  bool _isSaving;

  bool isClickVideo;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Plugin example app'),
        ),
        body: _isSaving == true
            ? Center(child: CircularProgressIndicator())
            : ListView(
                children: <Widget>[
                  _buildPickedImage(),
                  _buildImagePickerButton(),
                  _buildVideoPickerButton(),
                  _buildSaveToAlbumButton(),
                  _buildCreateAlbumButton(),
                ],
              ),
      ),
    );
  }

  Widget _buildPickedImage() {
    return Container(
      margin: EdgeInsets.all(16),
      height: 300.0,
      child: isClickVideo != null
          ? isClickVideo
              ? VideoWidget(
                  file: _file,
                )
              : Image.file(
                  _file,
                  fit: BoxFit.fill,
                )
          : Center(
              child: Container(
                child: Text("No selected image or video"),
              ),
            ),
      decoration: isClickVideo != null
          ? null
          : BoxDecoration(border: Border.all(width: 1)),
    );
  }

  Widget _buildImagePickerButton() {
    return Container(
      child: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          IconButton(
            tooltip: 'select image from camera',
            icon: Icon(Icons.camera_alt),
            onPressed: () async {
              var image =
                  await ImagePicker.pickImage(source: ImageSource.camera);
              if (image != null) {
                isClickVideo = false;
                setState(() {
                  _file = image;
                });
              }
            },
          ),
          IconButton(
            tooltip: 'select image from gallery',
            icon: Icon(Icons.folder),
            onPressed: () async {
              var image =
                  await ImagePicker.pickImage(source: ImageSource.gallery);
              if (image != null) {
                isClickVideo = false;
                setState(() {
                  _file = image;
                });
              }
            },
          ),
        ],
      ),
    );
  }

  Widget _buildVideoPickerButton() {
    return Container(
      child: Row(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          IconButton(
            tooltip: 'select video from camera',
            icon: Icon(Icons.videocam),
            onPressed: () async {
              var video =
                  await ImagePicker.pickVideo(source: ImageSource.camera);
              if (video != null) {
                isClickVideo = true;
                setState(() {
                  _file = video;
                });
              }
            },
          ),
          IconButton(
            tooltip: 'select video from gallery',
            icon: Icon(Icons.folder),
            onPressed: () async {
              var video =
                  await ImagePicker.pickVideo(source: ImageSource.gallery);
              if (video != null) {
                isClickVideo = true;
                setState(() {
                  _file = video;
                });
              }
            },
          ),
        ],
      ),
    );
  }

  Widget _buildSaveToAlbumButton() {
    return Container(
      padding: const EdgeInsets.symmetric(horizontal: 16.0),
      child: RaisedButton(
        color: Colors.blue,
        textColor: Colors.white,
        child: Text("Save to album"),
        onPressed: () async {
          setState(() {
            _isSaving = true;
          });
          if (_file != null) {
            if (await canReadStorage()) {
              await RAlbum.saveAlbum(
                "test_album_saver2",
                [_file.path],
              );
              setState(() {
                _isSaving = false;
              });
            }
          } else {
            setState(() {
              _isSaving = false;
            });
          }
        },
      ),
    );
  }

  Future<bool> canReadStorage() async {
    if (Platform.isIOS) return true;
    var status = await PermissionHandler()
        .checkPermissionStatus(PermissionGroup.storage);
    if (status != PermissionStatus.granted) {
      var future = await PermissionHandler()
          .requestPermissions([PermissionGroup.storage]);
      for (final item in future.entries) {
        if (item.value != PermissionStatus.granted) {
          return false;
        }
      }
    } else {
      return true;
    }
    return true;
  }

  Widget _buildCreateAlbumButton() {
    return Container(
      padding: const EdgeInsets.symmetric(horizontal: 16.0),
      child: RaisedButton(
        color: Colors.blue,
        textColor: Colors.white,
        child: Text("Create a album named MyTestAlbum"),
        onPressed: () async {
          if (await canReadStorage()) {
            setState(() {
              _isSaving = true;
            });
            await RAlbum.createAlbum("MyTestAlbum");
            setState(() {
              _isSaving = false;
            });
          }
        },
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  r_album: ^0.1.0

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:r_album/r_album.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
50
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
75
Learn more about scoring.

We analyzed this package on Jun 4, 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

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