asset_pickers 0.1.2

  • Readme
  • Changelog
  • Example
  • Installing
  • 68

asset_pickers #

Plug-in update: iOS has been supported, android to be updated.

Similar to WeChat style of resource selection, support a variety of picture, video combination selection, support compression, preview pictures and video.

类似微信风格资源选取,支持图片、视频多种组合选取 ,支持压缩,预览图片和视频。

Supported Platforms

  • iOS
  • Android (Ready to update)

How to Use #

1. Depend on it

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

dependencies:
  asset_pickers: ^0.1.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:asset_pickers/asset_pickers.dart';

Plugin instructions #

插件调用入口

static Future<List> getAssets({
      AssetsType assetType = AssetsType.imageOnly,
      int imageCount = 9
})

提供4中选取类型

/// 资源选择类型
enum AssetsType {
  /// 仅图片
  imageOnly, 
  /// 仅视频
  videoOnly,
  /// 图片或视频
  imageOrVideo,
  /// 图片和视频
  imageAndVideo,
}

1、imageOnly

仅选择图片

2、videoOnly

仅选择视频

3、imageOrVideo

选择图片或视频

4、imageAndVideo

选择图片和视频

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>

github地址:https://github.com/Qson8/asset_pickers

了解学习更多关于Flutter技术,欢迎关注公众号: Hi Flutter,个人微信:qiukangsheng

0.1.2 #

  • iOS is supported, android to be updated

0.1.0 #

  • iOS is supported, android to be updated

0.0.3 #

  • iOS is supported, android to be updated

0.0.2 #

  • iOS已支持,安卓待更新
  • IOS is supported, android to be updated

0.0.1 #

  • iOS已支持,安卓待更新
  • IOS is supported, android to be updated

example/lib/main.dart

import 'dart:io';
import 'package:flutter/material.dart';
import 'package:asset_pickers/asset_pickers.dart';
import 'my_player.dart';

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

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

class _MyAppState extends State<MyApp> {
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: HomePage(),
    );
  }
}

class HomePage extends StatefulWidget {
  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  List assets = [];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('资源选择器'),
      ),
      body: Container(
        child: ListView(
          children: [
            InkWell(
              onTap: () async {
                List list = await AssetPickers.getAssets();
                setState(() {
                  assets = list;
                });
              },
              child: Container(
                color: Color(0xfff1f1f1),
                padding: EdgeInsets.all(15),
                margin: EdgeInsets.all(10),
                child: Text(
                  '选择图片',
                  style: TextStyle(color: Colors.lightGreen, fontSize: 16),
                ),
              ),
            ),
            InkWell(
              onTap: () async {
                List list = await AssetPickers.getAssets(
                    assetType: AssetsType.videoOnly);
                setState(() {
                  assets = list;
                });
              },
              child: Container(
                color: Color(0xfff1f1f1),
                padding: EdgeInsets.all(15),
                margin: EdgeInsets.all(10),
                child: Text(
                  '选择视频',
                  style: TextStyle(color: Colors.lightGreen, fontSize: 16),
                ),
              ),
            ),
            InkWell(
              onTap: () async {
                List list = await AssetPickers.getAssets(
                    assetType: AssetsType.imageOrVideo);
                setState(() {
                  assets = list;
                });
              },
              child: Container(
                color: Color(0xfff1f1f1),
                padding: EdgeInsets.all(15),
                margin: EdgeInsets.all(10),
                child: Text(
                  '图片或视频',
                  style: TextStyle(color: Colors.lightGreen, fontSize: 16),
                ),
              ),
            ),
            InkWell(
              onTap: () async {
                List list = await AssetPickers.getAssets(
                    assetType: AssetsType.imageAndVideo);
                setState(() {
                  assets = list;
                });
              },
              child: Container(
                color: Color(0xfff1f1f1),
                padding: EdgeInsets.all(15),
                margin: EdgeInsets.all(10),
                child: Text(
                  '图片和视频',
                  style: TextStyle(color: Colors.lightGreen, fontSize: 16),
                ),
              ),
            ),
            InkWell(
              child: Container(
                color: Color(0xfff4f4f4),
                margin: EdgeInsets.all(10),
                child: Center(
                  child: Wrap(children: <Widget>[
                    for (Map item in assets) _assetWidget(item)
                  ]),
                ),
              ),
            ),
          ],
        ),
      ),
    );
  }

  Widget _assetWidget(Map file) {
    String filePath = file['path'];
    String type = file['type'];

    return Container(
      height: 80,
      width: 80,
      margin: EdgeInsets.all(2),
      decoration: BoxDecoration(
          color: Colors.lightBlue,
          border:
              Border.all(color: Colors.blueAccent.withAlpha(60), width: 1.0),
          borderRadius: BorderRadius.all(Radius.circular(1))),
      child: Container(
        child: (type == 'image')
            ? Image.file(File(filePath))
            : MyPlayer(
                file: File(filePath),
              ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  asset_pickers: ^0.1.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:asset_pickers/asset_pickers.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
35
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]
68
Learn more about scoring.

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