flutter wechat assets picker
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.
all ui designs are based on wechat 8.x, and it will be updated following the wechat update in anytime.
features ✨
- ♻️ fully implementable with delegates override
- �� 99% similar to wechat style
- ⚡️ adjustable performance according to parameters
- �� image asset support
- �� heic/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 ��
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 ��
version constraints
flutter sdk: >=2.0.0
.
if you got a resolve conflict
error when running flutter pub get
,
please use dependency_overrides
to fix it. see here .
flutter
add wechat_assets_picker
to pubspec.yaml
dependencies.
dependencies:
wechat_assets_picker: ^latest_version
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
- platform version has to be at least 9.0. modify
ios/podfile
and update accordingly.
platform :ios, '9.0'
- 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
- platform version has to be at least 10.15. modify
macos/podfile
and update accordingly.
platform :osx, '10.15'
- set the minimum deployment target to 10.15. use xcode to open
macos/runner.xcworkspace
. - follow the ios instructions and modify
info.plist
accordingly.
usage ��
name | type | description | default |
---|---|---|---|
selectedassets | list<assetentity>? |
selected assets. prevent duplicate selection. if you don’t need to prevent duplicate selection, just don’t pass it. | null |
maxassets | int |
maximum asset that the picker can pick. | 9 |
pagesize | int? |
number of assets per page. must be a multiple of gridcount . |
320 (80 * 4) |
gridthumbsize | int |
thumbnail size for the grid’s item. | 200 |
paththumbsize | int |
thumbnail size for the path selector. | 80 |
previewthumbsize | list<int>? |
preview thumbnail size in the viewer. | null |
gridcount | int |
grid count in picker. | 4 |
requesttype | requesttype |
request type for picker. | requesttype.image |
specialpickertype | spacialpickertype? |
provides the option to integrate a custom picker type. | null |
themecolor | color? |
main theme color for the picker. | color(0xff00bc56) |
pickertheme | themedata? |
theme data provider for the picker and the viewer. | null |
sortpathdelegate | sortpathdeleage? |
path entities sort delegate for the picker, sort paths as you want. | commonsortpathdelegate |
textdelegate | assetspickertextdelegate? |
text delegate for the picker, for customize the texts. | defaultassetspickertextdelegate() |
filteroptions | filteroptiongroup? |
allow users to customize assets filter options. | null |
specialitembuilder | widgetbuilder? |
the widget builder for the special item. | null |
specialitemposition | specialitemposition |
allow users set a special item in the picker with several positions. | specialitemposition.none |
loadingindicatorbuilder | indicatorbuilder? |
indicates the loading status for the builder. | null |
allowspecialitemwhenempty | bool |
whether the special item will display or not when assets is empty. | false |
selectpredicate | assetselectpredicate |
predicate whether an asset can be selected or unselected. | null |
routecurve | curve |
the curve which the picker use to build page route transition. | curves.easein |
routeduration | duration |
the duration which the picker use to build page route transition. | const duration(milliseconds: 500) |
simple usage
final list<assetentity> assets = await assetpicker.pickassets(context);
using custom delegate
final yourassetpickerprovider provider = yourprovider;
final customassetpickerbuilderdelegate builder = yourbuilder(provider);
final list<yourassetentity>? result = await assetpicker.pickassetswithdelegate(
context,
provider: provider,
delegate: builder,
);
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.
detailed usage
tl;dr, we’ve put multiple common usage with the packages into the example.
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 only defined a picker that integrates with directory
and file
(completely out of the photo_manager
scope).
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 ❔
build failed with unresolved reference: r
e: <path>photo_manager-x.y.zandroidsrcmainkotlintopkiktimagescannercorephotomanagerdeletemanager.kt: (116, 36): unresolved reference: r
e: <path>photo_manager-x.y.zandroidsrcmainkotlintopkiktimagescannercorephotomanagerdeletemanager.kt: (119, 36): unresolved reference: createtrashrequest
e: <path>photo_manager-x.y.zandroidsrcmainkotlintopkiktimagescannercorephotomanagerplugin.kt: (341, 84): unresolved reference: r
e: <path>photo_manager-x.y.zandroidsrcmainkotlintopkiktimagescannercoreutilsandroid30dbutils.kt: (34, 34): unresolved reference: r
e: <path>photo_manager-x.y.zandroidsrcmainkotlintopkiktimagescannercoreutilsidbutils.kt: (27, 67): unresolved reference: r
failure: build failed with an exception.
run flutter clean
first.
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.originfile
, if uint8list
then entity.originbytes
.
if you still need path after requested the file
, get it through file.absolutepath
.
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 uint8list bytedata = await file.readasbytes(); // convert to uint8list
final assetentity imageentity = await photomanager.editor.saveimage(bytedata); // saved in the device then create an assetentity
if you don’t want to keep the asset in your device,
just delete it after you complete with your process (upload, editing, etc).
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"
/>
Comments are closed.