Skip to content

Commit 5a27f6a

Browse files
authored
Add more SnackBar documentation. (flutter#6696)
Fixes flutter#6628
1 parent d3cdb27 commit 5a27f6a

File tree

2 files changed

+30
-7
lines changed

2 files changed

+30
-7
lines changed

packages/flutter/lib/src/material/scaffold.dart

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -520,12 +520,17 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin {
520520
AnimationController _snackBarController;
521521
Timer _snackBarTimer;
522522

523-
/// Shows a [SnackBar] at the bottom fo the scaffold.
523+
/// Shows a [SnackBar] at the bottom of the scaffold.
524524
///
525525
/// A scaffold can show at most one snack bar at a time. If this function is
526526
/// called while another snack bar is already visible, the given snack bar
527527
/// will be added to a queue and displayed after the earlier snack bars have
528528
/// closed.
529+
///
530+
/// To control how long a [SnackBar] remains visible, use [SnackBar.duration].
531+
///
532+
/// To remove a [SnackBar] suddenly (without an animation), use
533+
/// [removeCurrentSnackBar].
529534
ScaffoldFeatureController<SnackBar, Null> showSnackBar(SnackBar snackbar) {
530535
_snackBarController ??= SnackBar.createAnimationController(vsync: this)
531536
..addStatusListener(_handleSnackBarStatusChange);

packages/flutter/lib/src/material/snack_bar.dart

Lines changed: 24 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ const Color _kSnackBackground = const Color(0xFF323232);
2626
// TODO(ianh): Implement the Tablet version of snackbar if we're "on a tablet".
2727

2828
const Duration _kSnackBarTransitionDuration = const Duration(milliseconds: 250);
29-
const Duration _kSnackBarShortDisplayDuration = const Duration(milliseconds: 1500);
30-
const Duration _kSnackBarMediumDisplayDuration = const Duration(milliseconds: 2750);
29+
const Duration _kSnackBarDisplayDuration = const Duration(milliseconds: 1500);
3130
const Curve _snackBarHeightCurve = Curves.fastOutSlowIn;
3231
const Curve _snackBarFadeCurve = const Interval(0.72, 1.0, curve: Curves.fastOutSlowIn);
3332

@@ -92,12 +91,20 @@ class _SnackBarActionState extends State<SnackBarAction> {
9291
/// A lightweight message with an optional action which briefly displays at the
9392
/// bottom of the screen.
9493
///
95-
/// Displayed with the Scaffold.of().showSnackBar() API.
94+
/// To display a snack bar, call `Scaffold.of(context).showSnackBar()`, passing
95+
/// an instance of [SnackBar] that describes the message.
96+
///
97+
/// To control how long the [SnackBar] remains visible, specify a [duration].
9698
///
9799
/// See also:
98100
///
99-
/// * [Scaffold.of] and [ScaffoldState.showSnackBar]
100-
/// * [SnackBarAction]
101+
/// * [Scaffold.of], to obtain the current [ScaffoldState], which manages the
102+
/// display and animation of snack bars.
103+
/// * [ScaffoldState.showSnackBar], which displays a [SnackBar].
104+
/// * [ScaffoldState.removeCurrentSnackBar], which abruptly hides the currently
105+
/// displayed snack bar, if any, and allows the next to be displayed.
106+
/// * [SnackBarAction], which is used to specify an [action] button to show
107+
/// on the snack bar.
101108
/// * <https://material.google.com/components/snackbars-toasts.html>
102109
class SnackBar extends StatelessWidget {
103110
/// Creates a snack bar.
@@ -107,7 +114,7 @@ class SnackBar extends StatelessWidget {
107114
Key key,
108115
this.content,
109116
this.action,
110-
this.duration: _kSnackBarShortDisplayDuration,
117+
this.duration: _kSnackBarDisplayDuration,
111118
this.animation
112119
}) : super(key: key) {
113120
assert(content != null);
@@ -122,9 +129,20 @@ class SnackBar extends StatelessWidget {
122129
///
123130
/// For example, the snack bar might let the user undo the operation that
124131
/// prompted the snackbar. Snack bars can have at most one action.
132+
///
133+
/// The action should not be "dismiss" or "cancel".
125134
final SnackBarAction action;
126135

127136
/// The amount of time the snack bar should be displayed.
137+
///
138+
/// Defaults to 1.5s.
139+
///
140+
/// See also:
141+
///
142+
/// * [ScaffoldState.removeCurrentSnackBar], which abruptly hides the
143+
/// currently displayed snack bar, if any, and allows the next to be
144+
/// displayed.
145+
/// * <https://material.google.com/components/snackbars-toasts.html>
128146
final Duration duration;
129147

130148
/// The animation driving the entrance and exit of the snack bar.

0 commit comments

Comments
 (0)