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. required DefaultAssetPickerProvider provider(),
  7. required dynamic onCompleted(
    1. Stream<InstaExportDetails> exportDetails
    ),
  8. InstaAssetPickerConfig pickerConfig = const InstaAssetPickerConfig(),
})

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.

Those arguments are used by InstaAssetPickerBuilder

  • Set provider getter of type DefaultAssetPickerProvider to specifies picker options. Getter needed to initialize the provider state after permission check. This argument is required.

  • The onCompleted callback is called when the assets selection is confirmed. It will as argument a Stream with exportation details InstaExportDetails.

  • Set pickerConfig to specifies more optional parameters for the picker.

Implementation

Future<List<AssetEntity>?> restorableAssetsPicker(
  BuildContext context, {
  Key? key,
  bool useRootNavigator = true,
  AssetPickerPageRouteBuilder<List<AssetEntity>>? pageRouteBuilder,
  Function(BuildContext context, String delegateDescription)?
      onPermissionDenied,

  /// InstaAssetPickerBuilder parameters
  required DefaultAssetPickerProvider Function() provider,
  required Function(Stream<InstaExportDetails> exportDetails) onCompleted,
  InstaAssetPickerConfig pickerConfig = const InstaAssetPickerConfig(),
}) async {
  PermissionState? ps;
  try {
    ps = await _permissionCheck(null);
  } catch (e) {
    _openErrorPermission(
      context,
      pickerConfig.textDelegate,
      onPermissionDenied,
    );
    return [];
  }

  /// Provider must be initialized after permission check or gallery is empty (#43)
  final restoredProvider = provider();
  _assertRequestType(restoredProvider.requestType);

  builder ??= InstaAssetPickerBuilder(
    initialPermission: ps,
    provider: restoredProvider,
    keepScrollOffset: true,
    onCompleted: onCompleted,
    config: pickerConfig,
    locale: Localizations.maybeLocaleOf(context),
  );

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