From 5fc17c4e93f6171cb866e4ab14b3d20c2dc2abf5 Mon Sep 17 00:00:00 2001 From: bqubique Date: Sat, 11 May 2024 19:05:44 +0300 Subject: [PATCH 1/2] Add support for custom barriers on ModalSheet --- package/lib/src/modal/cupertino.dart | 12 +++++++ package/lib/src/modal/modal_sheet.dart | 43 ++++++++++++++++++-------- 2 files changed, 42 insertions(+), 13 deletions(-) diff --git a/package/lib/src/modal/cupertino.dart b/package/lib/src/modal/cupertino.dart index f78560dc..fcaf9468 100644 --- a/package/lib/src/modal/cupertino.dart +++ b/package/lib/src/modal/cupertino.dart @@ -416,6 +416,7 @@ class CupertinoModalSheetPage extends Page { this.transitionDuration = _cupertinoTransitionDuration, this.transitionCurve = _cupertinoTransitionCurve, required this.child, + this.barrier, }); /// The content to be shown in the [Route] created by this page. @@ -436,6 +437,8 @@ class CupertinoModalSheetPage extends Page { final Curve transitionCurve; + final Widget? barrier; + @override Route createRoute(BuildContext context) { return _PageBasedCupertinoModalSheetRoute( @@ -478,6 +481,9 @@ class _PageBasedCupertinoModalSheetRoute @override Widget buildContent(BuildContext context) => _page.child; + + @override + Widget? get barrierWidget => _page.barrier; } class CupertinoModalSheetRoute extends _BaseCupertinoModalSheetRoute { @@ -491,10 +497,13 @@ class CupertinoModalSheetRoute extends _BaseCupertinoModalSheetRoute { this.barrierColor = _cupertinoBarrierColor, this.transitionDuration = _cupertinoTransitionDuration, this.transitionCurve = _cupertinoTransitionCurve, + this.barrier, }); final WidgetBuilder builder; + final Widget? barrier; + @override final Color? barrierColor; @@ -517,4 +526,7 @@ class CupertinoModalSheetRoute extends _BaseCupertinoModalSheetRoute { Widget buildContent(BuildContext context) { return builder(context); } + + @override + Widget? get barrierWidget => barrier; } diff --git a/package/lib/src/modal/modal_sheet.dart b/package/lib/src/modal/modal_sheet.dart index 16758098..b6599e3e 100644 --- a/package/lib/src/modal/modal_sheet.dart +++ b/package/lib/src/modal/modal_sheet.dart @@ -26,6 +26,7 @@ class ModalSheetPage extends Page { this.barrierColor = Colors.black54, this.transitionDuration = const Duration(milliseconds: 300), this.transitionCurve = Curves.fastEaseInToSlowEaseOut, + this.barrier, required this.child, }); @@ -47,6 +48,8 @@ class ModalSheetPage extends Page { final Curve transitionCurve; + final Widget? barrier; + @override Route createRoute(BuildContext context) { return _PageBasedModalSheetRoute( @@ -88,6 +91,9 @@ class _PageBasedModalSheetRoute extends PageRoute @override Widget buildContent(BuildContext context) => _page.child; + + @override + Widget? get barrierWidget => _page.barrier; } class ModalSheetRoute extends PageRoute with ModalSheetRouteMixin { @@ -98,13 +104,16 @@ class ModalSheetRoute extends PageRoute with ModalSheetRouteMixin { this.maintainState = true, this.barrierDismissible = true, this.barrierLabel, - this.barrierColor = Colors.black54, + this.barrierColor = Colors.black, this.transitionDuration = const Duration(milliseconds: 300), this.transitionCurve = Curves.fastEaseInToSlowEaseOut, + this.barrier, }); final WidgetBuilder builder; + final Widget? barrier; + @override final Color? barrierColor; @@ -127,6 +136,9 @@ class ModalSheetRoute extends PageRoute with ModalSheetRouteMixin { Widget buildContent(BuildContext context) { return builder(context); } + + @override + Widget? get barrierWidget => barrier; } mixin ModalSheetRouteMixin on ModalRoute { @@ -155,6 +167,8 @@ mixin ModalSheetRouteMixin on ModalRoute { Widget buildContent(BuildContext context); + Widget? get barrierWidget; + @override Widget buildPage( BuildContext context, @@ -199,18 +213,21 @@ mixin ModalSheetRouteMixin on ModalRoute { final barrierColor = this.barrierColor; if (barrierColor != null && barrierColor.alpha != 0 && !offstage) { assert(barrierColor != barrierColor.withOpacity(0.0)); - return AnimatedModalBarrier( - onDismiss: onDismiss, - dismissible: barrierDismissible, - semanticsLabel: barrierLabel, - barrierSemanticsDismissible: semanticsDismissible, - color: animation!.drive( - ColorTween( - begin: barrierColor.withOpacity(0.0), - end: barrierColor, - ).chain(CurveTween(curve: barrierCurve)), - ), - ); + + return barrierWidget != null + ? GestureDetector(onTap: onDismiss, child: barrierWidget) + : AnimatedModalBarrier( + onDismiss: onDismiss, + dismissible: barrierDismissible, + semanticsLabel: barrierLabel, + barrierSemanticsDismissible: semanticsDismissible, + color: animation!.drive( + ColorTween( + begin: barrierColor.withOpacity(0.0), + end: barrierColor, + ).chain(CurveTween(curve: barrierCurve)), + ), + ); } else { return ModalBarrier( onDismiss: onDismiss, From 37f9b2cb176dc09052f74b66cdc52776b4d6cbe1 Mon Sep 17 00:00:00 2001 From: bqubique Date: Sun, 12 May 2024 21:56:20 +0300 Subject: [PATCH 2/2] Undo barrier black color instead of black54 --- package/lib/src/modal/modal_sheet.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package/lib/src/modal/modal_sheet.dart b/package/lib/src/modal/modal_sheet.dart index b6599e3e..8468e587 100644 --- a/package/lib/src/modal/modal_sheet.dart +++ b/package/lib/src/modal/modal_sheet.dart @@ -104,7 +104,7 @@ class ModalSheetRoute extends PageRoute with ModalSheetRouteMixin { this.maintainState = true, this.barrierDismissible = true, this.barrierLabel, - this.barrierColor = Colors.black, + this.barrierColor = Colors.black54, this.transitionDuration = const Duration(milliseconds: 300), this.transitionCurve = Curves.fastEaseInToSlowEaseOut, this.barrier,