pickAssets static method
- BuildContext context, {
- Key? key,
- AssetPickerPageRouteBuilder<
List< ? pageRouteBuilder,AssetEntity> > - dynamic onPermissionDenied(
- BuildContext context,
- String delegateDescription
- required dynamic onCompleted(
- Stream<
InstaExportDetails> exportDetails
- Stream<
- InstaAssetPickerConfig pickerConfig = const InstaAssetPickerConfig(),
- List<
AssetEntity> ? selectedAssets, - int maxAssets = defaultMaxAssetsCount,
- int pageSize = defaultAssetsPerPage,
- ThumbnailSize pathThumbnailSize = defaultPathThumbnailSize,
- SortPathDelegate<
AssetPathEntity> ? sortPathDelegate = SortPathDelegate.common, - bool sortPathsByModifiedDate = false,
- PMFilter? filterOptions,
- Duration initializeDelayDuration = _kInitializeDelayDuration,
- RequestType requestType = RequestType.common,
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.
Those arguments are used by InstaAssetPickerBuilder
-
The
onCompleted
callback is called when the assets selection is confirmed. It will as argument a Stream with exportation detailsInstaAssetsExportDetails
. -
Set
pickerConfig
to specifies more optional parameters for 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 to defaultMaxAssetsCount. -
Set
pageSize
to specifies the quantity of assets to display in a single page. Defaults to defaultAssetsPerPage. -
Set
pathThumbnailSize
to specifies the album thumbnail size in the albums list Defaults to defaultPathThumbnailSize. -
Set
sortPathDelegate
to specifies the order of the assets Defaults to SortPathDelegate.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
. -
Set
requestType
to specifies which type of asset to show in the picker. Defaults is RequestType.common. Only RequestType.image, RequestType.common and RequestType.common are supported.
Implementation
static Future<List<AssetEntity>?> pickAssets(
BuildContext context, {
Key? key,
bool useRootNavigator = true,
AssetPickerPageRouteBuilder<List<AssetEntity>>? pageRouteBuilder,
Function(BuildContext context, String delegateDescription)?
onPermissionDenied,
/// InstaAssetPickerBuilder parameters
required Function(Stream<InstaExportDetails> exportDetails) onCompleted,
InstaAssetPickerConfig pickerConfig = const InstaAssetPickerConfig(),
/// DefaultAssetPickerProvider parameters
List<AssetEntity>? selectedAssets,
int maxAssets = defaultMaxAssetsCount,
int pageSize = defaultAssetsPerPage,
ThumbnailSize pathThumbnailSize = defaultPathThumbnailSize,
SortPathDelegate<AssetPathEntity>? sortPathDelegate =
SortPathDelegate.common,
bool sortPathsByModifiedDate = false,
PMFilter? filterOptions,
Duration initializeDelayDuration = _kInitializeDelayDuration,
RequestType requestType = RequestType.common,
}) async {
_assertRequestType(requestType);
// must be called before initializing any picker provider to avoid `PlatformException(PERMISSION_REQUESTING)` type exception
PermissionState? ps;
try {
ps = await _permissionCheck(requestType);
} catch (e) {
_openErrorPermission(
context,
pickerConfig.textDelegate,
onPermissionDenied,
);
return [];
}
final DefaultAssetPickerProvider provider = DefaultAssetPickerProvider(
selectedAssets: selectedAssets,
maxAssets: maxAssets,
pageSize: pageSize,
pathThumbnailSize: pathThumbnailSize,
requestType: requestType,
sortPathDelegate: sortPathDelegate,
sortPathsByModifiedDate: sortPathsByModifiedDate,
filterOptions: filterOptions,
initializeDelayDuration: initializeDelayDuration,
);
final InstaAssetPickerBuilder builder = InstaAssetPickerBuilder(
initialPermission: ps,
provider: provider,
keepScrollOffset: false,
onCompleted: onCompleted,
config: pickerConfig,
locale: Localizations.maybeLocaleOf(context),
);
return AssetPicker.pickAssetsWithDelegate(
context,
delegate: builder,
permissionRequestOption: PermissionRequestOption(
androidPermission: AndroidPermission(
type: requestType,
mediaLocation: false,
),
),
useRootNavigator: useRootNavigator,
pageRouteBuilder: pageRouteBuilder,
);
}