Skip to content

[104] Changing "Panel" to "Layer" #24

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

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
53 changes: 27 additions & 26 deletions mdc_100_series/lib/backdrop.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ import 'login.dart';

const double _kFlingVelocity = 2.0;

class _BackdropPanel extends StatelessWidget {
const _BackdropPanel({
class _FrontLayer extends StatelessWidget {
const _FrontLayer({
Key key,
this.onTap,
this.child,
Expand Down Expand Up @@ -101,26 +101,26 @@ class _BackdropTitle extends AnimatedWidget {

/// Builds a Backdrop.
///
/// A Backdrop widget has two panels, front and back. The front panel is shown
/// by default, and slides down to show the back panel, from which a user
/// A Backdrop widget has two layers, front and back. The front layer is shown
/// by default, and slides down to show the back layer, from which a user
/// can make a selection. The user can also configure the titles for when the
/// front or back panel is showing.
/// front or back layer is showing.
class Backdrop extends StatefulWidget {
final Category currentCategory;
final Widget frontPanel;
final Widget backPanel;
final Widget frontLayer;
final Widget backLayer;
final Widget frontTitle;
final Widget backTitle;

const Backdrop({
@required this.currentCategory,
@required this.frontPanel,
@required this.backPanel,
@required this.frontLayer,
@required this.backLayer,
@required this.frontTitle,
@required this.backTitle,
}) : assert(currentCategory != null),
assert(frontPanel != null),
assert(backPanel != null),
assert(frontLayer != null),
assert(backLayer != null),
assert(frontTitle != null),
assert(backTitle != null);

Expand Down Expand Up @@ -150,9 +150,9 @@ class _BackdropState extends State<Backdrop>
setState(() {
_controller.fling(
velocity:
_backdropPanelVisible ? -_kFlingVelocity : _kFlingVelocity);
_frontLayerVisible ? -_kFlingVelocity : _kFlingVelocity);
});
} else if (!_backdropPanelVisible) {
} else if (!_frontLayerVisible) {
setState(() {
_controller.fling(velocity: _kFlingVelocity);
});
Expand All @@ -165,37 +165,38 @@ class _BackdropState extends State<Backdrop>
super.dispose();
}

bool get _backdropPanelVisible {
bool get _frontLayerVisible {
final AnimationStatus status = _controller.status;
return status == AnimationStatus.completed ||
status == AnimationStatus.forward;
}

void _toggleBackdropPanelVisibility() {
void _toggleBackdropLayerVisibility() {
print(_frontLayerVisible);
_controller.fling(
velocity: _backdropPanelVisible ? -_kFlingVelocity : _kFlingVelocity);
velocity: _frontLayerVisible ? -_kFlingVelocity : _kFlingVelocity);
}

Widget _buildStack(BuildContext context, BoxConstraints constraints) {
const double panelTitleHeight = 48.0;
final Size panelSize = constraints.biggest;
final double panelTop = panelSize.height - panelTitleHeight;
const double layerTitleHeight = 48.0;
final Size layerSize = constraints.biggest;
final double layerTop = layerSize.height - layerTitleHeight;

Animation<RelativeRect> panelAnimation = RelativeRectTween(
Animation<RelativeRect> layerAnimation = RelativeRectTween(
begin: RelativeRect.fromLTRB(
0.0, panelTop, 0.0, panelTop - panelSize.height),
0.0, layerTop, 0.0, layerTop - layerSize.height),
end: RelativeRect.fromLTRB(0.0, 0.0, 0.0, 0.0),
).animate(_controller.view);

return Stack(
key: _backdropKey,
children: <Widget>[
widget.backPanel,
widget.backLayer,
PositionedTransition(
rect: panelAnimation,
child: _BackdropPanel(
onTap: _toggleBackdropPanelVisibility,
child: widget.frontPanel,
rect: layerAnimation,
child: _FrontLayer(
onTap: _toggleBackdropLayerVisibility,
child: widget.frontLayer,
),
),
],
Expand Down