Skip to content

Commit

Permalink
🐛 Fix bottom actions bar display conditions (#627)
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexV525 authored Sep 20, 2024
1 parent 9ac6ef8 commit f63a0e5
Show file tree
Hide file tree
Showing 4 changed files with 120 additions and 58 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ that can be found in the LICENSE file. -->
## Unreleased

*None.*
### Fixes

- Fix bottom actions bar display conditions.

## 9.2.2

Expand Down
12 changes: 5 additions & 7 deletions example/lib/customs/pickers/directory_file_asset_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -485,8 +485,7 @@ class FileAssetPickerBuilder
child: Column(
children: <Widget>[
Expanded(child: assetsGridBuilder(context)),
if (!isAppleOS(context))
bottomActionBar(context),
bottomActionBar(context),
],
),
),
Expand Down Expand Up @@ -537,11 +536,10 @@ class FileAssetPickerBuilder
Positioned.fill(
child: assetsGridBuilder(context),
),
if (!isSingleAssetMode || isAppleOS(context))
PositionedDirectional(
bottom: 0.0,
child: bottomActionBar(context),
),
PositionedDirectional(
bottom: 0.0,
child: bottomActionBar(context),
),
],
),
),
Expand Down
2 changes: 1 addition & 1 deletion example/lib/customs/pickers/multi_tabs_assets_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -531,7 +531,7 @@ class MultiTabAssetPickerBuilder extends DefaultAssetPickerBuilderDelegate {
child: Column(
children: <Widget>[
Expanded(child: assetsGridBuilder(context)),
if (isPreviewEnabled) bottomActionBar(context),
bottomActionBar(context),
],
),
),
Expand Down
160 changes: 111 additions & 49 deletions lib/src/delegates/asset_picker_builder_delegate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -538,35 +538,44 @@ abstract class AssetPickerBuilderDelegate<Asset, Path> {
/// Action bar widget aligned to bottom.
/// 底部操作栏部件
Widget bottomActionBar(BuildContext context) {
Widget child = Container(
height: bottomActionBarHeight + context.bottomPadding,
padding: const EdgeInsets.symmetric(horizontal: 20).copyWith(
bottom: context.bottomPadding,
),
color: theme.primaryColor.withOpacity(isAppleOS(context) ? 0.90 : 1),
child: Row(
children: <Widget>[
previewButton(context),
const Spacer(),
confirmButton(context),
],
final children = <Widget>[
if (isPermissionLimited) accessLimitedBottomTip(context),
Container(
height: bottomActionBarHeight + context.bottomPadding,
padding: const EdgeInsets.symmetric(horizontal: 20).copyWith(
bottom: context.bottomPadding,
),
color: theme.bottomAppBarTheme.color?.withOpacity(
theme.bottomAppBarTheme.color!.opacity *
(isAppleOS(context) ? .9 : 1),
),
child: Row(
children: <Widget>[
previewButton(context),
if (!isSingleAssetMode) const Spacer(),
if (!isSingleAssetMode) confirmButton(context),
],
),
),
];
if (children.isEmpty) {
return const SizedBox.shrink();
}
Widget child = Column(
mainAxisSize: MainAxisSize.min,
children: children,
);
if (isPermissionLimited) {
child = Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[accessLimitedBottomTip(context), child],
if (isAppleOS(context)) {
child = ClipRect(
child: BackdropFilter(
filter: ui.ImageFilter.blur(
sigmaX: appleOSBlurRadius,
sigmaY: appleOSBlurRadius,
),
child: child,
),
);
}
child = ClipRect(
child: BackdropFilter(
filter: ui.ImageFilter.blur(
sigmaX: appleOSBlurRadius,
sigmaY: appleOSBlurRadius,
),
child: child,
),
);
return child;
}

Expand Down Expand Up @@ -800,6 +809,9 @@ class DefaultAssetPickerBuilderDelegate
@override
bool get isSingleAssetMode => provider.maxAssets == 1;

/// Whether the bottom actions bar should display.
bool get hasBottomActions => isPreviewEnabled || !isSingleAssetMode;

/// The listener to track the scroll position of the [gridScrollController]
/// if [keepScrollOffset] is true.
/// 当 [keepScrollOffset] 为 true 时,跟踪 [gridScrollController] 位置的监听。
Expand Down Expand Up @@ -1086,8 +1098,7 @@ class DefaultAssetPickerBuilderDelegate
child: Column(
children: <Widget>[
Expanded(child: assetsGridBuilder(context)),
if (isPreviewEnabled || !isSingleAssetMode)
bottomActionBar(context),
bottomActionBar(context),
],
),
),
Expand All @@ -1113,8 +1124,7 @@ class DefaultAssetPickerBuilderDelegate
child: Stack(
children: <Widget>[
Positioned.fill(child: assetsGridBuilder(context)),
if (isPreviewEnabled || !isSingleAssetMode)
Positioned.fill(top: null, child: bottomActionBar(context)),
Positioned.fill(top: null, child: bottomActionBar(context)),
],
),
),
Expand Down Expand Up @@ -2296,29 +2306,81 @@ class DefaultAssetPickerBuilderDelegate
}

@override
Widget bottomActionBar(BuildContext context) {
Widget child = Container(
height: bottomActionBarHeight + context.bottomPadding,
padding: const EdgeInsets.symmetric(horizontal: 20).copyWith(
bottom: context.bottomPadding,
),
color: theme.bottomAppBarTheme.color?.withOpacity(
theme.bottomAppBarTheme.color!.opacity * (isAppleOS(context) ? .9 : 1),
),
child: Row(
children: <Widget>[
if (isPreviewEnabled) previewButton(context),
if (isPreviewEnabled || !isSingleAssetMode) const Spacer(),
if (isPreviewEnabled || !isSingleAssetMode) confirmButton(context),
],
Widget accessLimitedBottomTip(BuildContext context) {
final double bottomPadding;
if (hasBottomActions) {
bottomPadding = 0;
} else {
bottomPadding = MediaQuery.paddingOf(context).bottom;
}
return GestureDetector(
onTap: () {
Feedback.forTap(context);
PhotoManager.openSetting();
},
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 10)
.add(EdgeInsets.only(bottom: bottomPadding)),
height: permissionLimitedBarHeight + bottomPadding,
color: theme.primaryColor.withOpacity(isAppleOS(context) ? 0.90 : 1),
child: Row(
children: <Widget>[
const SizedBox(width: 5),
Icon(
Icons.warning,
color: Colors.orange[400]!.withOpacity(.8),
),
const SizedBox(width: 15),
Expanded(
child: ScaleText(
textDelegate.accessAllTip,
style: context.textTheme.bodySmall?.copyWith(
fontSize: 14,
),
semanticsLabel: semanticsTextDelegate.accessAllTip,
),
),
Icon(
Icons.keyboard_arrow_right,
color: context.iconTheme.color?.withOpacity(.5),
),
],
),
),
);
if (isPermissionLimited) {
child = Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[accessLimitedBottomTip(context), child],
);
}

@override
Widget bottomActionBar(BuildContext context) {
final children = <Widget>[
if (isPermissionLimited) accessLimitedBottomTip(context),
if (hasBottomActions)
Container(
height: bottomActionBarHeight + context.bottomPadding,
padding: const EdgeInsets.symmetric(horizontal: 20).copyWith(
bottom: context.bottomPadding,
),
color: theme.bottomAppBarTheme.color?.withOpacity(
theme.bottomAppBarTheme.color!.opacity *
(isAppleOS(context) ? .9 : 1),
),
child: Row(
children: <Widget>[
if (isPreviewEnabled) previewButton(context),
if (isPreviewEnabled || !isSingleAssetMode) const Spacer(),
if (isPreviewEnabled || !isSingleAssetMode)
confirmButton(context),
],
),
),
];
if (children.isEmpty) {
return const SizedBox.shrink();
}
Widget child = Column(
mainAxisSize: MainAxisSize.min,
children: children,
);
if (isAppleOS(context)) {
child = ClipRect(
child: BackdropFilter(
Expand Down

0 comments on commit f63a0e5

Please sign in to comment.