pickAssets static method

Future<List<AssetEntity>?> pickAssets(
  1. BuildContext context, {
  2. Key? key,
  3. bool useRootNavigator = true,
  4. AssetPickerPageRouteBuilder<List<AssetEntity>>? pageRouteBuilder,
  5. dynamic onPermissionDenied(
    1. BuildContext context,
    2. String delegateDescription
    )?,
  6. required dynamic onCompleted(
    1. Stream<InstaAssetsExportDetails> exportDetails
    ),
  7. InstaAssetPickerConfig pickerConfig = const InstaAssetPickerConfig(),
  8. List<AssetEntity>? selectedAssets,
  9. int maxAssets = defaultMaxAssetsCount,
  10. int pageSize = defaultAssetsPerPage,
  11. ThumbnailSize pathThumbnailSize = defaultPathThumbnailSize,
  12. SortPathDelegate<AssetPathEntity>? sortPathDelegate = SortPathDelegate.common,
  13. bool sortPathsByModifiedDate = false,
  14. PMFilter? filterOptions,
  15. Duration initializeDelayDuration = _kInitializeDelayDuration,
  16. 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 details InstaAssetsExportDetails.

  • 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 to false.

  • 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<InstaAssetsExportDetails> 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,
    useRootNavigator: useRootNavigator,
    pageRouteBuilder: pageRouteBuilder,
  );
}