Skip to content

Commit 97a953a

Browse files
committed
♻️ Refactored bottom height getter
1 parent e871ec4 commit 97a953a

File tree

2 files changed

+34
-25
lines changed

2 files changed

+34
-25
lines changed

example/lib/customs/pickers/directory_file_asset_picker.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ class FileAssetPickerBuilder
629629
SliverToBoxAdapter(
630630
child: SizedBox(
631631
height: MediaQuery.of(context).padding.bottom +
632-
bottomActionBarHeight,
632+
bottomSectionHeight,
633633
),
634634
),
635635
if (isAppleOS)

lib/src/delegates/asset_picker_builder_delegate.dart

Lines changed: 33 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,19 @@ abstract class AssetPickerBuilderDelegate<A, P> {
128128
/// 苹果系列系统布局方式下的模糊度
129129
double get appleOSBlurRadius => 10.0;
130130

131+
/// Height for the bottom occupied section.
132+
/// 底部区域占用的高度
133+
double get bottomSectionHeight =>
134+
bottomActionBarHeight + permissionLimitedBarHeight;
135+
131136
/// Height for bottom action bar.
132137
/// 底部操作栏的高度
133138
double get bottomActionBarHeight => kToolbarHeight / 1.1;
134139

140+
/// Height for the permission limited bar.
141+
/// 权限受限栏的高度
142+
double get permissionLimitedBarHeight => isPermissionLimited ? 75 : 0;
143+
135144
/// Notifier for the current [PermissionState].
136145
/// 当前 [PermissionState] 的监听
137146
late final ValueNotifier<PermissionState> permission =
@@ -344,7 +353,8 @@ abstract class AssetPickerBuilderDelegate<A, P> {
344353
return GestureDetector(
345354
onTap: PhotoManager.openSetting,
346355
child: Container(
347-
padding: const EdgeInsets.symmetric(horizontal: 10, vertical: 15),
356+
padding: const EdgeInsets.symmetric(horizontal: 10),
357+
height: permissionLimitedBarHeight,
348358
color: theme.primaryColor.withOpacity(isAppleOS ? 0.90 : 1.0),
349359
child: Row(
350360
children: <Widget>[
@@ -376,10 +386,8 @@ abstract class AssetPickerBuilderDelegate<A, P> {
376386
/// 底部操作栏部件
377387
Widget bottomActionBar(BuildContext context) {
378388
Widget child = Container(
379-
height: bottomActionBarHeight + Screens.bottomSafeHeight,
380-
padding: EdgeInsetsDirectional.only(
381-
start: 20.0,
382-
end: 20.0,
389+
height: bottomActionBarHeight + context.bottomPadding,
390+
padding: const EdgeInsets.symmetric(horizontal: 20).copyWith(
383391
bottom: Screens.bottomSafeHeight,
384392
),
385393
color: theme.primaryColor.withOpacity(isAppleOS ? 0.90 : 1.0),
@@ -389,23 +397,21 @@ abstract class AssetPickerBuilderDelegate<A, P> {
389397
if (isAppleOS) confirmButton(context),
390398
]),
391399
);
392-
if (isAppleOS) {
393-
if (isPermissionLimited) {
394-
child = Column(
395-
mainAxisSize: MainAxisSize.min,
396-
children: <Widget>[accessLimitedBottomTip(context), child],
397-
);
398-
}
399-
child = ClipRect(
400-
child: BackdropFilter(
401-
filter: ui.ImageFilter.blur(
402-
sigmaX: appleOSBlurRadius,
403-
sigmaY: appleOSBlurRadius,
404-
),
405-
child: child,
406-
),
400+
if (isPermissionLimited) {
401+
child = Column(
402+
mainAxisSize: MainAxisSize.min,
403+
children: <Widget>[accessLimitedBottomTip(context), child],
407404
);
408405
}
406+
child = ClipRect(
407+
child: BackdropFilter(
408+
filter: ui.ImageFilter.blur(
409+
sigmaX: appleOSBlurRadius,
410+
sigmaY: appleOSBlurRadius,
411+
),
412+
child: child,
413+
),
414+
);
409415
return child;
410416
}
411417

@@ -826,14 +832,17 @@ class DefaultAssetPickerBuilderDelegate
826832

827833
return LayoutBuilder(
828834
builder: (BuildContext c, BoxConstraints constraints) {
829-
final double _itemSize = constraints.maxWidth / gridCount;
835+
final double itemSize = constraints.maxWidth / gridCount;
836+
// Reduce [permissionLimitedBarHeight] for the final height.
837+
final double height =
838+
constraints.maxHeight - permissionLimitedBarHeight;
830839
// Use [ScrollView.anchor] to determine where is the first place of
831840
// the [SliverGrid]. Each row needs [dividedSpacing] to calculate,
832841
// then minus one times of [itemSpacing] because spacing's count in the
833842
// cross axis is always less than the rows.
834843
final double anchor = math.min(
835-
(row * (_itemSize + dividedSpacing) + topPadding - itemSpacing) /
836-
constraints.maxHeight,
844+
(row * (itemSize + dividedSpacing) + topPadding - itemSpacing) /
845+
height,
837846
1,
838847
);
839848

@@ -858,7 +867,7 @@ class DefaultAssetPickerBuilderDelegate
858867
// Ignore the gap when the [anchor] is not equal to 1.
859868
if (isAppleOS && anchor == 1)
860869
SliverGap.v(
861-
context.mediaQuery.padding.bottom + bottomActionBarHeight,
870+
context.mediaQuery.padding.bottom + bottomSectionHeight,
862871
),
863872
if (isAppleOS)
864873
SliverToBoxAdapter(

0 commit comments

Comments
 (0)