Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: variable front page height #73

Merged
merged 16 commits into from Feb 22, 2021
27 changes: 21 additions & 6 deletions lib/scaffold.dart
Expand Up @@ -146,6 +146,16 @@ class BackdropScaffold extends StatefulWidget {
/// If null, the color is handled automatically according to the theme.
final Color frontLayerBackgroundColor;

/// Fraction of the available height the front layer will occupy,
/// when active. Clamped to (0, 1).
///
/// Note the front layer will not fully conceal the back layer when
/// this value is less than 1. A scrim will cover the
/// partially concealed back layer if [drawerScrimColor] is provided.
///
/// Defaults to 1.0.
final double frontLayerActiveFactor;

/// Defines the color for the inactive front layer.
/// A default opacity of 0.7 is applied to the passed color.
/// See [inactiveOverlayOpacity].
Expand Down Expand Up @@ -271,6 +281,7 @@ class BackdropScaffold extends StatefulWidget {
this.stickyFrontLayer = false,
this.animationCurve = Curves.easeInOut,
this.frontLayerBackgroundColor,
double frontLayerActiveFactor = 1.0,
this.backLayerBackgroundColor,
this.inactiveOverlayColor = const Color(0xFFEEEEEE),
this.inactiveOverlayOpacity = 0.7,
Expand All @@ -297,6 +308,7 @@ class BackdropScaffold extends StatefulWidget {
this.drawerEnableOpenDragGesture = true,
this.endDrawerEnableOpenDragGesture = true,
}) : assert(inactiveOverlayOpacity >= 0.0 && inactiveOverlayOpacity <= 1.0),
frontLayerActiveFactor = frontLayerActiveFactor.clamp(0, 1).toDouble(),
super(key: key);

@override
Expand Down Expand Up @@ -441,21 +453,20 @@ class BackdropScaffoldState extends State<BackdropScaffold>
Animation<RelativeRect> _getPanelAnimation(
BuildContext context, BoxConstraints constraints) {
double backPanelHeight, frontPanelHeight;

if (widget.stickyFrontLayer &&
_backPanelHeight < constraints.biggest.height - _headerHeight) {
final availableHeight = constraints.biggest.height - _headerHeight;
if (widget.stickyFrontLayer && _backPanelHeight < availableHeight) {
// height is adapted to the height of the back panel
backPanelHeight = _backPanelHeight;
frontPanelHeight = -_backPanelHeight;
} else {
// height is set to fixed value defined in widget.headerHeight
final height = constraints.biggest.height;
backPanelHeight = height - _headerHeight;
backPanelHeight = availableHeight;
frontPanelHeight = -backPanelHeight;
}
return RelativeRectTween(
begin: RelativeRect.fromLTRB(0.0, backPanelHeight, 0.0, frontPanelHeight),
end: RelativeRect.fromLTRB(0.0, 0.0, 0.0, 0.0),
end: RelativeRect.fromLTRB(
0.0, availableHeight * (1 - widget.frontLayerActiveFactor), 0.0, 0.0),
).animate(CurvedAnimation(
parent: controller,
curve: widget.animationCurve,
Expand Down Expand Up @@ -574,6 +585,10 @@ class BackdropScaffoldState extends State<BackdropScaffold>
fit: StackFit.expand,
children: <Widget>[
_buildBackPanel(),
if (isBackLayerConcealed && widget.frontLayerActiveFactor < 1)
Container(
color: widget.drawerScrimColor,
daadu marked this conversation as resolved.
Show resolved Hide resolved
height: _backPanelHeight),
PositionedTransition(
rect: _getPanelAnimation(context, constraints),
child: _buildFrontPanel(context),
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Expand Up @@ -12,7 +12,7 @@ authors:
- Felix Wortmann <https://github.com/felixwortmann>

environment:
sdk: ">=1.19.0 <3.0.0"
sdk: ">=2.3.0 <3.0.0"

dependencies:
flutter:
Expand Down