image_pickers 1.0.7+3

  • Readme
  • Changelog
  • Example
  • Installing
  • 89

image_pickers #

image_pickers支持本地图片多选,本地视频多选,支持将网络图片保存到相册,支持截图保存到相册,支持将网络视频保存到相册,支持预览视频和预览图片功能,支持主题颜色设置

image pickers support multi-selection of local pictures, multi-selection of local videos, support for saving network pictures to albums, support for saving screenshots to albums, support for saving network videos to albums, support for preview videos and preview images, and support for theme color settings

Supported Platforms

  • Android
  • iOS

注意 #

从1.0.6+2开始 CorpConfig 类 改为 CropConfig 类,参数中的 corpConfig 改为 cropConfig. From 1.0.6 + 2, the CorpConfig class is changed to CropConfig class, and the corpConfig in the parameters is changed to cropConfig.

How to Use #

# add this line to your dependencies
image_pickers: ^1.0.7+3
import 'package:image_pickers/image_pickers.dart';
import 'package:image_pickers/CropConfig.dart';
import 'package:image_pickers/Media.dart';
import 'package:image_pickers/UIConfig.dart';


///选择多张图片 Select multiple images
Future<void> selectImages() async {
    List<Media> _listImagePaths = await ImagePickers.pickerPaths(
              galleryMode: GalleryMode.image,
              selectCount: 2,
              showCamera: true,
              compressSize: 500,
              uiConfig: UIConfig(uiThemeColor: Color(0xffff0f50)),
              cropConfig: CropConfig(enableCrop: true, width: 2, height: 1));
  }

/// 或者 or
ImagePickers.pickerPaths().then((List medias){
      /// medias 照片路径信息 Photo path information
    });

///选择多个视频 Select multiple videos
Future<void> selectVideos() async {
   List<Media> _listVideoPaths = await ImagePickers.pickerPaths(
          galleryMode: GalleryMode.video,
          selectCount: 5,
        );
  }
///直接打开相机拍摄图片 Open the camera directly to take a picture
ImagePickers.openCamera().then((Media media){
    /// media 包含照片路径信息 Include photo path information
  });

///直接打开相机拍摄视频 Open the camera directly to shoot the video
ImagePickers.openCamera(cameraMimeType: CameraMimeType.video).then((media){
    /// media 包含视频路径信息 Contains video path information
  });

///预览图片 Preview picture
ImagePickers.previewImage(_listImagePaths[index].path);
///预览多张图片 Preview multiple pictures
ImagePickers.previewImagesByMedia(_listImagePaths,index);
///预览多张图片 Preview multiple pictures
ImagePickers.previewImages(paths,index);

///预览视频 Preview video
ImagePickers.previewVideo(_listVideoPaths[index].path);
///保存图片到图库 Save image to gallery
ImagePickers.saveImageToGallery("http://i1.sinaimg.cn/ent/d/2008-06-04/U105P28T3D2048907F326DT20080604225106.jpg");
/// 保存截图图片 ByteData 到图库 Save screenshot image ByteData to gallery
RenderRepaintBoundary boundary = globalKey.currentContext.findRenderObject();
ui.Image image = await boundary.toImage(pixelRatio: 3);
ByteData byteData = await image.toByteData(format: ui.ImageByteFormat.png);
Uint8List data = byteData.buffer.asUint8List();

String dataImagePath = await ImagePickers.saveByteDataImageToGallery(data,);

///保存视频到图库 Save video to gallery
ImagePickers.saveVideoToGallery("http://xxxx/xx/xx.mp4");

iOS #

Add the following entry to your Info.plist file, located in /Info.plist : <key>NSAppTransportSecurity</key> <dict> <key>NSAllowsArbitraryLoads</key> <true/> </dict> <key>NSMicrophoneUsageDescription</key> <string>...</string> <key>NSPhotoLibraryAddUsageDescription</key> <string>...</string> <key>NSCameraUsageDescription</key> <string>...</string> <key>NSPhotoLibraryUsageDescription</key> <string>...</string>

1.0.7+3 #

  • 临时修复 MethodChannel.Result 为 null 崩溃问题
  • Temporarily fix crash when MethodChannel.Result is null

1.0.7+2 #

  • 使用了sdk29,适配Android Q
  • Used sdk29, adapted to Android Q
  • 安卓修复小米Android Q 问题
  • Android fixes Xiaomi Android Q issue

1.0.7+1 #

  • 安卓修复安卓Q .gif 图片裁剪后无法播放的问题
  • Android fix the problem that Android Q .gif picture cannot be played after cropping

1.0.7 #

  • 新增保存图片ByteData数据
  • Added Byte Data for saving pictures
  • 修复iOS压缩图片异常
  • Fix iOS compressed picture abnormal

1.0.6+2 #

  • 修复flutter回调异常
  • Fix flutter callback exception
  • CorpConfig 类 改为 CropConfig 类,参数中的 corpConfig 改为 cropConfig
  • CorpConfig class changed toCropConfig class, and corpConfig in the parameter was changed tocropConfig
  • ios修复ios13获取图片路径没有后缀名问题,修复没有设置裁剪获取图片路径为null的问题
  • ios fix ios 13 get image path without suffix

1.0.6+1 #

  • ios修复ios13获取相册路径错误问题
  • iOS fix iOS13 getting album path error problem
  • android优化预览多图片时内存问题
  • Android optimization memory issues when previewing multiple pictures

1.0.6 #

  • 添加预览多图功能
  • Add preview multi-picture function
  • 修改ui主题颜色功能,由原来的预制ui颜色改为动态设置ui颜色
  • Modify the ui theme color function from the original pre-made ui color to dynamically set the ui color
  • 修复无法展示gif图片功能(注意:忽略了gif裁剪/压缩功能)
  • Fix unable to display gif image function (note: gif crop/compress function is ignored)

1.0.5+3 #

  • 安卓修复加载库报错问题
  • Android fixes some mobile phone loading library error

1.0.5+2 #

  • 修复项目主页重定向问题
  • Fix project homepage redirection problem

1.0.5+1 #

  • Modify bug

1.0.5 #

  • 适配安卓安卓Q,增加ui主题配置功能,增加直接拍照和录制视频功能
  • Adapt Android Android Q, add ui theme configuration function, increase direct photo and record video function

1.0.4+1 #

  • Fix Android P can't preview image

1.0.4 #

  • configuration description

1.0.3 #

  • Increase the save network video to album function

1.0.2 #

  • Support Android iOS
  • Android i OS supports local language environment (Chinese or English)
  • image_pickers Support picture selection, video multiple selection, support to save network pictures to albums, support preview video and preview picture function

example/lib/main.dart

import 'dart:io';
import 'dart:typed_data';

import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'dart:async';

import 'package:flutter/services.dart';
import 'package:image_pickers/image_pickers.dart';
import 'package:image_pickers/CropConfig.dart';
import 'package:image_pickers/Media.dart';
import 'package:image_pickers/UIConfig.dart';
import 'dart:ui' as ui;

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

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

class _MyAppState extends State<MyApp> {
  GalleryMode _galleryMode = GalleryMode.image;
  GlobalKey globalKey;
  @override
  void initState() {
    super.initState();
    globalKey = GlobalKey();
  }

  List<Media> _listImagePaths = List();
  List<Media> _listVideoPaths = List();
  String dataImagePath = "";

  Future<void> selectImages() async {
    try {
      _galleryMode = GalleryMode.image;
      _listImagePaths = await ImagePickers.pickerPaths(
          galleryMode: _galleryMode,
          selectCount: 8,
          showCamera: true,
          cropConfig :CropConfig(enableCrop: true,height: 1,width: 1),
          compressSize: 500,
          uiConfig: UIConfig(uiThemeColor: Color(0xffff0000)),
      );
      _listImagePaths.forEach((media){
        print(media.path.toString());
      });
      setState(() {

      });
    } on PlatformException {}
  }

  Future<void> selectVideos() async {
    try {
      _galleryMode = GalleryMode.video;
      _listVideoPaths = await ImagePickers.pickerPaths(
        galleryMode: _galleryMode,
        selectCount: 2,
        showCamera: true,
      );
      setState(() {

      });
      print(_listVideoPaths);
    } on PlatformException {}
  }

  @override
  Widget build(BuildContext context) {
    return RepaintBoundary(
      key: globalKey,
      child: MaterialApp(
        theme: ThemeData(
          backgroundColor: Colors.white,
          primaryColor: Colors.white,
        ),

        home: Scaffold(
          appBar: AppBar(
            title: const Text('多图选择'),
          ),
          body: SingleChildScrollView(
            physics: BouncingScrollPhysics(),
            child: Column(
              children: <Widget>[
                GridView.builder(
                    physics: NeverScrollableScrollPhysics(),
                    itemCount: _listImagePaths == null ? 0 : _listImagePaths.length,
                    shrinkWrap: true,
                    gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                        crossAxisCount: 3,
                        mainAxisSpacing: 20.0,
                        crossAxisSpacing: 10.0,
                        childAspectRatio: 1.0),
                    itemBuilder: (BuildContext context, int index) {
                      return GestureDetector(
                        onTap: (){
//                        ImagePickers.previewImage(_listImagePaths[index].path);

//                      List<String> paths = [];
//                        _listImagePaths.forEach((media){
//                          paths.add(media.path);
//                        });
//
//                        ImagePickers.previewImages(paths,index);

                          ImagePickers.previewImagesByMedia(_listImagePaths,index);
                        },
                        child: Image.file(
                          File(
                            _listImagePaths[index].path,
                          ),
                          fit: BoxFit.cover,
                        ),
                      );
                    }),
                RaisedButton(
                  onPressed: () {
                    selectImages();
                  },
                  child: Text("选择图片"),
                ),
                RaisedButton(
                  onPressed: () {

                    ImagePickers.openCamera(cropConfig: CropConfig(enableCrop: true, width: 2, height: 3)).then((Media media){
                      _listImagePaths.clear();
                      _listImagePaths.add(media);
                      setState(() {

                      });
                    });
                  },
                  child: Text("拍照"),
                ),
                RaisedButton(
                  onPressed: () {
                    ImagePickers.openCamera(cameraMimeType: CameraMimeType.video).then((media){
                      _listVideoPaths.clear();
                      _listVideoPaths.add(media);
                      setState(() {

                      });
                    });
                  },
                  child: Text("拍视频"),
                ),
                GridView.builder(
                    physics: NeverScrollableScrollPhysics(),
                    itemCount: _listVideoPaths == null ? 0 : _listVideoPaths.length,
                    shrinkWrap: true,
                    gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
                        crossAxisCount: 3,
                        mainAxisSpacing: 20.0,
                        crossAxisSpacing: 10.0,
                        childAspectRatio: 1.0),
                    itemBuilder: (BuildContext context, int index) {
                      return GestureDetector(
                        onTap: (){
                          ImagePickers.previewVideo(_listVideoPaths[index].path,);
                        },
                        child: Image.file(
                          File(
                            _listVideoPaths[index].thumbPath,
                          ),
                          fit: BoxFit.cover,
                        ),
                      );
                    }),
                RaisedButton(
                  onPressed: () {
                    selectVideos();
                  },
                  child: Text("选择视频"),
                ),

                InkWell(
                  onTap: (){
                    ImagePickers.previewImage("http://i1.sinaimg.cn/ent/d/2008-06-04/U105P28T3D2048907F326DT20080604225106.jpg");
                  },
                    child: Image.network("http://i1.sinaimg.cn/ent/d/2008-06-04/U105P28T3D2048907F326DT20080604225106.jpg",fit: BoxFit.cover,width: 100,height: 100,)),
                RaisedButton(
                  onPressed: () {
                    Future<String> future = ImagePickers.saveImageToGallery("http://i1.sinaimg.cn/ent/d/2008-06-04/U105P28T3D2048907F326DT20080604225106.jpg");
                    future.then((path){
                      print("保存图片路径:"+ path);
                    });
                  },
                  child: Text("保存网络图片"),
                ),
                dataImagePath == "" ? Container():GestureDetector(onTap: (){
                  ImagePickers.previewImage(dataImagePath);
                },child: Image.file(File(dataImagePath),fit: BoxFit.cover,width: 100,height: 100,)),
                RaisedButton(
                  onPressed: () async {

                    RenderRepaintBoundary boundary = globalKey.currentContext.findRenderObject();
                    ui.Image image = await boundary.toImage(pixelRatio: 3);
                    ByteData byteData = await image.toByteData(format: ui.ImageByteFormat.png);
                    Uint8List data = byteData.buffer.asUint8List();

                    dataImagePath = await ImagePickers.saveByteDataImageToGallery(data,);

                    print("保存截屏图片 = "+ dataImagePath);
                    setState(() {

                    });
                  },
                  child: Text("保存截屏图片"),
                ),

                RaisedButton(
                  onPressed: () {
                      Future<String> future = ImagePickers.saveVideoToGallery("http://vd4.bdstatic.com/mda-jbmn50510sid5yx5/sc/mda-jbmn50510sid5yx5.mp4");
                      future.then((path){
                        print("视频保存成功");
                      });
                  },
                  child: Text("保存视频"),
                ),
              ],
            ),
          ),
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  image_pickers: ^1.0.7+3

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:image_pickers/image_pickers.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
78
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]
89
Learn more about scoring.

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

  • Dart: 2.8.1
  • pana: 0.13.8-dev
  • Flutter: 1.17.0

Health suggestions

Format lib/UIConfig.dart.

Run flutter format to format lib/UIConfig.dart.

Format lib/image_pickers.dart.

Run flutter format to format lib/image_pickers.dart.

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