-
Notifications
You must be signed in to change notification settings - Fork 72
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
[Breaking Change] Refactor page navigation in page list, remove pageIndexNotifier and pageListBuilderNotifier #182
Conversation
Visit the preview URL for this PR (updated for commit d2b02bb):
(expires Fri, 26 Apr 2024 16:47:34 GMT) 🔥 via Firebase Hosting GitHub Action 🌎 Sign: 906758393beb0353b979d020649d6a1efc40fb5b |
14ee6fe
to
d2b02bb
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice work!
/// This method can be expensive (it walks the element tree). | ||
static WoltModalSheetState of(BuildContext context) { | ||
// Handles the case where the input context is a navigator element. | ||
WoltModalSheetState? wms; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't public but i suggest to use words as they're readable and searchable if needed.
WoltModalSheetState? wms; | |
WoltModalSheetState? woltModalSheetState; |
// Handles the case where the input context is a navigator element. | ||
WoltModalSheetState? wms; | ||
if (context is StatefulElement && context.state is WoltModalSheetState) { | ||
wms = context.state as WoltModalSheetState; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wms = context.state as WoltModalSheetState; | |
woltModalSheetState = context.state as WoltModalSheetState; |
if (context is StatefulElement && context.state is WoltModalSheetState) { | ||
wms = context.state as WoltModalSheetState; | ||
} | ||
wms ??= context.findAncestorStateOfType<WoltModalSheetState>(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wms ??= context.findAncestorStateOfType<WoltModalSheetState>(); | |
woltModalSheetState ??= context.findAncestorStateOfType<WoltModalSheetState>(); |
wms ??= context.findAncestorStateOfType<WoltModalSheetState>(); | ||
|
||
assert(() { | ||
if (wms == null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (wms == null) { | |
if (woltModalSheetState == null) { |
} | ||
return true; | ||
}()); | ||
return wms!; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return wms!; | |
return woltModalSheetState!; |
bool found = false; | ||
final List<SliverWoltModalSheetPage> newPages = _pages.map((p) { | ||
if (p.id == id) { | ||
found = true; | ||
return page; | ||
} | ||
return p; | ||
}).toList(); | ||
if (!found) return false; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bool found = false; | |
final List<SliverWoltModalSheetPage> newPages = _pages.map((p) { | |
if (p.id == id) { | |
found = true; | |
return page; | |
} | |
return p; | |
}).toList(); | |
if (!found) return false; | |
final List<SliverWoltModalSheetPage> newPages = _pages.where((SliverWoltModalSheetPage sheetPage) { | |
return sheetPage.id == id; | |
}).toList(); | |
if (newPages.isEmpty) { | |
return false; | |
} |
This could where and avoid using inline veriables. I haven't tested the code so please verify it works.
void pushPages(List<SliverWoltModalSheetPage> pages) { | ||
setState(() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
void pushPages(List<SliverWoltModalSheetPage> pages) { | |
setState(() { | |
void pushPages(List<SliverWoltModalSheetPage> pages) { | |
if (pages.isEmpty) { | |
return; | |
} | |
setState(() { |
if pages
is empty, avoid calling setState.
/// | ||
/// Returns: | ||
/// None. | ||
void replaceAllPages(List<SliverWoltModalSheetPage> newPages) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
void replaceAllPages(List<SliverWoltModalSheetPage> newPages) { | |
void replaceAllPages(List<SliverWoltModalSheetPage> newPages) { | |
if (newPages.isEmpty) { | |
return; | |
} |
if (pages.isNotEmpty) { | ||
_selectedPageIndex = | ||
_pages.length - pages.length; // Set to the first of the newly added pages. | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if (pages.isNotEmpty) { | |
_selectedPageIndex = | |
_pages.length - pages.length; // Set to the first of the newly added pages. | |
} | |
_selectedPageIndex = | |
_pages.length - pages.length; // Set to the first of the newly added pages. |
if we're checking pages
isn't empty above, we can feel confident page
is not empty and update this.
/// navigating to a specific page or popping a page. | ||
final Object? id; | ||
|
||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Closing this because a new PR will be opened. |
Overview
This pull request introduces breaking and major changes to the in-modal navigation system of the
WoltModalSheet
. The changes are aimed at increasing flexibility and improving the developer experience by allowing dynamic navigation updates, multiple page management, and a more intuitive interaction model for in-modal navigation.Key Changes
addPagesToStack
and its overloadaddPageToStack
: These methods facilitate the addition of one or multiple pages to the navigation stack without altering while staying at current page. This is particularly useful for preloading pages in scenarios where the user might need to interact with multiple subsequent screens.addAndReplace.mov
pushPages
and its overloadpushPage
: Extended to allow pushing a list of pages onto the navigation stack, making the first of these new pages the currently visible one. This is crucial for workflows where a sequence of new pages needs to be added and immediately accessed.push.mov
Page Replacement Enhancements:
Navigation Control Improvements:
State Management and Error Handling:
Migration Notes
Testing
Future Work
TODO
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?