restorableAssetsPicker method
- BuildContext context, {
- Key? key,
- AssetPickerPageRouteBuilder<
List< ? pageRouteBuilder,AssetEntity> > - dynamic onPermissionDenied(
- BuildContext context,
- String delegateDescription
- required DefaultAssetPickerProvider provider(),
- required dynamic onCompleted(
- Stream<
InstaExportDetails> exportDetails
- Stream<
- 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 detailsInstaAssetsExportDetails
. -
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,
);
}