From cfdda1504915c6d0651a7bab430c116d1bff3176 Mon Sep 17 00:00:00 2001 From: Harsh Bhikadia Date: Wed, 6 Sep 2023 15:58:01 +0530 Subject: [PATCH 1/4] feat: added `concealBacklayerOnBackButton` option --- lib/src/scaffold.dart | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/lib/src/scaffold.dart b/lib/src/scaffold.dart index 7dbe63c..e731c6a 100644 --- a/lib/src/scaffold.dart +++ b/lib/src/scaffold.dart @@ -217,6 +217,11 @@ class BackdropScaffold extends StatefulWidget { /// Defaults to `true`. final bool maintainBackLayerState; + /// Specifiy whether to conceal [backLayer] when back button pressed. + /// + /// Default to `true`. + final bool concealBacklayerOnBackButton; + // ------------- PROPERTIES TAKEN OVER FROM SCAFFOLD ------------- // /// A key to use when building the [Scaffold]. @@ -331,6 +336,7 @@ class BackdropScaffold extends StatefulWidget { this.onBackLayerConcealed, this.onBackLayerRevealed, this.maintainBackLayerState = true, + this.concealBacklayerOnBackButton = true, this.scaffoldKey, this.appBar, this.floatingActionButton, @@ -601,7 +607,7 @@ class BackdropScaffoldState extends State } Future _willPopCallback(BuildContext context) async { - if (isBackLayerRevealed) { + if (widget.concealBacklayerOnBackButton && isBackLayerRevealed) { concealBackLayer(); return false; } From f3cfc8823be866961eccb2aa5dea5cecda5b2dbb Mon Sep 17 00:00:00 2001 From: Harsh Bhikadia Date: Wed, 6 Sep 2023 16:13:12 +0530 Subject: [PATCH 2/4] not wrapping WillPopScope if opt disabled --- lib/src/scaffold.dart | 84 ++++++++++++++++++++++--------------------- 1 file changed, 44 insertions(+), 40 deletions(-) diff --git a/lib/src/scaffold.dart b/lib/src/scaffold.dart index e731c6a..f603c9f 100644 --- a/lib/src/scaffold.dart +++ b/lib/src/scaffold.dart @@ -620,48 +620,52 @@ class BackdropScaffoldState extends State ); Widget _buildBody(BuildContext context) { - return WillPopScope( - onWillPop: () => _willPopCallback(context), - child: Scaffold( - key: scaffoldKey, - appBar: widget.appBar, - body: LayoutBuilder( - builder: (context, constraints) { - return Stack( - fit: StackFit.expand, - children: [ - _buildBackPanel(), - PositionedTransition( - rect: _getPanelAnimation(context, constraints), - child: _buildFrontPanel(context), - ), - ], - ); - }, - ), - floatingActionButton: widget.floatingActionButton, - floatingActionButtonLocation: widget.floatingActionButtonLocation, - floatingActionButtonAnimator: widget.floatingActionButtonAnimator, - persistentFooterButtons: widget.persistentFooterButtons, - drawer: widget.drawer, - onDrawerChanged: widget.onDrawerChanged, - endDrawer: widget.endDrawer, - onEndDrawerChanged: widget.onEndDrawerChanged, - bottomNavigationBar: widget.bottomNavigationBar, - bottomSheet: widget.bottomSheet, - backgroundColor: widget.backgroundColor, - resizeToAvoidBottomInset: widget.resizeToAvoidBottomInset, - primary: widget.primary, - drawerDragStartBehavior: widget.drawerDragStartBehavior, - extendBody: widget.extendBody, - extendBodyBehindAppBar: widget.extendBodyBehindAppBar, - drawerScrimColor: widget.drawerScrimColor, - drawerEdgeDragWidth: widget.drawerEdgeDragWidth, - drawerEnableOpenDragGesture: widget.drawerEnableOpenDragGesture, - endDrawerEnableOpenDragGesture: widget.endDrawerEnableOpenDragGesture, - restorationId: widget.restorationId, + final bodyWidget = Scaffold( + key: scaffoldKey, + appBar: widget.appBar, + body: LayoutBuilder( + builder: (context, constraints) { + return Stack( + fit: StackFit.expand, + children: [ + _buildBackPanel(), + PositionedTransition( + rect: _getPanelAnimation(context, constraints), + child: _buildFrontPanel(context), + ), + ], + ); + }, ), + floatingActionButton: widget.floatingActionButton, + floatingActionButtonLocation: widget.floatingActionButtonLocation, + floatingActionButtonAnimator: widget.floatingActionButtonAnimator, + persistentFooterButtons: widget.persistentFooterButtons, + drawer: widget.drawer, + onDrawerChanged: widget.onDrawerChanged, + endDrawer: widget.endDrawer, + onEndDrawerChanged: widget.onEndDrawerChanged, + bottomNavigationBar: widget.bottomNavigationBar, + bottomSheet: widget.bottomSheet, + backgroundColor: widget.backgroundColor, + resizeToAvoidBottomInset: widget.resizeToAvoidBottomInset, + primary: widget.primary, + drawerDragStartBehavior: widget.drawerDragStartBehavior, + extendBody: widget.extendBody, + extendBodyBehindAppBar: widget.extendBodyBehindAppBar, + drawerScrimColor: widget.drawerScrimColor, + drawerEdgeDragWidth: widget.drawerEdgeDragWidth, + drawerEnableOpenDragGesture: widget.drawerEnableOpenDragGesture, + endDrawerEnableOpenDragGesture: widget.endDrawerEnableOpenDragGesture, + restorationId: widget.restorationId, ); + + return widget.concealBacklayerOnBackButton + ? WillPopScope( + onWillPop: () => _willPopCallback(context), + child: bodyWidget, + ) + : bodyWidget; } Container _buildBackLayerScrim() => Container( From 63d6ee2f9396e0a97efc0d704a8429f0f2e0e0cb Mon Sep 17 00:00:00 2001 From: Harsh Bhikadia Date: Wed, 6 Sep 2023 16:17:04 +0530 Subject: [PATCH 3/4] minor changes --- lib/src/scaffold.dart | 110 +++++++++++++++++++++--------------------- 1 file changed, 55 insertions(+), 55 deletions(-) diff --git a/lib/src/scaffold.dart b/lib/src/scaffold.dart index f603c9f..303129b 100644 --- a/lib/src/scaffold.dart +++ b/lib/src/scaffold.dart @@ -606,67 +606,67 @@ class BackdropScaffoldState extends State ); } - Future _willPopCallback(BuildContext context) async { - if (widget.concealBacklayerOnBackButton && isBackLayerRevealed) { - concealBackLayer(); - return false; - } - return true; - } - ColorTween _buildBackLayerScrimColorTween() => ColorTween( begin: Colors.transparent, end: widget.backLayerScrim, ); - Widget _buildBody(BuildContext context) { - final bodyWidget = Scaffold( - key: scaffoldKey, - appBar: widget.appBar, - body: LayoutBuilder( - builder: (context, constraints) { - return Stack( - fit: StackFit.expand, - children: [ - _buildBackPanel(), - PositionedTransition( - rect: _getPanelAnimation(context, constraints), - child: _buildFrontPanel(context), - ), - ], - ); - }, - ), - floatingActionButton: widget.floatingActionButton, - floatingActionButtonLocation: widget.floatingActionButtonLocation, - floatingActionButtonAnimator: widget.floatingActionButtonAnimator, - persistentFooterButtons: widget.persistentFooterButtons, - drawer: widget.drawer, - onDrawerChanged: widget.onDrawerChanged, - endDrawer: widget.endDrawer, - onEndDrawerChanged: widget.onEndDrawerChanged, - bottomNavigationBar: widget.bottomNavigationBar, - bottomSheet: widget.bottomSheet, - backgroundColor: widget.backgroundColor, - resizeToAvoidBottomInset: widget.resizeToAvoidBottomInset, - primary: widget.primary, - drawerDragStartBehavior: widget.drawerDragStartBehavior, - extendBody: widget.extendBody, - extendBodyBehindAppBar: widget.extendBodyBehindAppBar, - drawerScrimColor: widget.drawerScrimColor, - drawerEdgeDragWidth: widget.drawerEdgeDragWidth, - drawerEnableOpenDragGesture: widget.drawerEnableOpenDragGesture, - endDrawerEnableOpenDragGesture: widget.endDrawerEnableOpenDragGesture, - restorationId: widget.restorationId, - ); + Widget _buildBody(BuildContext context) => _wrapWillPopScope( + context, + child: Scaffold( + key: scaffoldKey, + appBar: widget.appBar, + body: LayoutBuilder( + builder: (context, constraints) { + return Stack( + fit: StackFit.expand, + children: [ + _buildBackPanel(), + PositionedTransition( + rect: _getPanelAnimation(context, constraints), + child: _buildFrontPanel(context), + ), + ], + ); + }, + ), + floatingActionButton: widget.floatingActionButton, + floatingActionButtonLocation: widget.floatingActionButtonLocation, + floatingActionButtonAnimator: widget.floatingActionButtonAnimator, + persistentFooterButtons: widget.persistentFooterButtons, + drawer: widget.drawer, + onDrawerChanged: widget.onDrawerChanged, + endDrawer: widget.endDrawer, + onEndDrawerChanged: widget.onEndDrawerChanged, + bottomNavigationBar: widget.bottomNavigationBar, + bottomSheet: widget.bottomSheet, + backgroundColor: widget.backgroundColor, + resizeToAvoidBottomInset: widget.resizeToAvoidBottomInset, + primary: widget.primary, + drawerDragStartBehavior: widget.drawerDragStartBehavior, + extendBody: widget.extendBody, + extendBodyBehindAppBar: widget.extendBodyBehindAppBar, + drawerScrimColor: widget.drawerScrimColor, + drawerEdgeDragWidth: widget.drawerEdgeDragWidth, + drawerEnableOpenDragGesture: widget.drawerEnableOpenDragGesture, + endDrawerEnableOpenDragGesture: widget.endDrawerEnableOpenDragGesture, + restorationId: widget.restorationId, + ), + ); - return widget.concealBacklayerOnBackButton - ? WillPopScope( - onWillPop: () => _willPopCallback(context), - child: bodyWidget, - ) - : bodyWidget; - } + Widget _wrapWillPopScope(BuildContext context, {required Widget child}) => + !widget.concealBacklayerOnBackButton + ? child + : WillPopScope( + onWillPop: () async { + if (isBackLayerRevealed) { + concealBackLayer(); + return false; + } + return true; + }, + child: child, + ); Container _buildBackLayerScrim() => Container( color: _backLayerScrimColorTween.evaluate(animationController), From e06223ca9e5fd98ade6add2f636c6f02c0048104 Mon Sep 17 00:00:00 2001 From: Harsh Bhikadia Date: Wed, 6 Sep 2023 16:18:38 +0530 Subject: [PATCH 4/4] minor changes --- lib/src/scaffold.dart | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/lib/src/scaffold.dart b/lib/src/scaffold.dart index 303129b..61a86c6 100644 --- a/lib/src/scaffold.dart +++ b/lib/src/scaffold.dart @@ -611,6 +611,20 @@ class BackdropScaffoldState extends State end: widget.backLayerScrim, ); + Widget _wrapWillPopScope(BuildContext context, {required Widget child}) { + if (!widget.concealBacklayerOnBackButton) return child; + return WillPopScope( + onWillPop: () async { + if (isBackLayerRevealed) { + concealBackLayer(); + return false; + } + return true; + }, + child: child, + ); + } + Widget _buildBody(BuildContext context) => _wrapWillPopScope( context, child: Scaffold( @@ -654,20 +668,6 @@ class BackdropScaffoldState extends State ), ); - Widget _wrapWillPopScope(BuildContext context, {required Widget child}) => - !widget.concealBacklayerOnBackButton - ? child - : WillPopScope( - onWillPop: () async { - if (isBackLayerRevealed) { - concealBackLayer(); - return false; - } - return true; - }, - child: child, - ); - Container _buildBackLayerScrim() => Container( color: _backLayerScrimColorTween.evaluate(animationController), height: _backPanelHeight);