Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Support Multiple Special Items #635

Open
wants to merge 18 commits into
base: main
Choose a base branch
from

Conversation

yujune
Copy link
Contributor

@yujune yujune commented Sep 27, 2024

✨ What's the context?

Current AssetPickerConfig only accept single specialItemPosition and specialItemBuilder which is is not suitable for cases where multiple special items is required.

🛠 Changes being made

  • Added specialItems in AssetPickerConfig and which accept list of specialItemPosition and specialItemBuilder.
  • Added isPermissionLimited param to SpecialItemBuilder typedef for case where special item is required to remove when isPermissionLimited is false. Example as below.
SpecialItem(
                itemPosition: SpecialItemPosition.append,
                itemBuilder: (
                  BuildContext context,
                  AssetPathEntity? path,
                  int length,
                  bool isPermissionLimited,
                ) {
                  if (!isPermissionLimited) {
                    return null;
                  }
                  return const Center(
                    child: Text('Append Widget', textAlign: TextAlign.center),
                  );
                },
              ),
  • Removed unused SpecialPosition.none enum.

✨ Result

example/lib/l10n/app_zh.arb Outdated Show resolved Hide resolved
lib/src/constants/config.dart Outdated Show resolved Hide resolved
lib/src/constants/typedefs.dart Outdated Show resolved Hide resolved
lib/src/delegates/asset_picker_builder_delegate.dart Outdated Show resolved Hide resolved
lib/src/delegates/asset_picker_builder_delegate.dart Outdated Show resolved Hide resolved
lib/src/delegates/asset_picker_builder_delegate.dart Outdated Show resolved Hide resolved
lib/src/models/special_item.dart Outdated Show resolved Hide resolved
lib/wechat_assets_picker.dart Show resolved Hide resolved
Copy link
Member

@AlexV525 AlexV525 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this idea, would be better if we go further to support dynamic grid positions. 😆

lib/src/constants/typedefs.dart Outdated Show resolved Hide resolved
lib/src/delegates/asset_picker_builder_delegate.dart Outdated Show resolved Hide resolved
lib/src/delegates/asset_picker_builder_delegate.dart Outdated Show resolved Hide resolved
lib/src/delegates/asset_picker_builder_delegate.dart Outdated Show resolved Hide resolved
lib/src/delegates/asset_picker_builder_delegate.dart Outdated Show resolved Hide resolved
lib/src/delegates/asset_picker_builder_delegate.dart Outdated Show resolved Hide resolved
lib/src/delegates/asset_picker_builder_delegate.dart Outdated Show resolved Hide resolved
@yujune yujune requested a review from AlexV525 October 16, 2024 08:48
@yujune yujune requested a review from AlexV525 October 16, 2024 12:59
bool get shouldBuildSpecialItem =>
specialItemPosition != SpecialItemPosition.none &&
specialItemBuilder != null;
bool get shouldBuildSpecialItem => specialItems.isNotEmpty;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The semantics of this field is broken since it no longer respects the builder.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

any suggestion for this?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can get rid of it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If shouldBuildSpecialItem is removed, then it will always show loading indicator even there are special item to be displayed. Below is the current code which depends on shouldBuildSpecialItem.

 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),

lib/src/delegates/asset_picker_builder_delegate.dart Outdated Show resolved Hide resolved
lib/src/delegates/asset_picker_builder_delegate.dart Outdated Show resolved Hide resolved
bool get shouldBuildSpecialItem =>
specialItemPosition != SpecialItemPosition.none &&
specialItemBuilder != null;
bool get shouldBuildSpecialItem => specialItems.isNotEmpty;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe we can get rid of it.

lib/src/delegates/asset_picker_builder_delegate.dart Outdated Show resolved Hide resolved
lib/src/delegates/asset_picker_builder_delegate.dart Outdated Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants