Skip to content

qoohoo-app/flutter_wechat_assets_picker

Β 
Β 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

Flutter WeChat Assets Picker

pub package pub package Build status CodeFactor GitHub license

Awesome Flutter GitHub stars GitHub forks FlutterCandies

Language: English | δΈ­ζ–‡

An assets picker which based on the WeChat's UI, using photo_manager for asset implementation, extended_image for image preview, and provider to help control the state of the picker.

To take a photo or a video for assets, please check the detailed usage in the example, and head over to wechat_camera_picker.

Current WeChat version that UI based on: 8.x UI designs will be updated following the WeChat update in anytime.

Category πŸ—‚

Migration Guide ♻️

See Migration Guide.

Features ✨

  • ♻️ Fully implementable with delegates override
  • πŸ’š 99% similar to WeChat style
  • ⚑️ Adjustable performance according to parameters
  • πŸ“· Image asset support
    • πŸ”¬ HEIF Image type support
  • πŸŽ₯ Video asset support
  • 🎢 Audio asset support
  • 1️⃣ Single asset mode
  • πŸ’± i18n support
    • βͺ RTL language support
  • βž• Special item builder (prepend/append) support
  • πŸ—‚ Custom sort path delegate support
  • πŸ“ Custom text delegate support
  • ⏳ Custom filter options support ( photo_manager )
  • 🎏 Fully customizable theme
  • πŸ’» macOS support

Screenshots πŸ“Έ

1 2 3
4 5 6
7 8 9
10 10 12

READ THIS FIRST ‼️

Although the package provides assets selection, it still requires users to build their own methods to handle upload, image compress, etc. If you have any questions about how to build them, please run the example or refer to photo_manager for API usage.

Preparing for use 🍭

Versions compatibility

<2.5.0 2.8.0 2.10.0
7.0.0+ ❌ βœ… βœ…
6.3.0+ ❌ βœ… βœ…

If you got a resolve conflict error when running flutter pub get, please use dependency_overrides to fix it.

Flutter

Add wechat_assets_picker to pubspec.yaml dependencies.

dependencies:
  wechat_assets_picker: ^latest_version

The latest stable version is: pub package

The latest dev version is: pub package

Then import the package in your code:

import 'package:wechat_assets_picker/wechat_assets_picker.dart';

Android

Required permissions: INTERNET, READ_EXTERNAL_STORAGE, WRITE_EXTERNAL_STORAGE, ACCESS_MEDIA_LOCATION. If you don't need the ACCESS_MEDIA_LOCATION permission, see Disable ACCESS_MEDIA_LOCATION permission.

If you found some warning logs with Glide appearing, then the main project needs an implementation of AppGlideModule. See Generated API.

iOS

  1. Platform version has to be at least 9.0. Modify ios/Podfile and update accordingly.
platform :ios, '9.0'
  1. Add the following content to info.plist.
<key>NSAppTransportSecurity</key>
<dict>
	<key>NSAllowsArbitraryLoads</key>
	<true/>
</dict>
<key>NSPhotoLibraryUsageDescription</key>
<string>Replace with your permission description.</string>

macOS

  1. Platform version has to be at least 10.15. Modify macos/Podfile and update accordingly.
platform :osx, '10.15'
  1. Set the minimum deployment target to 10.15. Use XCode to open macos/Runner.xcworkspace .

  2. step 1

  3. step 2

  4. Follow the iOS instructions and modify info.plist accordingly.

Usage πŸ“–

Simple usage

final List<AssetEntity>? result = await AssetPicker.pickAssets(context);

Use AssetPickerConfig for more picking behaviors.

final List<AssetEntity>? result = await AssetPicker.pickAssets(
  context,
  pickerConfig: const AssetPickerConfig(),
);

Fields in AssetPickerConfig:

Name Type Description Default
selectedAssets List<AssetEntity>? Selected assets. Prevent duplicate selection. null
maxAssets int Maximum asset that the picker can pick. 9
pageSize int? Number of assets per page. Must be a multiple of gridCount. 80
gridThumbnailSize ThumbnailSize Thumbnail size for the grid's item. ThumbnailSize.square(200)
pathThumbnailSize ThumbnailSize Thumbnail size for the path selector. ThumbnailSize.square(80)
previewThumbnailSize ThumbnailSize? Preview thumbnail size in the viewer. null
requestType RequestType Request type for picker. RequestType.common
specialPickerType SpacialPickerType? Provides the option to integrate a custom picker type. null
keepScrollOffset bool Whether the picker should save the scroll offset between pushes and pops. null
sortPathDelegate SortPathDelegate<AssetPathEntity>? Path entities sort delegate for the picker, sort paths as you want. CommonSortPathDelegate
filterOptions FilterOptionGroup? Allow users to customize assets filter options. null
gridCount int Grid count in picker. 4
themeColor Color? Main theme color for the picker. Color(0xff00bc56)
pickerTheme ThemeData? Theme data provider for the picker and the viewer. null
textDelegate AssetPickerTextDelegate? Text delegate for the picker, for customize the texts. AssetPickerTextDelegate()
specialItemPosition SpecialItemPosition Allow users set a special item in the picker with several positions. SpecialItemPosition.none
specialItemBuilder SpecialItemBuilder? The widget builder for the special item. null
loadingIndicatorBuilder IndicatorBuilder? Indicates the loading status for the builder. null
selectPredicate AssetSelectPredicate Predicate whether an asset can be selected or unselected. null
shouldRevertGrid bool? Whether the assets grid should revert. null

Detailed usage

TL;DR, we've put multiple common usage with the packages into the example.

Using custom delegate

You can use the keepScrollOffset feature only with the pickAssetsWithDelegate method. See the Keep scroll offset pick method in the example for how to implement it.

For more details about custom delegates, head over to example/lib/customs.

Regular picking

You can both found List<PickMethod> pickMethods in example/lib/pages/multi_assets_page.dart and example/lib/pages/single_assets_page.dart, which provide methods in multiple picking and single picking mode. Assets will be stored temporary and displayed at the below of the page.

Multiple assets picking

The maximum assets limit is 9 in the multiple picking page, and you can modify it as you wish.

Some methods can only work with multiple mode, such as "WeChat Moment".

Single asset picking

Only one and maximum to one asset can be picked at once.

Custom pickers

You can try custom pickers with the "Custom" page. We've defined a picker that integrates with Directory and File (completely out of the photo_manager scope), and a picker with multiple tabs switching. You can submit PRs to create your own implementation if you found your implementation might be useful for others. See [Contribute custom implementations][lib/customs/CONTRIBUTING.md] for more details.

Display selected assets

The AssetEntityImageProvider can display the thumb image of images & videos, and the original data of image. Use it like a common ImageProvider.

Image(image: AssetEntityImageProvider(asset, isOriginal: false))

Check the example for how it displays.

Register assets change observe callback

AssetPicker.registerObserve(); // Register callback.
AssetPicker.unregisterObserve(); // Unregister callback.

Customize with your own type or UI

AssetPickerBuilderDelegate, AssetPickerViewerBuilderDelegate, AssetPickerProvider and AssetPickerViewerProvider are all exposed and overridable. You can extend them and use your own type with generic type <A: Asset, P: Path>, then implement abstract methods. See the Custom page in the example which has an implementation based on <File, Directory> types.

Frequently asked question ❔

Execution failed for task ':photo_manager:compileDebugKotlin'

See photo_manager#561 for more details.

How can I get path from the AssetEntity to integrate with File object, upload or edit?

You don't need it (might be).

You can always request the File object with entity.file or entity.originFile, and entity.originBytes for Uint8List.

If you still need path after requested the File, get it through file.path.

final File file = await entity.file; // Thumbnails or edited files.
final File originFile = await entity.originFile; // Original files.
final String path = file.path;
final String originPath = originFile.path;

How can I change the name of "Recent" or other entities name/properties?

The path entity called "Recent", brought by photo_manager in the path entities list, includes all AssetEntity on your device. "Recent" is a system named entity in most platforms. While we provided ability to customize the text delegate, the name/properties can only be updated with SortPathDelegate. This is the only way that you have access to all path entities, or the only way that we exposed currently.

To change the name of the path entity, extend the CommonSortPathDelegate with your own delegate, then write something like the code below:

/// Create your own sort path delegate.
class CustomSortPathDelegate extends CommonSortPathDelegate {
  const CustomSortPathDelegate();

  @override
  void sort(List<AssetPathEntity> list) {
    ///...///

    // In here you can check every path entities if you want.
    // The only property we recommend to change is [name],
    // And we have no responsibility for issues caused by
    // other properties update.
    for (final AssetPathEntity entity in list) {
      // If the entity `isAll`, that's the "Recent" entity you want.
      if (entity.isAll) {
        entity.name = 'Whatever you want';
      }
    }

    ///...///
  }
}

Pass the delegate through the static call method, then you will get a self-named path entity.

Create AssetEntity from File or Uint8List (rawData)

In order to combine this package with camera shooting or something related, there's a solution about how to create an AssetEntity with File or Uint8List object.

final File file = your_file; // Your `File` object
final String path = file.path;
final AssetEntity fileEntity = await PhotoManager.editor.saveImageWithPath(
  path,
  title: basename(path),
); // Saved in the device then create an AssetEntity

final Uint8List data = your_data; // Your `Uint8List` object
final AssetEntity imageEntity = await PhotoManager.editor.saveImage(
  file.path,
  title: 'title_with_extension.jpg',
); // Saved in the device then create an AssetEntity

Notice: If you don't want to keep the file in your device, use File for operations as much as possible. A deletion operation might call system popups with some OS:

final List<String> result = await PhotoManager.editor.deleteWithIds([entity.id]);

ref: flutter_photo_manager#insert-new-item

Glide warning 'Failed to find GeneratedAppGlideModule'

W/Glide   (21133): Failed to find GeneratedAppGlideModule. You should include an annotationProcessor compile dependency on com.github.bumptech.glide:compiler in you application ana a @GlideModule annotated AppGlideModule implementation or LibraryGlideModules will be silently ignored.

Glide needs annotation to keep singleton, prevent conflict between instances and versions, so while the photo manager uses Glide to implement image features, the project which import this should define its own AppGlideModule. See Android section for implementation.

Disable ACCESS_MEDIA_LOCATION permission

Android contains ACCESS_MEDIA_LOCATION permission by default. This permission is introduced in Android Q. If your app doesn't need the permission, you need to add the following node to the AndroidManifest.xml in your app:

<uses-permission
  android:name="android.permission.ACCESS_MEDIA_LOCATION"
  tools:node="remove"
  />

Contributors ✨

Many thanks to these wonderful people (emoji key):


Alex Li

πŸ’» 🎨 πŸ“– πŸ’‘ πŸ€” 🚧 πŸ’¬ πŸ‘€

Caijinglong

πŸ’‘ πŸ€”

Marcel Schneider

πŸ› πŸ’» πŸ€”

ganlanshu0211

πŸ› πŸ€”

JasonHezz

πŸ› πŸ’»

Yaniv Shaked

🌍 πŸ’» πŸ› 🚧

avi-yadav

πŸ’»

Letalus

πŸ› 🌍

greymag

🌍

Nickolay Savchenko

🎨

Kosuke Saigusa

🌍

δΈ‰ι—»δΉ¦εΊ—

πŸ“–

DidiosFaust

🌍

xiejie

πŸ›

Ahmed Masoud

🌍

luomo-pro

️️️️♿️ πŸ›

paigupai

🌍

This project follows the all-contributors specification. Contributions of any kind welcomed!!

Acknowledgement

Every aspect of IntelliJ IDEA has been designed to maximize developer productivity. Together, intelligent coding assistance and ergonomic design make development not only productive but also enjoyable.

Thanks to JetBrains for allocating free open-source licenses for IDEs such as IntelliJ IDEA.

Packages

No packages published

Languages

  • Dart 97.9%
  • Ruby 1.6%
  • Other 0.5%