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

Refactor updateCurrentPage method and introduce easy page update #213

Merged
merged 4 commits into from
May 28, 2024

Conversation

ulusoyca
Copy link
Collaborator

@ulusoyca ulusoyca commented May 27, 2024

Description

This PR introduces significant refactoring to the updateCurrentPage method. The aim is to enhance flexibility and enable more dynamic updates to the properties of the currently visible page without the need for decorator field and wrapping the components with Builder or ValueListenableBuilder widgets.

Previously, the method directly replaced the current page's properties by accepting a new SliverWoltModalSheetPage instance. The refactor changes this approach by instead accepting a function (updateFunction) that applies updates to the current page using copyWith method.

Example

A new case to the playground app is added: Page with updateCurrentPage method.

Screen recording:

update_page_rec.mov

_ConfigSwitch(
  label: 'Is top bar layer visible',
  initialConfigValue: hasTopBarLayer,
  updatePageCallback: ({required bool newValue}) {
    WoltModalSheet.of(context).updateCurrentPage((currentPage) {
      return currentPage.copyWithChild(
        isTopBarLayerAlwaysVisible: newValue,
        hasTopBarLayer: newValue,
        topBarTitle: newValue ? const ModalSheetTopBarTitle('Update page') : const SizedBox.shrink(),
        leadingNavBarWidget: newValue ? const WoltModalSheetBackButton() : const SizedBox.shrink(),
        trailingNavBarWidget: newValue ? const WoltModalSheetCloseButton() : const SizedBox.shrink(),
        child: const Placeholder(fallbackHeight: 1200, color: Colors.pink),
      );
    });
  },
),
_ConfigSwitch(
  label: 'Enable Drag for Bottom Sheet',
  initialConfigValue: enableDrag,
  updatePageCallback: ({required bool newValue}) {
    WoltModalSheet.of(context).updateCurrentPage((currentPage) {
      return currentPage.copyWith(
          enableDrag: newValue,
          mainContentSliversBuilder: (context) {
            return [
              SliverToBoxAdapter(
                child: Placeholder(
                  fallbackHeight: MediaQuery.sizeOf(context).height / 2,
                  color: Colors.green,
                ),
              ),
            ];
          });
    });
  },
),

Related Issues

Replace this paragraph with a list of issues related to this PR from the issue database. Indicate, which of these issues are resolved or fixed by this PR.

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]).
This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • My PR includes tests for all changed/updated/fixed behaviors.
  • All existing and new tests are passing.
  • I updated/added relevant documentation (doc comments with ///).
  • The analyzer (melos run analyze) does not report any problems on my PR.
  • The package compiles with the minimum Flutter version stated in the pubspec.yaml

Breaking Change

Does your PR require plugin users to manually update their apps to accommodate your change?

  • Yes, this is a breaking change.
  • No, this is not a breaking change.

* Update `wolt_modal_sheet_test.dart` tests

* format

* Update tests
@ulusoyca ulusoyca mentioned this pull request May 27, 2024
Copy link

github-actions bot commented May 27, 2024

Visit the preview URL for this PR (updated for commit 34572b0):

(expires Tue, 04 Jun 2024 12:29:07 GMT)

🔥 via Firebase Hosting GitHub Action 🌎

Sign: 906758393beb0353b979d020649d6a1efc40fb5b

@ulusoyca ulusoyca requested review from TahaTesser and AcarFurkan May 27, 2024 22:08
Copy link
Collaborator

@TahaTesser TahaTesser left a comment

Choose a reason for hiding this comment

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

LGTM! (Please execute dart format . in the root directory to fix format check)

@AcarFurkan AcarFurkan merged commit 6433ead into main May 28, 2024
4 checks passed
@AcarFurkan AcarFurkan deleted the refactor-update-current-page-method branch May 28, 2024 12:28
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.

4 participants