Skip to content

Commit

Permalink
add static method to determine the current modal tyoe
Browse files Browse the repository at this point in the history
  • Loading branch information
ulusoyca committed Jun 29, 2024
1 parent 7ae8718 commit a409b91
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
17 changes: 17 additions & 0 deletions lib/src/modal_type/wolt_modal_type.dart
Original file line number Diff line number Diff line change
@@ -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';
Expand Down Expand Up @@ -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<WoltModalSheetThemeData>()
?.modalTypeBuilder ??
WoltModalSheetDefaultThemeData(context).modalTypeBuilder;
return builder(context);
}
}
13 changes: 3 additions & 10 deletions lib/src/wolt_modal_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -322,7 +322,9 @@ class WoltModalSheetState extends State<WoltModalSheet> {
Widget build(BuildContext context) {
final themeData = Theme.of(context).extension<WoltModalSheetThemeData>();
final defaultThemeData = WoltModalSheetDefaultThemeData(context);
final modalType = _currentModalType();
final modalType =
WoltModalType.currentModalType(widget.modalTypeBuilder, context);

return ValueListenableBuilder(
valueListenable: widget.pageIndexNotifier,
builder: (context, currentPageIndex, __) {
Expand Down Expand Up @@ -503,15 +505,6 @@ class WoltModalSheetState extends State<WoltModalSheet> {
}
}

WoltModalType _currentModalType() {
final builder = widget.modalTypeBuilder ??
Theme.of(context)
.extension<WoltModalSheetThemeData>()
?.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
Expand Down
8 changes: 1 addition & 7 deletions lib/src/wolt_modal_sheet_route.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,6 @@ class WoltModalSheetRoute<T> extends PageRoute<T> {
Widget child,
) {
final modalType = _determineCurrentModalType(context);
print('modalType: $modalType');
return modalType.buildTransitions(
context, animation, secondaryAnimation, child);
}
Expand Down Expand Up @@ -146,11 +145,6 @@ class WoltModalSheetRoute<T> extends PageRoute<T> {
}

WoltModalType _determineCurrentModalType(BuildContext context) {
final builder = _modalTypeBuilder ??
Theme.of(context)
.extension<WoltModalSheetThemeData>()
?.modalTypeBuilder ??
WoltModalSheetDefaultThemeData(context).modalTypeBuilder;
return builder(context);
return WoltModalType.currentModalType(_modalTypeBuilder, context);
}
}

0 comments on commit a409b91

Please sign in to comment.