語言:英語| 中文
基於微信的UI的圖像選擇器(也帶有視頻和音頻),用於撲朔迷離的項目。
當前基於以下UI的微信版將在隨時更新之後更新8.0.51 UI設計。
要拍攝照片或視頻以獲取資產,請檢查示例中的詳細用法,然後轉到Wechat_camera_picker。該包是一個獨立的擴展名,可以結合使用。
請參閱《遷移指南》,以了解如何在破裂變化之間遷移。
該軟件包僅保證在穩定版本的Flutter上工作。我們不會實時更新它以與其他撲波頻道保持一致。
| 3.0 | 3.3 | 3.7 | 3.10 | 3.13 | 3.16 | |
|---|---|---|---|---|---|---|
| 8.9.0+ | ✅ | |||||
| 8.7.0+ | ✅ | |||||
| 8.5.0+ | ✅ | |||||
| 8.4.0+ | ✅ | |||||
| 8.0.0+ | ✅ | ✅ | ||||
| 7.3.0+ | ✅ | ✅ |
如果您在運行flutter pub get時遇到了resolve conflict錯誤,請使用dependency_overrides來修復它。
該軟件包是由這些精美的包裝構建的。
| 姓名 | 特徵 |
|---|---|
| photo_manager | 資產的基本抽象和管理。 |
| Extended_Image | 預覽具有預期行為的資產。 |
| 提供者 | 幫助管理選擇器的相互作用狀態。 |
| Video_player | 相應地播放視頻和音頻。 |
它們的實現應在包裝中相對穩定。如果您在使用Picker時發現與他們有關的任何問題,請首先向我們的問題跟踪器提交問題。
AssetEntityhttpdioRecent與他人最新)File或Uint8List (RAWDATA)創建AssetEntityThemeData的完全可定制主題entity.file或AssetEntityImage圖像。| 姓名 | 酒吧 | github |
|---|---|---|
| insta_assets_picker |
![]() | ![]() | ![]() |
|---|---|---|
![]() | ![]() | ![]() |
![]() | ![]() | ![]() |
在開始任何事情之前,請注意以下通知:
AssetEntityAssetPathEntity當您對相關的API和行為有疑問時,請查看Photo_Manager的API文檔以獲取更多詳細信息。
大多數用法詳細介紹了該示例。請在有任何疑問之前仔細瀏覽示例。
運行flutter pub add wechat_assets_picker ,或者手動添加wechat_assets_picker pubspec.yaml
dependencies :
wechat_assets_picker : ^latest_version最新的穩定版本是:
最新的開發版本是:
然後在您的代碼中導入包:
import 'package:wechat_assets_picker/wechat_assets_picker.dart' ;使用軟件包時,請將targetSdkVersion和compileSdkVersion升級到33 。否則,在Android 13上無法獲取資產。
| 姓名 | 必需的 | 宣布 | 最大API級別 | 其他的 |
|---|---|---|---|---|
READ_EXTERNAL_STORAGE | 是的 | 是的 | 32 | |
WRITE_EXTERNAL_STORAGE | 不 | 不 | 29 | |
ACCESS_MEDIA_LOCATION | 是的* | 不 | N/A。 | 閱讀exif時需要 |
READ_MEDIA_IMAGES | 是的* | 是的 | N/A。 | 閱讀圖像時需要 |
READ_MEDIA_VIDEO | 是的* | 是的 | N/A。 | 閱讀視頻時需要 |
READ_MEDIA_AUDIO | 是的* | 是的 | N/A。 | 閱讀音頻時需要 |
如果您針對Android SDK 33+,並且不需要加載照片,視頻或音頻,請考慮在應用程序中僅聲明相關許可,更具體地說:
< manifest xmlns : android = " http://schemas.android.com/apk/res/android "
xmlns : tools = " http://schemas.android.com/tools "
package = " com.your.app " >
<!-- Requesting access to images and videos. -->
< uses-permission android : name = " android.permission.READ_MEDIA_IMAGES " />
< uses-permission android : name = " android.permission.READ_MEDIA_VIDEO " />
<!-- When your app has no need to access audio, remove it or comment it out. -->
<!-- <uses-permission android:name="android.permission.READ_MEDIA_AUDIO" /> -->
</ manifest >ios/Podfile並進行相應更新。 platform :ios, '11.0'
#標題。Info.plist 。 <key>NSPhotoLibraryUsageDescription</key>
<string>Replace with your permission description.</string>
macos/Podfile並進行相應更新。 platform :osx , '10.15'#標題。macos/Runner.xcworkspace 。Info.plist 。 當您選擇資產時,包裹將獲得該Locale?從您的BuildContext ,然後返回當前語言的相應文本委託。確保您可以從BuildContext訪問的小部件樹中有一個有效的Locale 。否則,將使用默認的中國代表。
嵌入式文本代表語言為:
如果要使用自定義/固定文本委託,請通過AssetPickerConfig.textDelegate將其傳遞。
final List < AssetEntity > ? result = await AssetPicker . pickAssets (context);使用AssetPickerConfig進行更多的採摘行為。
final List < AssetEntity > ? result = await AssetPicker . pickAssets (
context,
pickerConfig : const AssetPickerConfig (),
); AssetPickerConfig的字段:
| 姓名 | 類型 | 描述 | 預設 |
|---|---|---|---|
| 選定 | List<AssetEntity>? | 選定的資產。防止重複選擇。 | null |
| Maxassets | int | 採摘者可以選擇的最大資產。 | 9 |
| 打頁 | int? | 每頁資產數量。必須是gridCount的倍數。 | 80 |
| 網格示威 | ThumbnailSize | 網格項目的縮略圖大小。 | ThumbnailSize.square(200) |
| paththumbnailsize | ThumbnailSize | 路徑選擇器的縮略圖大小。 | ThumbnailSize.square(80) |
| PreviewThumbNailsize | ThumbnailSize? | 預覽查看器中的縮略圖。 | null |
| requestType | RequestType | 請求類型選擇器。 | RequestType.common |
| 特殊Pickertype | SpecialPickerType? | 提供了集成自定義選擇器類型的選項。 | null |
| 保持Scrolloffset | bool | 選擇器是否應保存滾動和彈出之間的滾動偏移。 | null |
| SortPathDelegate | SortPathDelegate<AssetPathEntity>? | 路徑實體對選擇器進行排序,並根據需要對路徑進行排序。 | CommonSortPathDelegate |
| sortpathsbymodifieddate | bool | 是否允許排序代表使用FilterOptionGroup.containsPathModified對路徑進行分類。 | false |
| 過濾器 | PMFilter? | 允許用戶自定義資產過濾選項。 | null |
| gridcount | int | 在選擇器中的網格計數。 | 4 |
| themecolor | Color? | 選擇器的主要主題顏色。 | Color(0xff00bc56) |
| Pickertheme | ThemeData? | 選擇器和觀眾的主題數據提供商。 | null |
| Textdelegate | AssetPickerTextDelegate? | 文本委派選擇器,以自定義文本。 | AssetPickerTextDelegate() |
| 專業問題 | SpecialItemPosition | 允許用戶在選擇器中設置一個特殊物品,並設置多個位置。 | SpecialItemPosition.none |
| 專業人物 | SpecialItemBuilder? | 特殊物品的小部件構建器。 | null |
| 加載輔助構成器 | IndicatorBuilder? | 指示建築商的加載狀態。 | null |
| SelectPredicate | AssetSelectPredicate | 謂語是可以選擇還是未選擇資產。 | null |
| 應該reververtgrid | bool? | 資產網格是否應恢復。 | null |
| 限量性permissionOverlayPredicate | LimitedPermissionOverlayPredicate? | 謂詞是否應顯示有限的權限覆蓋。 | null |
| PATHNAMEBUILDER | PathNameBuilder<AssetPathEntity>? | 使用給定路徑實體構建自定義路徑(專輯)名稱。 | null |
| AssetschangeCallback | AssetsChangeCallback<AssetPathEntity>? | 當系統通知資產時,將調用回調。 | null |
| Assetschangerefreshpredicate | AssetsChangeRefreshPredicate<AssetPathEntity>? | 資產更改是否應使用給定的呼叫和當前選定路徑刷新。 | null |
| 應該autooplaypreview | bool | 預覽是否應自動播放。 | false |
maxAssets等於1 (又稱單選模式)時,使用SpecialPickerType.noPreview將立即選擇用戶單擊(按)並彈出的資產。limitedPermissionOverlayPredicate生命無堅持,如果您想忽略重新啟動後的有限預覽,則需要與自己的儲蓄方法集成。在示例中,我們對包裹進行了多個常見用法。您都可以在此處和此處找到List<PickMethod> pickMethods ,該方法在多個選擇和單個選擇模式下提供了方法。資產將臨時存儲,並顯示在頁面下方。
AssetEntityImage和AssetEntityImageProvider可以顯示圖像和視頻的拇指圖像以及圖像的原始數據。將其像常見的Image和ImageProvider一樣使用。
AssetEntityImage (asset, isOriginal : false );或者:
Image (image : AssetEntityImageProvider (asset, isOriginal : false )); // Register callback.
AssetPicker . registerObserve ();
// Unregister callback.
AssetPicker . unregisterObserve ();AssetEntity有多種方法可以使用I/O相關方法上傳AssetEntity 。請注意,I/O相關方法將消耗性能(通常是時間和內存),不應經常調用它們。
http http軟件包:https://pub.dev/packages/http
http軟件包使用MultipartFile來處理請求中的文件。
虛擬程式碼:
import 'package:http/http.dart' as http;
Future < void > upload () async {
final entity = await obtainYourEntity ();
final uri = Uri . https ( 'example.com' , 'create' );
final request = http. MultipartRequest ( 'POST' , uri)
..fields[ 'test_field' ] = 'test_value'
..files. add ( await multipartFileFromAssetEntity (entity));
final response = await request. send ();
if (response.statusCode == 200 ) {
print ( 'Uploaded!' );
}
}
Future <http. MultipartFile > multipartFileFromAssetEntity ( AssetEntity entity) async {
http. MultipartFile mf;
// Using the file path.
final file = await entity.file;
if (file == null ) {
throw StateError ( 'Unable to obtain file of the entity ${ entity . id }.' );
}
mf = await http. MultipartFile . fromPath ( 'test_file' , file.path);
// Using the bytes.
final bytes = await entity.originBytes;
if (bytes == null ) {
throw StateError ( 'Unable to obtain bytes of the entity ${ entity . id }.' );
}
mf = http. MultipartFile . fromBytes ( 'test_file' , bytes);
return mf;
}dio dio軟件包:https://pub.dev/packages/dio
dio軟件包還使用MultipartFile來處理請求中的文件。
虛擬程式碼:
import 'package:dio/dio.dart' as dio;
Future < void > upload () async {
final entity = await obtainYourEntity ();
final uri = Uri . https ( 'example.com' , 'create' );
final response = dio. Dio (). requestUri (
uri,
data : dio. FormData . fromMap ({
'test_field' : 'test_value' ,
'test_file' : await multipartFileFromAssetEntity (entity),
}),
);
print ( 'Uploaded!' );
}
Future <dio. MultipartFile > multipartFileFromAssetEntity ( AssetEntity entity) async {
dio. MultipartFile mf;
// Using the file path.
final file = await entity.file;
if (file == null ) {
throw StateError ( 'Unable to obtain file of the entity ${ entity . id }.' );
}
mf = await dio. MultipartFile . fromFile (file.path);
// Using the bytes.
final bytes = await entity.originBytes;
if (bytes == null ) {
throw StateError ( 'Unable to obtain bytes of the entity ${ entity . id }.' );
}
mf = dio. MultipartFile . fromBytes (bytes);
return mf;
}AssetPickerBuilderDelegate , AssetPickerViewerBuilderDelegate , AssetPickerProvider和AssetPickerViewerProvider都暴露了和不受歡迎。您可以擴展它們,並使用自己的類型使用通用類型<A: Asset, P: Path> ,然後實現抽象方法。
要知道如何完全自定義主題,小部件或佈局。請參閱如何在示例的“自定義選擇器”頁面中自定義委託。
如果您發現實現可能對他人有用,則可以提交PRS以創建自己的實現。有關更多詳細信息,請參見貢獻自定義實施。
Recent與他人最新) Recent是Android上所有資產的修復專輯名稱,因為所有資產的專輯不是實際的專輯,它僅代表所有媒體數據記錄。
要在Android上解決該問題,請使用pathNameBuilder ,例如:
AssetPickerConfig (
pathNameBuilder : ( AssetPathEntity path) => switch (path) {
final p when p.isAll => '最近' ,
// You can apply similar conditions to other common paths.
_ => path.name,
},
)其他平台上的其他專輯或專輯(iOS/MACOS)將遵循配置的系統本地化和支持的本地化。 pathNameBuilder可用於所有專輯。
有關更多詳細信息,請參見Photo_manager#561。
File或Uint8List (RAWDATA)創建AssetEntity為了將此軟件包與相機拍攝或相關的內容相結合,有一個解決方案,即如何使用File或Uint8List對象創建AssetEntity 。
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注意:如果您不想將文件保存在設備中,請盡可能地使用File進行操作。刪除AssetEntity可能會導致系統彈出窗口顯示:
final List < String > result = await PhotoManager .editor. deleteWithIds (
< String > [entity.id],
);有關更多詳細信息,請參見photo_manager#from-raw-data和photo_manager#delete-entities。
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需要註釋以保持單身,防止實例和版本之間的衝突,因此,當照片管理器使用Glide實現圖像功能時,該項目將定義其自己的AppGlideModule 。請參閱Glide生成的API文檔以進行實施。
非常感謝這些出色的人(表情符號鑰匙):
亞歷克斯·李 ? ? ? ?門ch情該q情️? | Caijinglong ? | 馬塞爾·施耐德(Marcel Schneider) ? ? | Ganlanshu0211 ? ? | Jasonhezz ? | Yaniv搖搖欲墜 ? ? ? | Avi-Yadav |
letalus ? ? | 藻類 ? | Nickolay Savchenko ? | 西格薩(Kosuke Saigusa) ? | 三聞書店 | didiosfaust ? | Xiejie ? |
艾哈邁德·馬蘇德(Ahmed Masoud) ? | Luomo-Pro 門ch情該q情️? | Paigupai ? | 穆罕默德·塔基·阿卜杜勒·阿齊茲(Muhammad Taqi Abdul Aziz) | 何錦餘 ? | 萊昂·達德利克(Leon Dudlik) ? | 梅爾 ? |
DDDROP | nguyen phuc loi ? | Cevheri ? | Mirimhee ? | 阿莫斯 ? | Dimil Kalathiya | 加索爾·吳(Gasol Wu) ? |
該項目遵循全企業規範。歡迎任何形式的貢獻! !
Intellij Idea的各個方面都是為了最大程度地提高開發人員的生產率。智能編碼援助和人體工程學設計共同使發展不僅富有成效,而且使開髮變得愉快。
感謝Jetbrains為Intellij Idea等IDE分配免費的開源許可證。
