Skip to content

Commit

Permalink
Remove shouldBuildSpecialItem.
Browse files Browse the repository at this point in the history
  • Loading branch information
yujunetee committed Nov 11, 2024
1 parent 750dd16 commit 3d8f331
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 75 deletions.
3 changes: 1 addition & 2 deletions example/lib/customs/pickers/insta_asset_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -673,8 +673,7 @@ class InstaAssetPickerBuilder extends DefaultAssetPickerBuilderDelegate {
appBarPreferredSize ??= appBar(context).preferredSize;
return Consumer<DefaultAssetPickerProvider>(
builder: (BuildContext context, DefaultAssetPickerProvider p, __) {
final bool shouldDisplayAssets =
p.hasAssetsToDisplay || shouldBuildSpecialItem;
final bool shouldDisplayAssets = p.hasAssetsToDisplay;
_initializePreviewAsset(p, shouldDisplayAssets);

return AnimatedSwitcher(
Expand Down
37 changes: 13 additions & 24 deletions example/lib/customs/pickers/multi_tabs_assets_picker.dart
Original file line number Diff line number Diff line change
Expand Up @@ -518,30 +518,19 @@ class MultiTabAssetPickerBuilder extends DefaultAssetPickerBuilderDelegate {
}

Widget _buildGrid(BuildContext context) {
return Consumer<DefaultAssetPickerProvider>(
builder: (BuildContext context, DefaultAssetPickerProvider p, __) {
final bool shouldDisplayAssets =
p.hasAssetsToDisplay || shouldBuildSpecialItem;
return AnimatedSwitcher(
duration: const Duration(milliseconds: 300),
child: shouldDisplayAssets
? Stack(
children: <Widget>[
RepaintBoundary(
child: Column(
children: <Widget>[
Expanded(child: assetsGridBuilder(context)),
bottomActionBar(context),
],
),
),
pathEntityListBackdrop(context),
pathEntityListWidget(context),
],
)
: loadingIndicator(context),
);
},
return Stack(
children: <Widget>[
RepaintBoundary(
child: Column(
children: <Widget>[
Expanded(child: assetsGridBuilder(context)),
bottomActionBar(context),
],
),
),
pathEntityListBackdrop(context),
pathEntityListWidget(context),
],
);
}

Expand Down
68 changes: 19 additions & 49 deletions lib/src/delegates/asset_picker_builder_delegate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -176,10 +176,6 @@ abstract class AssetPickerBuilderDelegate<Asset, Path> {
/// 选择器是否为单选模式
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;
Expand Down Expand Up @@ -1121,30 +1117,19 @@ class DefaultAssetPickerBuilderDelegate
Widget androidLayout(BuildContext context) {
return AssetPickerAppBarWrapper(
appBar: appBar(context),
body: Consumer<DefaultAssetPickerProvider>(
builder: (BuildContext context, DefaultAssetPickerProvider p, _) {
final bool shouldDisplayAssets =
p.hasAssetsToDisplay || shouldBuildSpecialItem;
return AnimatedSwitcher(
duration: switchingPathDuration,
child: shouldDisplayAssets
? Stack(
children: <Widget>[
RepaintBoundary(
child: Column(
children: <Widget>[
Expanded(child: assetsGridBuilder(context)),
bottomActionBar(context),
],
),
),
pathEntityListBackdrop(context),
pathEntityListWidget(context),
],
)
: loadingIndicator(context),
);
},
body: Stack(
children: <Widget>[
RepaintBoundary(
child: Column(
children: <Widget>[
Expanded(child: assetsGridBuilder(context)),
bottomActionBar(context),
],
),
),
pathEntityListBackdrop(context),
pathEntityListWidget(context),
],
),
);
}
Expand Down Expand Up @@ -1172,27 +1157,12 @@ class DefaultAssetPickerBuilderDelegate
return Stack(
children: <Widget>[
Positioned.fill(
child: Consumer<DefaultAssetPickerProvider>(
builder: (_, DefaultAssetPickerProvider p, __) {
final Widget child;
final bool shouldDisplayAssets =
p.hasAssetsToDisplay || shouldBuildSpecialItem;
if (shouldDisplayAssets) {
child = Stack(
children: <Widget>[
gridLayout(context),
pathEntityListBackdrop(context),
pathEntityListWidget(context),
],
);
} else {
child = loadingIndicator(context);
}
return AnimatedSwitcher(
duration: switchingPathDuration,
child: child,
);
},
child: Stack(
children: <Widget>[
gridLayout(context),
pathEntityListBackdrop(context),
pathEntityListWidget(context),
],
),
),
appBar(context),
Expand Down

0 comments on commit 3d8f331

Please sign in to comment.