Commit 5a27f6a2 authored by Ian Hickson's avatar Ian Hickson Committed by GitHub

Add more SnackBar documentation. (#6696)

Fixes https://github.com/flutter/flutter/issues/6628
parent d3cdb270
...@@ -520,12 +520,17 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin { ...@@ -520,12 +520,17 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin {
AnimationController _snackBarController; AnimationController _snackBarController;
Timer _snackBarTimer; Timer _snackBarTimer;
/// Shows a [SnackBar] at the bottom fo the scaffold. /// Shows a [SnackBar] at the bottom of the scaffold.
/// ///
/// A scaffold can show at most one snack bar at a time. If this function is /// A scaffold can show at most one snack bar at a time. If this function is
/// called while another snack bar is already visible, the given snack bar /// called while another snack bar is already visible, the given snack bar
/// will be added to a queue and displayed after the earlier snack bars have /// will be added to a queue and displayed after the earlier snack bars have
/// closed. /// closed.
///
/// To control how long a [SnackBar] remains visible, use [SnackBar.duration].
///
/// To remove a [SnackBar] suddenly (without an animation), use
/// [removeCurrentSnackBar].
ScaffoldFeatureController<SnackBar, Null> showSnackBar(SnackBar snackbar) { ScaffoldFeatureController<SnackBar, Null> showSnackBar(SnackBar snackbar) {
_snackBarController ??= SnackBar.createAnimationController(vsync: this) _snackBarController ??= SnackBar.createAnimationController(vsync: this)
..addStatusListener(_handleSnackBarStatusChange); ..addStatusListener(_handleSnackBarStatusChange);
......
...@@ -26,8 +26,7 @@ const Color _kSnackBackground = const Color(0xFF323232); ...@@ -26,8 +26,7 @@ const Color _kSnackBackground = const Color(0xFF323232);
// TODO(ianh): Implement the Tablet version of snackbar if we're "on a tablet". // TODO(ianh): Implement the Tablet version of snackbar if we're "on a tablet".
const Duration _kSnackBarTransitionDuration = const Duration(milliseconds: 250); const Duration _kSnackBarTransitionDuration = const Duration(milliseconds: 250);
const Duration _kSnackBarShortDisplayDuration = const Duration(milliseconds: 1500); const Duration _kSnackBarDisplayDuration = const Duration(milliseconds: 1500);
const Duration _kSnackBarMediumDisplayDuration = const Duration(milliseconds: 2750);
const Curve _snackBarHeightCurve = Curves.fastOutSlowIn; const Curve _snackBarHeightCurve = Curves.fastOutSlowIn;
const Curve _snackBarFadeCurve = const Interval(0.72, 1.0, curve: Curves.fastOutSlowIn); const Curve _snackBarFadeCurve = const Interval(0.72, 1.0, curve: Curves.fastOutSlowIn);
...@@ -92,12 +91,20 @@ class _SnackBarActionState extends State<SnackBarAction> { ...@@ -92,12 +91,20 @@ class _SnackBarActionState extends State<SnackBarAction> {
/// A lightweight message with an optional action which briefly displays at the /// A lightweight message with an optional action which briefly displays at the
/// bottom of the screen. /// bottom of the screen.
/// ///
/// Displayed with the Scaffold.of().showSnackBar() API. /// To display a snack bar, call `Scaffold.of(context).showSnackBar()`, passing
/// an instance of [SnackBar] that describes the message.
///
/// To control how long the [SnackBar] remains visible, specify a [duration].
/// ///
/// See also: /// See also:
/// ///
/// * [Scaffold.of] and [ScaffoldState.showSnackBar] /// * [Scaffold.of], to obtain the current [ScaffoldState], which manages the
/// * [SnackBarAction] /// display and animation of snack bars.
/// * [ScaffoldState.showSnackBar], which displays a [SnackBar].
/// * [ScaffoldState.removeCurrentSnackBar], which abruptly hides the currently
/// displayed snack bar, if any, and allows the next to be displayed.
/// * [SnackBarAction], which is used to specify an [action] button to show
/// on the snack bar.
/// * <https://material.google.com/components/snackbars-toasts.html> /// * <https://material.google.com/components/snackbars-toasts.html>
class SnackBar extends StatelessWidget { class SnackBar extends StatelessWidget {
/// Creates a snack bar. /// Creates a snack bar.
...@@ -107,7 +114,7 @@ class SnackBar extends StatelessWidget { ...@@ -107,7 +114,7 @@ class SnackBar extends StatelessWidget {
Key key, Key key,
this.content, this.content,
this.action, this.action,
this.duration: _kSnackBarShortDisplayDuration, this.duration: _kSnackBarDisplayDuration,
this.animation this.animation
}) : super(key: key) { }) : super(key: key) {
assert(content != null); assert(content != null);
...@@ -122,9 +129,20 @@ class SnackBar extends StatelessWidget { ...@@ -122,9 +129,20 @@ class SnackBar extends StatelessWidget {
/// ///
/// For example, the snack bar might let the user undo the operation that /// For example, the snack bar might let the user undo the operation that
/// prompted the snackbar. Snack bars can have at most one action. /// prompted the snackbar. Snack bars can have at most one action.
///
/// The action should not be "dismiss" or "cancel".
final SnackBarAction action; final SnackBarAction action;
/// The amount of time the snack bar should be displayed. /// The amount of time the snack bar should be displayed.
///
/// Defaults to 1.5s.
///
/// See also:
///
/// * [ScaffoldState.removeCurrentSnackBar], which abruptly hides the
/// currently displayed snack bar, if any, and allows the next to be
/// displayed.
/// * <https://material.google.com/components/snackbars-toasts.html>
final Duration duration; final Duration duration;
/// The animation driving the entrance and exit of the snack bar. /// The animation driving the entrance and exit of the snack bar.
......
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