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 716933c
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 17 deletions.
21 changes: 21 additions & 0 deletions lib/src/utils/wolt_modal_type_utils.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import 'package:flutter/material.dart';
import 'package:wolt_modal_sheet/src/theme/wolt_modal_sheet_default_theme_data.dart';
import 'package:wolt_modal_sheet/wolt_modal_sheet.dart';

class WoltModalTypeUtils {
/// 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);
}
}
14 changes: 4 additions & 10 deletions lib/src/wolt_modal_sheet.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
import 'package:wolt_modal_sheet/src/content/wolt_modal_sheet_animated_switcher.dart';
import 'package:wolt_modal_sheet/src/theme/wolt_modal_sheet_default_theme_data.dart';
import 'package:wolt_modal_sheet/src/utils/bottom_sheet_suspended_curve.dart';
import 'package:wolt_modal_sheet/src/utils/wolt_modal_type_utils.dart';
import 'package:wolt_modal_sheet/wolt_modal_sheet.dart';

const double _minFlingVelocity = 700.0;
Expand Down Expand Up @@ -322,7 +323,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 =
WoltModalTypeUtils.currentModalType(widget.modalTypeBuilder, context);

return ValueListenableBuilder(
valueListenable: widget.pageIndexNotifier,
builder: (context, currentPageIndex, __) {
Expand Down Expand Up @@ -503,15 +506,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
9 changes: 2 additions & 7 deletions lib/src/wolt_modal_sheet_route.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:wolt_modal_sheet/src/theme/wolt_modal_sheet_default_theme_data.dart';
import 'package:wolt_modal_sheet/wolt_modal_sheet.dart';
import 'package:wolt_modal_sheet/src/utils/wolt_modal_type_utils.dart';

class WoltModalSheetRoute<T> extends PageRoute<T> {
WoltModalSheetRoute({
Expand Down Expand Up @@ -102,7 +103,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 +146,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 WoltModalTypeUtils.currentModalType(_modalTypeBuilder, context);
}
}

0 comments on commit 716933c

Please sign in to comment.