diff --git a/example/lib/pages/camera/camera_picker.dart b/example/lib/pages/camera/camera_picker.dart index a20a6ea..09276a2 100644 --- a/example/lib/pages/camera/camera_picker.dart +++ b/example/lib/pages/camera/camera_picker.dart @@ -79,8 +79,7 @@ class _CameraPickerState extends State { context, onPressed: () => InstaAssetPicker.pickAssets( context, - builderOptions: InstaAssetPickerBuilderOptions( - context, + pickerConfig: InstaAssetPickerConfig( title: widget.description.fullLabel, pickerTheme: widget.getPickerTheme(context), actionsBuilder: ( diff --git a/example/lib/pages/camera/wechat_camera_picker.dart b/example/lib/pages/camera/wechat_camera_picker.dart index 343c5fd..7772140 100644 --- a/example/lib/pages/camera/wechat_camera_picker.dart +++ b/example/lib/pages/camera/wechat_camera_picker.dart @@ -28,8 +28,7 @@ class WeChatCameraPicker extends StatelessWidget with InstaPickerInterface { context, onPressed: () => InstaAssetPicker.pickAssets( context, - builderOptions: InstaAssetPickerBuilderOptions( - context, + pickerConfig: InstaAssetPickerConfig( title: description.fullLabel, pickerTheme: getPickerTheme(context), actionsBuilder: ( diff --git a/example/lib/pages/restorable_picker.dart b/example/lib/pages/restorable_picker.dart index fd2a981..6ada2a0 100644 --- a/example/lib/pages/restorable_picker.dart +++ b/example/lib/pages/restorable_picker.dart @@ -36,8 +36,7 @@ class _PickerScreenState extends State { final List? result = await _instaAssetsPicker.restorableAssetsPicker( context, - builderOptions: InstaAssetPickerBuilderOptions( - context, + pickerConfig: InstaAssetPickerConfig( title: widget.description.fullLabel, closeOnComplete: true, pickerTheme: _pickerTheme, diff --git a/example/lib/widgets/insta_picker_interface.dart b/example/lib/widgets/insta_picker_interface.dart index a6c8a16..8e92e82 100644 --- a/example/lib/widgets/insta_picker_interface.dart +++ b/example/lib/widgets/insta_picker_interface.dart @@ -79,8 +79,7 @@ mixin InstaPickerInterface on Widget { void pickAssets(BuildContext context, {required int maxAssets}) => InstaAssetPicker.pickAssets( context, - builderOptions: InstaAssetPickerBuilderOptions( - context, + pickerConfig: InstaAssetPickerConfig( title: description.fullLabel, closeOnComplete: true, pickerTheme: getPickerTheme(context), diff --git a/lib/src/assets_picker.dart b/lib/src/assets_picker.dart index 1d65474..bca18c3 100644 --- a/lib/src/assets_picker.dart +++ b/lib/src/assets_picker.dart @@ -33,25 +33,54 @@ class InstaAssetCropDelegate { final List cropRatios; } -class InstaAssetPickerBuilderOptions { - InstaAssetPickerBuilderOptions( - BuildContext context, { - ThemeData? pickerTheme, - AssetPickerTextDelegate? textDelegate, - Locale? locale, +/// Configurations for the [InstaAssetPickerBuilder]. +class InstaAssetPickerConfig { + const InstaAssetPickerConfig({ + /// [DefaultAssetPickerBuilderDelegate] config + this.gridCount = _kGridCount, + this.pickerTheme, + this.specialItemPosition, + this.specialItemBuilder, + this.loadingIndicatorBuilder, + this.selectPredicate, + this.limitedPermissionOverlayPredicate, + this.themeColor, + this.textDelegate, + this.locale, + this.gridThumbnailSize = defaultAssetGridPreviewSize, + + /// [InstaAssetPickerBuilder] config + this.title, this.closeOnComplete = false, + this.actionsBuilder, + }); + + InstaAssetPickerConfig.withContext( + BuildContext context, { + /// [DefaultAssetPickerBuilderDelegate] config + + this.gridCount = _kGridCount, + this.specialItemPosition, + this.specialItemBuilder, this.loadingIndicatorBuilder, + this.selectPredicate, this.limitedPermissionOverlayPredicate, - this.specialItemBuilder, - this.specialItemPosition, + this.themeColor, + this.gridThumbnailSize = defaultAssetGridPreviewSize, + + /// [InstaAssetPickerBuilder] config + + this.title, + this.closeOnComplete = false, this.actionsBuilder, - }) : pickerTheme = pickerTheme ?? + }) : pickerTheme = InstaAssetPicker.themeData(Theme.of(context).primaryColor), - textDelegate = - textDelegate ?? InstaAssetPicker.defaultTextDelegate(context), - locale = locale ?? Localizations.maybeLocaleOf(context); + textDelegate = InstaAssetPicker.defaultTextDelegate(context), + locale = Localizations.maybeLocaleOf(context); + + /* [DefaultAssetPickerBuilderDelegate] config */ /// Specifies the number of assets in the cross axis. /// Defaults to [_kGridCount], like instagram. @@ -61,10 +90,38 @@ class InstaAssetPickerBuilderOptions { /// It is by default initialized with the `primaryColor` of the context theme. final ThemeData? pickerTheme; + /// 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]. + final SpecialItemPosition? specialItemPosition; + + /// Specifies [Widget] for the the special item. + final SpecialItemBuilder? specialItemBuilder; + + /// The loader indicator to display in the picker. + final LoadingIndicatorBuilder? loadingIndicatorBuilder; + + final AssetSelectPredicate? selectPredicate; + + /// Specifies if the limited permission overlay should be displayed. + final LimitedPermissionOverlayPredicate? limitedPermissionOverlayPredicate; + + /// Main color for the picker. + final Color? themeColor; + /// Specifies the language to apply to the picker. /// Default is the locale language from the context. final AssetPickerTextDelegate? textDelegate; + /// Identifier used to select picker language + final Locale? locale; + + /// Thumbnail size in the grid. + final ThumbnailSize gridThumbnailSize; + + /* [InstaAssetPickerBuilder] config */ + /// Specifies the text title in the picker [AppBar]. final String? title; @@ -72,27 +129,9 @@ class InstaAssetPickerBuilderOptions { /// Defaults to `false`. final bool closeOnComplete; - /// The loader indicator to display in the picker. - final LoadingIndicatorBuilder? loadingIndicatorBuilder; - - /// Specifies if the limited permission overlay should be displayed. - final LimitedPermissionOverlayPredicate? limitedPermissionOverlayPredicate; - - /// Specifies [Widget] for the the special item. - final SpecialItemBuilder? specialItemBuilder; - - /// 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]. - final SpecialItemPosition? specialItemPosition; - /// The [Widget] to display on top of the assets grid view. /// Default is unselect all assets button. final InstaPickerActionsBuilder? actionsBuilder; - - /// Identifier used to select picker language - final Locale? locale; } class InstaAssetPicker { @@ -183,7 +222,7 @@ class InstaAssetPicker { /// Set [onPermissionDenied] to manually handle the denied permission error. /// The default behavior is to open a [ScaffoldMessenger]. /// - /// Crop options + /// Crop parameters /// - Set [cropDelegate] to customize the display and export of crops. /// /// Those arguments are used by [InstaAssetPickerBuilder] @@ -195,7 +234,7 @@ class InstaAssetPicker { /// - The [onCompleted] callback is called when the assets selection is confirmed. /// It will as argument a [Stream] with exportation details [InstaAssetsExportDetails]. /// - /// - Set [builderOptions] to specifies more optional parameters for the picker. + /// - Set [pickerConfig] to specifies more optional parameters for the picker. Future?> restorableAssetsPicker( BuildContext context, { Key? key, @@ -204,24 +243,22 @@ class InstaAssetPicker { Function(BuildContext context, String delegateDescription)? onPermissionDenied, - /// Crop options + /// Crop parameters InstaAssetCropDelegate cropDelegate = const InstaAssetCropDelegate(), - /// InstaAssetPickerBuilder options + /// InstaAssetPickerBuilder parameters required DefaultAssetPickerProvider Function() provider, required Function(Stream exportDetails) onCompleted, - InstaAssetPickerBuilderOptions? builderOptions, + InstaAssetPickerConfig pickerConfig = const InstaAssetPickerConfig(), }) async { - builderOptions ??= InstaAssetPickerBuilderOptions(context); - PermissionState? ps; try { ps = await _permissionCheck(); } catch (e) { _openErrorPermission( context, - builderOptions.textDelegate, + pickerConfig.textDelegate, onPermissionDenied, ); return []; @@ -238,7 +275,7 @@ class InstaAssetPicker { keepScrollOffset: true, cropDelegate: cropDelegate, onCompleted: onCompleted, - options: builderOptions, + config: pickerConfig, ); return AssetPicker.pickAssetsWithDelegate( @@ -268,7 +305,7 @@ class InstaAssetPicker { /// - The [onCompleted] callback is called when the assets selection is confirmed. /// It will as argument a [Stream] with exportation details [InstaAssetsExportDetails]. /// - /// - Set [builderOptions] to specifies more optional parameters for the picker. + /// - Set [pickerConfig] to specifies more optional parameters for the picker. /// /// Those arguments are used by [DefaultAssetPickerProvider] /// @@ -303,15 +340,15 @@ class InstaAssetPicker { Function(BuildContext context, String delegateDescription)? onPermissionDenied, - /// Crop options + /// Crop parameters InstaAssetCropDelegate cropDelegate = const InstaAssetCropDelegate(), - /// InstaAssetPickerBuilder options + /// InstaAssetPickerBuilder parameters required Function(Stream exportDetails) onCompleted, - InstaAssetPickerBuilderOptions? builderOptions, + InstaAssetPickerConfig pickerConfig = const InstaAssetPickerConfig(), - /// DefaultAssetPickerProvider options + /// DefaultAssetPickerProvider parameters List? selectedAssets, int maxAssets = defaultMaxAssetsCount, int pageSize = defaultAssetsPerPage, @@ -322,8 +359,6 @@ class InstaAssetPicker { PMFilter? filterOptions, Duration initializeDelayDuration = _kInitializeDelayDuration, }) async { - builderOptions ??= InstaAssetPickerBuilderOptions(context); - // must be called before initializing any picker provider to avoid `PlatformException(PERMISSION_REQUESTING)` type exception PermissionState? ps; try { @@ -331,7 +366,7 @@ class InstaAssetPicker { } catch (e) { _openErrorPermission( context, - builderOptions.textDelegate, + pickerConfig.textDelegate, onPermissionDenied, ); return []; @@ -355,7 +390,7 @@ class InstaAssetPicker { keepScrollOffset: false, cropDelegate: cropDelegate, onCompleted: onCompleted, - options: builderOptions, + config: pickerConfig, ); return AssetPicker.pickAssetsWithDelegate( diff --git a/lib/src/widget/insta_asset_picker_delegate.dart b/lib/src/widget/insta_asset_picker_delegate.dart index 7751f7b..0c2e2ad 100644 --- a/lib/src/widget/insta_asset_picker_delegate.dart +++ b/lib/src/widget/insta_asset_picker_delegate.dart @@ -37,25 +37,28 @@ class InstaAssetPickerBuilder extends DefaultAssetPickerBuilderDelegate { required super.initialPermission, required super.provider, required this.onCompleted, - required InstaAssetPickerBuilderOptions options, + required InstaAssetPickerConfig config, InstaAssetCropDelegate cropDelegate = const InstaAssetCropDelegate(), super.keepScrollOffset, }) : _cropController = InstaAssetsCropController(keepScrollOffset, cropDelegate), - title = options.title, - closeOnComplete = options.closeOnComplete, - actionsBuilder = options.actionsBuilder, + title = config.title, + closeOnComplete = config.closeOnComplete, + actionsBuilder = config.actionsBuilder, super( - gridCount: options.gridCount, - pickerTheme: options.pickerTheme, - textDelegate: options.textDelegate, - loadingIndicatorBuilder: options.loadingIndicatorBuilder, - limitedPermissionOverlayPredicate: - options.limitedPermissionOverlayPredicate, - specialItemBuilder: options.specialItemBuilder, + gridCount: config.gridCount, + pickerTheme: config.pickerTheme, specialItemPosition: - options.specialItemPosition ?? SpecialItemPosition.none, - locale: options.locale, + config.specialItemPosition ?? SpecialItemPosition.none, + specialItemBuilder: config.specialItemBuilder, + loadingIndicatorBuilder: config.loadingIndicatorBuilder, + selectPredicate: config.selectPredicate, + limitedPermissionOverlayPredicate: + config.limitedPermissionOverlayPredicate, + themeColor: config.themeColor, + textDelegate: config.textDelegate, + locale: config.locale, + gridThumbnailSize: config.gridThumbnailSize, shouldRevertGrid: false, );