diff --git a/lib/src/modal_type/wolt_alert_dialog_type.dart b/lib/src/modal_type/wolt_alert_dialog_type.dart index f9efe80e..33ac8857 100644 --- a/lib/src/modal_type/wolt_alert_dialog_type.dart +++ b/lib/src/modal_type/wolt_alert_dialog_type.dart @@ -9,7 +9,7 @@ class WoltAlertDialogType extends WoltDialogType { @override BoxConstraints layoutModal(Size availableSize) { - late double width; + double width; final availableWidth = availableSize.width; final screenType = WoltBreakpoints.getScreenTypeForWidth(availableWidth); diff --git a/lib/src/modal_type/wolt_dialog_type.dart b/lib/src/modal_type/wolt_dialog_type.dart index 70b37979..0a7b8c62 100644 --- a/lib/src/modal_type/wolt_dialog_type.dart +++ b/lib/src/modal_type/wolt_dialog_type.dart @@ -57,7 +57,7 @@ class WoltDialogType extends WoltModalType { final double availableWidth = availableSize.width; final double availableHeight = availableSize.height; - late double width; + double width; if (availableWidth > horizontalBreakpoint) { width = minModalWidth; diff --git a/lib/src/wolt_modal_sheet.dart b/lib/src/wolt_modal_sheet.dart index 76e0c890..25d68dba 100644 --- a/lib/src/wolt_modal_sheet.dart +++ b/lib/src/wolt_modal_sheet.dart @@ -311,19 +311,18 @@ class WoltModalSheetState extends State { } @override - void didChangeDependencies() { - super.didChangeDependencies(); - if (_pages.isEmpty) { - // Get the initial page list from the initially provided pageListBuilder. - final initialPages = widget.pageListBuilderNotifier.value(context); - assert(initialPages.isNotEmpty, - 'pageListBuilder must return a non-empty list.'); - _pages = initialPages; + Widget build(BuildContext context) { + final modalDecorator = widget.modalDecorator; + if (modalDecorator != null) { + return modalDecorator(Builder(builder: (decoratedContext) { + return _buildModalContent(decoratedContext); + })); } + + return _buildModalContent(context); } - @override - Widget build(BuildContext context) { + Widget _buildModalContent(BuildContext context) { final themeData = Theme.of(context).extension(); final defaultThemeData = WoltModalSheetDefaultThemeData(context); final modalType = @@ -332,8 +331,17 @@ class WoltModalSheetState extends State { Widget modalContent = ValueListenableBuilder( valueListenable: widget.pageIndexNotifier, builder: (context, currentPageIndex, __) { + if (_pages.isEmpty) { + final initialPages = widget.pageListBuilderNotifier.value(context); + assert( + initialPages.isNotEmpty, + 'pageListBuilder must return a non-empty list.', + ); + _pages = initialPages; + } final pages = _pages; final page = pages[currentPageIndex]; + final enableDrag = page.enableDrag ?? widget.enableDrag ?? modalType.isDragToDismissEnabled ?? @@ -441,10 +449,6 @@ class WoltModalSheetState extends State { }, ); - if (widget.modalDecorator != null) { - modalContent = widget.modalDecorator!(modalContent); - } - return modalContent; } diff --git a/playground/lib/home/home_screen.dart b/playground/lib/home/home_screen.dart index a7113e33..720552b4 100644 --- a/playground/lib/home/home_screen.dart +++ b/playground/lib/home/home_screen.dart @@ -223,8 +223,20 @@ class _HomeScreenState extends State { Navigator.of(context).pop(); }, pageListBuilder: (BuildContext context) { + assert( + _MyModalDecorator.of(context) != null, + 'This is added to test the modalDecorator. It will throw a ' + 'runtime error if the modalDecorator is broken.', + ); + return [RootSheetPage.build(context)]; }, + modalDecorator: (child) { + return _MyModalDecorator( + data: 'Hello from _MyModalDecorator', + child: child, + ); + }, ); }, child: const Text('Show Modal Sheet'), @@ -265,6 +277,24 @@ class _HomeScreenState extends State { } } +class _MyModalDecorator extends InheritedWidget { + final String data; + + const _MyModalDecorator({ + required this.data, + required Widget child, + }) : super(child: child); + + static _MyModalDecorator? of(BuildContext context) { + return context.dependOnInheritedWidgetOfExactType<_MyModalDecorator>(); + } + + @override + bool updateShouldNotify(_MyModalDecorator oldWidget) { + return data != oldWidget.data; + } +} + enum _Responsiveness { alwaysDialog('Always dialog'), alwaysAlertDialog('Always alert dialog'),