Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 48 additions & 20 deletions lib/backdrop.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand All @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -233,31 +241,51 @@ class _BackdropScaffoldState extends State<BackdropScaffold>
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() =>
Expand Down Expand Up @@ -313,7 +341,7 @@ class _BackdropScaffoldState extends State<BackdropScaffold>

Widget _buildBackPanel() {
return FocusScope(
canRequestFocus: isBackPanelVisible,
canRequestFocus: isBackLayerRevealed,
child: Material(
color: this.widget.backLayerBackgroundColor ??
Theme.of(context).primaryColor,
Expand Down Expand Up @@ -344,8 +372,8 @@ class _BackdropScaffoldState extends State<BackdropScaffold>
}

Future<bool> _willPopCallback(BuildContext context) async {
if (isBackPanelVisible) {
showFrontLayer();
if (isBackLayerRevealed) {
concealBackLayer();
return null;
}
return true;
Expand Down