-
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
Fix modalDecorator Context Wrapping in WoltModalSheet #340
Conversation
It appears that this PR does not include any tests. It is recommended to add tests, especially for critical changes, to ensure code quality and prevent regressions. However, if this PR is only updating samples or documentation, feel free to skip adding tests and disregard this comment. |
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.
LGTM just added one comment
@@ -332,8 +331,17 @@ class WoltModalSheetState extends State<WoltModalSheet> { | |||
Widget modalContent = ValueListenableBuilder( | |||
valueListenable: widget.pageIndexNotifier, | |||
builder: (context, currentPageIndex, __) { | |||
if (_pages.isEmpty) { |
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.
maybe we can wrap to try-catch for prevent the app from crashing if there’s an issue with pageListBuilderNotifier
if (_pages.isEmpty) { | |
if (_pages.isEmpty) { | |
try { | |
final initialPages = widget.pageListBuilderNotifier.value(context); | |
assert( | |
initialPages.isNotEmpty, | |
'pageListBuilder must return a non-empty list.', | |
); | |
_pages = initialPages; | |
} catch (e) { | |
debugPrint("Error initializing pages: $e"); | |
} | |
} |
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.
Thanks for the input. I would like to keep it the current way because it should throw exception if the initial list is empty. We also provide assert which works in debug mode for feedback to devs.
It appears that this PR does not include any tests. It is recommended to add tests, especially for critical changes, to ensure code quality and prevent regressions. However, if this PR is only updating samples or documentation, feel free to skip adding tests and disregard this comment. |
Description
The
modalDecorator
inWoltModalSheet
was not correctly wrapping the modal content, causing inherited widgets or providers added via modalDecorator to be inaccessible withinpageListBuilder
. This resulted in exceptions likeProviderNotFoundException
when attempting to access context-dependent widgets inside pageListBuilder.Related Issues
Wolt internal problem.
Solution
The fix involves adjusting the build process in WoltModalSheet to ensure that the
modalDecorator
is applied beforepageListBuilder
is called. This way, thecontext
used withinpageListBuilder
includes the inherited widgets or providers added by modalDecorator.Changes Made
modalDecorator
is provided.modalDecorator
using aBuilder
widget to create a newBuildContext
that includes the decorations._buildModalContent
method, which now uses the decorated context._buildModalContent
to ensure it has access to the decorated context.Example usage after fix
How to test?
Show Modal Sheet
is pressed.Impact
modalDecorator
to wrap the entire modal, including thebarrier
andcontent
, with widgets that provide inherited context.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.
///
).melos run analyze
) does not report any problems on my PR.Breaking Change
Does your PR require plugin users to manually update their apps to accommodate your change?