Commit a2d322c0 authored by Adam Barth's avatar Adam Barth

Merge pull request #3013 from abarth/dismiss_snackbar

Make it possible to dismiss a snackbar manually
parents 040ff9b0 d4febd08
......@@ -304,6 +304,17 @@ class ScaffoldState extends State<Scaffold> {
}
}
void removeCurrentSnackBar() {
if (_snackBars.isEmpty)
return;
Completer<Null> completer = _snackBars.first._completer;
if (!completer.isCompleted)
completer.complete();
_snackBarTimer?.cancel();
_snackBarTimer = null;
_snackBarController.value = 0.0;
}
void _hideSnackBar() {
assert(_snackBarController.status == AnimationStatus.forward ||
_snackBarController.status == AnimationStatus.completed);
......
......@@ -7,6 +7,7 @@ import 'package:flutter/widgets.dart';
import 'button.dart';
import 'flat_button.dart';
import 'material.dart';
import 'scaffold.dart';
import 'theme_data.dart';
import 'theme.dart';
import 'typography.dart';
......@@ -118,23 +119,30 @@ class SnackBar extends StatelessWidget {
},
child: new Semantics(
container: true,
child: new Material(
elevation: 6,
color: _kSnackBackground,
child: new Container(
margin: const EdgeInsets.symmetric(horizontal: _kSideMargins),
child: new Theme(
data: new ThemeData(
brightness: ThemeBrightness.dark,
accentColor: theme.accentColor,
accentColorBrightness: theme.accentColorBrightness,
textTheme: Typography.white
),
child: new FadeTransition(
opacity: fadeAnimation,
child: new Row(
children: children,
crossAxisAlignment: CrossAxisAlignment.center
child: new Dismissable(
key: new Key('dismissable'),
direction: DismissDirection.down,
onDismissed: (DismissDirection direction) {
Scaffold.of(context).removeCurrentSnackBar();
},
child: new Material(
elevation: 6,
color: _kSnackBackground,
child: new Container(
margin: const EdgeInsets.symmetric(horizontal: _kSideMargins),
child: new Theme(
data: new ThemeData(
brightness: ThemeBrightness.dark,
accentColor: theme.accentColor,
accentColorBrightness: theme.accentColorBrightness,
textTheme: Typography.white
),
child: new FadeTransition(
opacity: fadeAnimation,
child: new Row(
children: children,
crossAxisAlignment: CrossAxisAlignment.center
)
)
)
)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment