pickAssets static method
- BuildContext context, {
- Key? key,
- AssetPickerPageRouteBuilder<
List< ? pageRouteBuilder,AssetEntity> > - dynamic onPermissionDenied(
- BuildContext context,
- String delegateDescription
- InstaAssetCropDelegate cropDelegate = const InstaAssetCropDelegate(),
- int gridCount = _kGridCount,
- ThemeData? pickerTheme,
- AssetPickerTextDelegate? textDelegate,
- String? title,
- bool closeOnComplete = false,
- required dynamic onCompleted(
- Stream<
InstaAssetsExportDetails> exportDetails
- Stream<
- Widget loadingIndicatorBuilder()?,
- List<
AssetEntity> ? selectedAssets, - int maxAssets = defaultMaxAssetsCount,
- int pageSize = defaultAssetsPerPage,
- ThumbnailSize pathThumbnailSize = defaultPathThumbnailSize,
- SortPathDelegate<
AssetPathEntity> ? sortPathDelegate = SortPathDelegate.common, - bool sortPathsByModifiedDate = false,
- FilterOptionGroup? filterOptions,
- Duration initializeDelayDuration = _kInitializeDelayDuration,
Pick assets with the given arguments.
Set useRootNavigator
to determine
whether the picker route should use the root Navigator.
By extending the AssetPickerPageRoute
, users can customize the route
and use it with the pageRouteBuilder
.
Set onPermissionDenied
to manually handle the denied permission error.
The default behavior is to open a ScaffoldMessenger.
Crop options
- Set
cropDelegate
to customize the display and export of crops.
Those arguments are used by InstaAssetPickerBuilder
-
Set
gridCount
to specifies the number of assets in the cross axis. Defaults to_kGridCount
, like instagram. -
Set
pickerTheme
to specifies the theme to apply to the picker. It is by default initialized with theprimaryColor
of the context theme. -
Set
textDelegate
to specifies the language to apply to the picker. Default is the locale language from the context. -
Set
title
to specifies the text title in the picker AppBar. -
Set
closeOnComplete
to specifies if the picker should be closed after assets selection confirmation. -
The
onCompleted
callback is called when the assets selection is confirmed. It will as argument a Stream with exportation details InstaAssetsExportDetails. -
Set
loadingIndicatorBuilder
to specifies the loader indicator to display in the picker.
Those arguments are used by DefaultAssetPickerProvider
-
Set
selectedAssets
to specifies which assets to preselect when the picker is opened. -
Set
maxAssets
to specifies the maximum of assets that can be selected Defaults todefaultMaxAssetsCount
. -
Set
pageSize
to specifies the quantity of assets to display in a single page. Defaults todefaultAssetsPerPage
. -
Set
pathThumbnailSize
to specifies the album thumbnail size in the albums list Defaults todefaultPathThumbnailSize
. -
Set
sortPathDelegate
to specifies the order of the assets Defaults toSortPathDelegate.common
. -
Set
sortPathsByModifiedDate
to specifies whether the modified_date can be used in the sort delegate. Defaults tofalse
. -
Set
filterOptions
to specifies the rules to include/exclude assets from the list -
Set
initializeDelayDuration
to specifies the delay before loading the assets Defaults to_kInitializeDelayDuration
.
Implementation
static Future<List<AssetEntity>?> pickAssets(
BuildContext context, {
Key? key,
bool useRootNavigator = true,
AssetPickerPageRouteBuilder<List<AssetEntity>>? pageRouteBuilder,
Function(BuildContext context, String delegateDescription)?
onPermissionDenied,
/// Crop options
InstaAssetCropDelegate cropDelegate = const InstaAssetCropDelegate(),
/// InstaAssetPickerBuilder options
int gridCount = _kGridCount,
ThemeData? pickerTheme,
AssetPickerTextDelegate? textDelegate,
String? title,
bool closeOnComplete = false,
required Function(Stream<InstaAssetsExportDetails> exportDetails)
onCompleted,
Widget Function(BuildContext, bool)? loadingIndicatorBuilder,
/// DefaultAssetPickerProvider options
List<AssetEntity>? selectedAssets,
int maxAssets = defaultMaxAssetsCount,
int pageSize = defaultAssetsPerPage,
ThumbnailSize pathThumbnailSize = defaultPathThumbnailSize,
SortPathDelegate<AssetPathEntity>? sortPathDelegate =
SortPathDelegate.common,
bool sortPathsByModifiedDate = false,
FilterOptionGroup? filterOptions,
Duration initializeDelayDuration = _kInitializeDelayDuration,
}) async {
final locale = Localizations.maybeLocaleOf(context);
final text = textDelegate ?? assetPickerTextDelegateFromLocale(locale);
// must be called before initializing any picker provider to avoid `PlatformException(PERMISSION_REQUESTING)` type exception
PermissionState? ps;
try {
ps = await _permissionCheck();
} catch (e) {
_openErrorPermission(context, text, onPermissionDenied);
return [];
}
final DefaultAssetPickerProvider provider = DefaultAssetPickerProvider(
selectedAssets: selectedAssets,
maxAssets: maxAssets,
pageSize: pageSize,
pathThumbnailSize: pathThumbnailSize,
requestType: RequestType.image,
sortPathDelegate: sortPathDelegate,
sortPathsByModifiedDate: sortPathsByModifiedDate,
filterOptions: filterOptions,
initializeDelayDuration: initializeDelayDuration,
);
final InstaAssetPickerBuilder builder = InstaAssetPickerBuilder(
initialPermission: ps,
provider: provider,
title: title,
gridCount: gridCount,
pickerTheme: pickerTheme ?? themeData(Theme.of(context).primaryColor),
locale: locale,
keepScrollOffset: false,
textDelegate: text,
loadingIndicatorBuilder: loadingIndicatorBuilder,
closeOnComplete: closeOnComplete,
cropDelegate: cropDelegate,
onCompleted: onCompleted,
);
return AssetPicker.pickAssetsWithDelegate(
context,
delegate: builder,
useRootNavigator: useRootNavigator,
pageRouteBuilder: pageRouteBuilder,
);
}