diff --git a/lib/backdrop.dart b/lib/backdrop.dart index 9dc9a89..d0451c0 100644 --- a/lib/backdrop.dart +++ b/lib/backdrop.dart @@ -8,7 +8,7 @@ import 'package:flutter/material.dart'; /// [_BackdropScaffoldState] to be accessed from anywhere below the widget tree. /// /// It can be used to explicitly call backdrop functionality like fling, -/// showBackLayer, showFrontLayer, etc. +/// concealBackLayer, revealBackLayer, etc. /// /// Example: /// ```dart @@ -149,12 +149,12 @@ class BackdropScaffold extends StatefulWidget { final Widget floatingActionButton; /// [FloatingActionButtonLocation] for the [FloatingActionButton] in the [Scaffold] - /// + /// /// Defaults to `null` which leads Scaffold to use the default [FloatingActionButtonLocation] final FloatingActionButtonLocation floatingActionButtonLocation; /// [FloatingActionButtonAnimator] for the [FloatingActionButton] in the [Scaffold] - /// + /// /// Defaults to `null` which leads Scaffold to use the default [FloatingActionButtonAnimator] final FloatingActionButtonAnimator floatingActionButtonAnimator; @@ -164,6 +164,12 @@ class BackdropScaffold extends StatefulWidget { /// Defaults to `const Color(0xFFEEEEEE)`. final Color inactiveOverlayColor; + /// Will be called when [backLayer] have been concealed. + final VoidCallback onBackLayerConcealed; + + /// Will be called when [backLayer] have been revealed. + final VoidCallback onBackLayerRevealed; + /// Creates a backdrop scaffold to be used as a material widget. BackdropScaffold({ this.controller, @@ -192,7 +198,9 @@ class BackdropScaffold extends StatefulWidget { this.floatingActionButton, this.inactiveOverlayColor = const Color(0xFFEEEEEE), this.floatingActionButtonLocation, - this.floatingActionButtonAnimator + this.floatingActionButtonAnimator, + this.onBackLayerConcealed, + this.onBackLayerRevealed, }); @override @@ -233,31 +241,51 @@ class _BackdropScaffoldState extends State if (_shouldDisposeController) _controller.dispose(); } - bool get isTopPanelVisible => + @Deprecated("Replace by the use of `isBackLayerConcealed`." + "This feature was deprecated after v0.3.3.") + bool get isTopPanelVisible => isBackLayerConcealed; + + bool get isBackLayerConcealed => controller.status == AnimationStatus.completed || controller.status == AnimationStatus.forward; - bool get isBackPanelVisible { - final AnimationStatus status = controller.status; - return status == AnimationStatus.dismissed || - status == AnimationStatus.reverse; - } + @Deprecated("Replace by the use of `isBackLayerRevealed`." + "This feature was deprecated after v0.3.3.") + bool get isBackPanelVisible => isBackLayerRevealed; + + bool get isBackLayerRevealed => + controller.status == AnimationStatus.dismissed || + controller.status == AnimationStatus.reverse; void fling() { FocusScope.of(context)?.unfocus(); - if (isTopPanelVisible) { - showBackLayer(); + if (isBackLayerConcealed) { + revealBackLayer(); } else { - showFrontLayer(); + concealBackLayer(); } } - void showBackLayer() { - if (isTopPanelVisible) controller.animateBack(-1.0); + @Deprecated("Replace by the use of `revealBackLayer`." + "This feature was deprecated after v0.3.3.") + void showBackLayer() => revealBackLayer(); + + void revealBackLayer() { + if (isBackLayerConcealed) { + controller.animateBack(-1.0); + widget.onBackLayerRevealed?.call(); + } } - void showFrontLayer() { - if (isBackPanelVisible) controller.animateTo(1.0); + @Deprecated("Replace by the use of `concealBackLayer`." + "This feature was deprecated after v0.3.3.") + void showFrontLayer() => concealBackLayer(); + + void concealBackLayer() { + if (isBackLayerRevealed) { + controller.animateTo(1.0); + widget.onBackLayerConcealed?.call(); + } } double _getBackPanelHeight() => @@ -313,7 +341,7 @@ class _BackdropScaffoldState extends State Widget _buildBackPanel() { return FocusScope( - canRequestFocus: isBackPanelVisible, + canRequestFocus: isBackLayerRevealed, child: Material( color: this.widget.backLayerBackgroundColor ?? Theme.of(context).primaryColor, @@ -344,8 +372,8 @@ class _BackdropScaffoldState extends State } Future _willPopCallback(BuildContext context) async { - if (isBackPanelVisible) { - showFrontLayer(); + if (isBackLayerRevealed) { + concealBackLayer(); return null; } return true;