From a409b919712304d54a5a975f1a65e42f4b5d941a Mon Sep 17 00:00:00 2001 From: Cagatay Ulusoy Date: Sat, 29 Jun 2024 17:11:36 +0200 Subject: [PATCH] add static method to determine the current modal tyoe --- lib/src/modal_type/wolt_modal_type.dart | 17 +++++++++++++++++ lib/src/wolt_modal_sheet.dart | 13 +++---------- lib/src/wolt_modal_sheet_route.dart | 8 +------- 3 files changed, 21 insertions(+), 17 deletions(-) diff --git a/lib/src/modal_type/wolt_modal_type.dart b/lib/src/modal_type/wolt_modal_type.dart index 2ca138f0..bd6bd9b2 100644 --- a/lib/src/modal_type/wolt_modal_type.dart +++ b/lib/src/modal_type/wolt_modal_type.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:wolt_modal_sheet/src/modal_type/wolt_alert_dialog_type.dart'; +import 'package:wolt_modal_sheet/src/theme/wolt_modal_sheet_default_theme_data.dart'; import 'package:wolt_modal_sheet/wolt_modal_sheet.dart'; export 'wolt_bottom_sheet_type.dart'; @@ -125,4 +126,20 @@ abstract class WoltModalType { bool useSafeArea, ) => useSafeArea ? SafeArea(child: modal) : modal; + + /// Determines the modal type based on the the presence of the modal type builder provided by + /// the [WoltModalSheet] widget, existence of the [WoltModalSheetThemeData.modalTypeBuilder]. + /// If none of these are available, the default modalTypeBuilder from the + /// [WoltModalSheetDefaultThemeData] is used. + static WoltModalType currentModalType( + WoltModalTypeBuilder? modalTypeBuilder, + BuildContext context, + ) { + final builder = modalTypeBuilder ?? + Theme.of(context) + .extension() + ?.modalTypeBuilder ?? + WoltModalSheetDefaultThemeData(context).modalTypeBuilder; + return builder(context); + } } diff --git a/lib/src/wolt_modal_sheet.dart b/lib/src/wolt_modal_sheet.dart index cce47b95..4fa2cd6a 100644 --- a/lib/src/wolt_modal_sheet.dart +++ b/lib/src/wolt_modal_sheet.dart @@ -322,7 +322,9 @@ class WoltModalSheetState extends State { Widget build(BuildContext context) { final themeData = Theme.of(context).extension(); final defaultThemeData = WoltModalSheetDefaultThemeData(context); - final modalType = _currentModalType(); + final modalType = + WoltModalType.currentModalType(widget.modalTypeBuilder, context); + return ValueListenableBuilder( valueListenable: widget.pageIndexNotifier, builder: (context, currentPageIndex, __) { @@ -503,15 +505,6 @@ class WoltModalSheetState extends State { } } - WoltModalType _currentModalType() { - final builder = widget.modalTypeBuilder ?? - Theme.of(context) - .extension() - ?.modalTypeBuilder ?? - WoltModalSheetDefaultThemeData(context).modalTypeBuilder; - return builder(context); - } - /// Adds one or more new pages to the modal sheet stack without making them the current view. /// /// This method appends one or multiple [SliverWoltModalSheetPage] to the navigation stack but does diff --git a/lib/src/wolt_modal_sheet_route.dart b/lib/src/wolt_modal_sheet_route.dart index 46868852..f56c359b 100644 --- a/lib/src/wolt_modal_sheet_route.dart +++ b/lib/src/wolt_modal_sheet_route.dart @@ -102,7 +102,6 @@ class WoltModalSheetRoute extends PageRoute { Widget child, ) { final modalType = _determineCurrentModalType(context); - print('modalType: $modalType'); return modalType.buildTransitions( context, animation, secondaryAnimation, child); } @@ -146,11 +145,6 @@ class WoltModalSheetRoute extends PageRoute { } WoltModalType _determineCurrentModalType(BuildContext context) { - final builder = _modalTypeBuilder ?? - Theme.of(context) - .extension() - ?.modalTypeBuilder ?? - WoltModalSheetDefaultThemeData(context).modalTypeBuilder; - return builder(context); + return WoltModalType.currentModalType(_modalTypeBuilder, context); } }