From 3d8f331e93b374bddb4d35e4ad7ce5444bda91bc Mon Sep 17 00:00:00 2001 From: yujune Date: Mon, 11 Nov 2024 10:18:34 +0800 Subject: [PATCH] Remove shouldBuildSpecialItem. --- .../customs/pickers/insta_asset_picker.dart | 3 +- .../pickers/multi_tabs_assets_picker.dart | 37 ++++------ .../asset_picker_builder_delegate.dart | 68 ++++++------------- 3 files changed, 33 insertions(+), 75 deletions(-) diff --git a/example/lib/customs/pickers/insta_asset_picker.dart b/example/lib/customs/pickers/insta_asset_picker.dart index c0ed62f3..36efc88b 100644 --- a/example/lib/customs/pickers/insta_asset_picker.dart +++ b/example/lib/customs/pickers/insta_asset_picker.dart @@ -673,8 +673,7 @@ class InstaAssetPickerBuilder extends DefaultAssetPickerBuilderDelegate { appBarPreferredSize ??= appBar(context).preferredSize; return Consumer( builder: (BuildContext context, DefaultAssetPickerProvider p, __) { - final bool shouldDisplayAssets = - p.hasAssetsToDisplay || shouldBuildSpecialItem; + final bool shouldDisplayAssets = p.hasAssetsToDisplay; _initializePreviewAsset(p, shouldDisplayAssets); return AnimatedSwitcher( diff --git a/example/lib/customs/pickers/multi_tabs_assets_picker.dart b/example/lib/customs/pickers/multi_tabs_assets_picker.dart index f60689e6..31b638c3 100644 --- a/example/lib/customs/pickers/multi_tabs_assets_picker.dart +++ b/example/lib/customs/pickers/multi_tabs_assets_picker.dart @@ -518,30 +518,19 @@ class MultiTabAssetPickerBuilder extends DefaultAssetPickerBuilderDelegate { } Widget _buildGrid(BuildContext context) { - return Consumer( - builder: (BuildContext context, DefaultAssetPickerProvider p, __) { - final bool shouldDisplayAssets = - p.hasAssetsToDisplay || shouldBuildSpecialItem; - return AnimatedSwitcher( - duration: const Duration(milliseconds: 300), - child: shouldDisplayAssets - ? Stack( - children: [ - RepaintBoundary( - child: Column( - children: [ - Expanded(child: assetsGridBuilder(context)), - bottomActionBar(context), - ], - ), - ), - pathEntityListBackdrop(context), - pathEntityListWidget(context), - ], - ) - : loadingIndicator(context), - ); - }, + return Stack( + children: [ + RepaintBoundary( + child: Column( + children: [ + Expanded(child: assetsGridBuilder(context)), + bottomActionBar(context), + ], + ), + ), + pathEntityListBackdrop(context), + pathEntityListWidget(context), + ], ); } diff --git a/lib/src/delegates/asset_picker_builder_delegate.dart b/lib/src/delegates/asset_picker_builder_delegate.dart index d123dab8..c0f440de 100644 --- a/lib/src/delegates/asset_picker_builder_delegate.dart +++ b/lib/src/delegates/asset_picker_builder_delegate.dart @@ -176,10 +176,6 @@ abstract class AssetPickerBuilderDelegate { /// 选择器是否为单选模式 bool get isSingleAssetMode; - /// Whether the delegate should build the special item. - /// 是否需要构建自定义 item - bool get shouldBuildSpecialItem => specialItems.isNotEmpty; - /// Space between assets item widget. /// 资源部件之间的间隔 double get itemSpacing => 2; @@ -1121,30 +1117,19 @@ class DefaultAssetPickerBuilderDelegate Widget androidLayout(BuildContext context) { return AssetPickerAppBarWrapper( appBar: appBar(context), - body: Consumer( - builder: (BuildContext context, DefaultAssetPickerProvider p, _) { - final bool shouldDisplayAssets = - p.hasAssetsToDisplay || shouldBuildSpecialItem; - return AnimatedSwitcher( - duration: switchingPathDuration, - child: shouldDisplayAssets - ? Stack( - children: [ - RepaintBoundary( - child: Column( - children: [ - Expanded(child: assetsGridBuilder(context)), - bottomActionBar(context), - ], - ), - ), - pathEntityListBackdrop(context), - pathEntityListWidget(context), - ], - ) - : loadingIndicator(context), - ); - }, + body: Stack( + children: [ + RepaintBoundary( + child: Column( + children: [ + Expanded(child: assetsGridBuilder(context)), + bottomActionBar(context), + ], + ), + ), + pathEntityListBackdrop(context), + pathEntityListWidget(context), + ], ), ); } @@ -1172,27 +1157,12 @@ class DefaultAssetPickerBuilderDelegate return Stack( children: [ Positioned.fill( - child: Consumer( - builder: (_, DefaultAssetPickerProvider p, __) { - final Widget child; - final bool shouldDisplayAssets = - p.hasAssetsToDisplay || shouldBuildSpecialItem; - if (shouldDisplayAssets) { - child = Stack( - children: [ - gridLayout(context), - pathEntityListBackdrop(context), - pathEntityListWidget(context), - ], - ); - } else { - child = loadingIndicator(context); - } - return AnimatedSwitcher( - duration: switchingPathDuration, - child: child, - ); - }, + child: Stack( + children: [ + gridLayout(context), + pathEntityListBackdrop(context), + pathEntityListWidget(context), + ], ), ), appBar(context),