restorableAssetsPicker method

Future<List<AssetEntity>?> restorableAssetsPicker(
  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. InstaAssetCropDelegate cropDelegate = const InstaAssetCropDelegate(),
  7. int gridCount = _kGridCount,
  8. required DefaultAssetPickerProvider provider,
  9. ThemeData? pickerTheme,
  10. AssetPickerTextDelegate? textDelegate,
  11. String? title,
  12. bool closeOnComplete = false,
  13. required dynamic onCompleted(
    1. Stream<InstaAssetsExportDetails> exportDetails
    ),
  14. Widget loadingIndicatorBuilder(
    1. BuildContext context,
    2. bool isAssetsEmpty
    )?,
  15. LimitedPermissionOverlayPredicate? limitedPermissionOverlayPredicate,
  16. Widget? specialItemBuilder(
    1. BuildContext context,
    2. AssetPathEntity? path,
    3. int length
    )?,
  17. SpecialItemPosition? specialItemPosition,
  18. InstaPickerActionsBuilder? actionsBuilder,
})

When using restorableAssetsPicker function, the picker's state is preserved even after pop

⚠️ InstaAssetPicker and provider must be disposed manually

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 provider of type DefaultAssetPickerProvider to specifies picker options. This argument is required.

  • 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 the primaryColor 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.

  • Set limitedPermissionOverlayPredicate to specifies if the limited permission overlay should be displayed.

  • Set specialItemPosition to allows users to set a special item in the picker with several positions. Since the grid view is reversed, SpecialItemPosition.prepend will be at the top and SpecialItemPosition.append at the bottom. Defaults to SpecialItemPosition.none.

  • Set specialItemBuilder to specifies Widget for the the special item.

  • Set actionsBuilder function to specifies the Widgets to display on top of the assets grid view. Default is unselect all assets button.

Implementation

Future<List<AssetEntity>?> restorableAssetsPicker(
  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,
  required DefaultAssetPickerProvider provider,
  ThemeData? pickerTheme,
  AssetPickerTextDelegate? textDelegate,
  String? title,
  bool closeOnComplete = false,
  required Function(Stream<InstaAssetsExportDetails> exportDetails)
      onCompleted,
  Widget Function(BuildContext context, bool isAssetsEmpty)?
      loadingIndicatorBuilder,
  LimitedPermissionOverlayPredicate? limitedPermissionOverlayPredicate,
  Widget? Function(BuildContext context, AssetPathEntity? path, int length)?
      specialItemBuilder,
  SpecialItemPosition? specialItemPosition,
  InstaPickerActionsBuilder? actionsBuilder,
}) async {
  assert(provider.requestType == RequestType.image,
      'Only images can be shown in the picker for now');

  final text = textDelegate ?? defaultTextDelegate(context);

  PermissionState? ps;
  if (builder == null) {
    try {
      ps = await _permissionCheck();
    } catch (e) {
      _openErrorPermission(context, text, onPermissionDenied);
    }
  }

  builder ??= InstaAssetPickerBuilder(
    initialPermission: ps ?? PermissionState.denied,
    provider: provider,
    title: title,
    gridCount: gridCount,
    pickerTheme: pickerTheme ?? themeData(Theme.of(context).primaryColor),
    locale: Localizations.maybeLocaleOf(context),
    keepScrollOffset: true,
    textDelegate: text,
    loadingIndicatorBuilder: loadingIndicatorBuilder,
    limitedPermissionOverlayPredicate: limitedPermissionOverlayPredicate,
    closeOnComplete: closeOnComplete,
    cropDelegate: cropDelegate,
    onCompleted: onCompleted,
    specialItemBuilder: specialItemBuilder,
    specialItemPosition: specialItemPosition,
    actionsBuilder: actionsBuilder,
  );

  return AssetPicker.pickAssetsWithDelegate(
    context,
    delegate: builder!,
    useRootNavigator: useRootNavigator,
    pageRouteBuilder: pageRouteBuilder,
  );
}