pickAssets method
Future<List<AssetEntity> ?>
pickAssets(
- BuildContext context, {
- Key? key,
- AssetPickerConfig pickerConfig = const AssetPickerConfig(),
- PermissionRequestOption? permissionRequestOption,
- AssetPickerPageRouteBuilder<
List< ? pageRouteBuilder,AssetEntity> >
Pick assets with the given pickerConfig
.
根据给定的 pickerConfig
选择资源。
Set useRootNavigator
to determine
whether the picker route should use the root Navigator.
使用 useRootNavigator
来控制选择器的路由是否使用最顶层的 Navigator。
By extending the AssetPickerPageRoute, users can customize the route
and use it with the pageRouteBuilder
.
继承 AssetPickerPageRoute 可以自定义路由,
并且通过 pageRouteBuilder
进行使用。
See also:
- AssetPickerConfig which holds all configurations for basic picking.
- DefaultAssetPickerProvider which is the default provider that manages assets during the picking process.
- DefaultAssetPickerBuilderDelegate which is the default builder that builds all widgets during the picking process.
Implementation
Future<List<AssetEntity>?> pickAssets(
BuildContext context, {
Key? key,
AssetPickerConfig pickerConfig = const AssetPickerConfig(),
PermissionRequestOption? permissionRequestOption,
bool useRootNavigator = true,
AssetPickerPageRouteBuilder<List<AssetEntity>>? pageRouteBuilder,
}) async {
permissionRequestOption ??= PermissionRequestOption(
androidPermission: AndroidPermission(
type: pickerConfig.requestType,
mediaLocation: false,
),
);
final PermissionState ps = await permissionCheck(
requestOption: permissionRequestOption,
);
final AssetPickerPageRoute<List<AssetEntity>> route =
pageRouteBuilder?.call(const SizedBox.shrink()) ??
AssetPickerPageRoute<List<AssetEntity>>(
builder: (_) => const SizedBox.shrink(),
);
final DefaultAssetPickerProvider provider = DefaultAssetPickerProvider(
maxAssets: pickerConfig.maxAssets,
pageSize: pickerConfig.pageSize,
pathThumbnailSize: pickerConfig.pathThumbnailSize,
selectedAssets: pickerConfig.selectedAssets,
requestType: pickerConfig.requestType,
sortPathDelegate: pickerConfig.sortPathDelegate,
filterOptions: pickerConfig.filterOptions,
initializeDelayDuration: route.transitionDuration,
);
final Widget picker = AssetPicker<AssetEntity, AssetPathEntity>(
key: key,
permissionRequestOption: permissionRequestOption,
builder: DefaultAssetPickerBuilderDelegate(
provider: provider,
initialPermission: ps,
gridCount: pickerConfig.gridCount,
pickerTheme: pickerConfig.pickerTheme,
gridThumbnailSize: pickerConfig.gridThumbnailSize,
previewThumbnailSize: pickerConfig.previewThumbnailSize,
specialPickerType: pickerConfig.specialPickerType,
specialItemPosition: pickerConfig.specialItemPosition,
specialItemBuilder: pickerConfig.specialItemBuilder,
loadingIndicatorBuilder: pickerConfig.loadingIndicatorBuilder,
selectPredicate: pickerConfig.selectPredicate,
shouldRevertGrid: pickerConfig.shouldRevertGrid,
limitedPermissionOverlayPredicate:
pickerConfig.limitedPermissionOverlayPredicate,
pathNameBuilder: pickerConfig.pathNameBuilder,
assetsChangeCallback: pickerConfig.assetsChangeCallback,
assetsChangeRefreshPredicate: pickerConfig.assetsChangeRefreshPredicate,
textDelegate: pickerConfig.textDelegate,
themeColor: pickerConfig.themeColor,
locale: Localizations.maybeLocaleOf(context),
shouldAutoplayPreview: pickerConfig.shouldAutoplayPreview,
),
);
final List<AssetEntity>? result = await Navigator.maybeOf(
context,
rootNavigator: useRootNavigator,
)?.push<List<AssetEntity>>(
pageRouteBuilder?.call(picker) ??
AssetPickerPageRoute<List<AssetEntity>>(builder: (_) => picker),
);
return result;
}