snack_bar.dart 21.6 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

5
import 'package:flutter/rendering.dart';
6
import 'package:flutter/widgets.dart';
7

8
import 'button_style.dart';
9
import 'color_scheme.dart';
10
import 'material.dart';
11
import 'material_state.dart';
12
import 'scaffold.dart';
13
import 'snack_bar_theme.dart';
14 15
import 'text_button.dart';
import 'text_button_theme.dart';
16
import 'theme.dart';
Matt Perry's avatar
Matt Perry committed
17

18
const double _singleLineVerticalPadding = 14.0;
Matt Perry's avatar
Matt Perry committed
19

Hixie's avatar
Hixie committed
20 21
// TODO(ianh): We should check if the given text and actions are going to fit on
// one line or not, and if they are, use the single-line layout, and if not, use
22 23 24
// the multiline layout, https://github.com/flutter/flutter/issues/32782
// See https://material.io/components/snackbars#specs, 'Longer Action Text' does
// not match spec.
Hixie's avatar
Hixie committed
25

26 27
const Duration _snackBarTransitionDuration = Duration(milliseconds: 250);
const Duration _snackBarDisplayDuration = Duration(milliseconds: 4000);
28
const Curve _snackBarHeightCurve = Curves.fastOutSlowIn;
29 30
const Curve _snackBarFadeInCurve = Interval(0.45, 1.0, curve: Curves.fastOutSlowIn);
const Curve _snackBarFadeOutCurve = Interval(0.72, 1.0, curve: Curves.fastOutSlowIn);
Hixie's avatar
Hixie committed
31

32 33
/// Specify how a [SnackBar] was closed.
///
34
/// The [ScaffoldMessengerState.showSnackBar] function returns a
35 36 37
/// [ScaffoldFeatureController]. The value of the controller's closed property
/// is a Future that resolves to a SnackBarClosedReason. Applications that need
/// to know how a snackbar was closed can use this value.
38 39 40 41
///
/// Example:
///
/// ```dart
42
/// ScaffoldMessenger.of(context).showSnackBar(
43
///   SnackBar( ... )
44 45 46 47 48 49 50 51
/// ).closed.then((SnackBarClosedReason reason) {
///    ...
/// });
/// ```
enum SnackBarClosedReason {
  /// The snack bar was closed after the user tapped a [SnackBarAction].
  action,

52
  /// The snack bar was closed through a [SemanticsAction.dismiss].
53 54
  dismiss,

55 56 57 58
  /// The snack bar was closed by a user's swipe.
  swipe,

  /// The snack bar was closed by the [ScaffoldFeatureController] close callback
59
  /// or by calling [ScaffoldMessengerState.hideCurrentSnackBar] directly.
60 61
  hide,

62
  /// The snack bar was closed by an call to [ScaffoldMessengerState.removeCurrentSnackBar].
63 64 65 66 67 68
  remove,

  /// The snack bar was closed because its timer expired.
  timeout,
}

69 70 71 72 73
/// A button for a [SnackBar], known as an "action".
///
/// Snack bar actions are always enabled. If you want to disable a snack bar
/// action, simply don't include it in the snack bar.
///
74 75
/// Snack bar actions can only be pressed once. Subsequent presses are ignored.
///
76 77 78
/// See also:
///
///  * [SnackBar]
jslavitz's avatar
jslavitz committed
79
///  * <https://material.io/design/components/snackbars.html>
80
class SnackBarAction extends StatefulWidget {
81 82 83
  /// Creates an action for a [SnackBar].
  ///
  /// The [label] and [onPressed] arguments must be non-null.
84
  const SnackBarAction({
85
    Key? key,
jslavitz's avatar
jslavitz committed
86 87
    this.textColor,
    this.disabledTextColor,
88 89
    required this.label,
    required this.onPressed,
90 91 92
  }) : assert(label != null),
       assert(onPressed != null),
       super(key: key);
93

94 95
  /// The button label color. If not provided, defaults to
  /// [SnackBarThemeData.actionTextColor].
96
  final Color? textColor;
jslavitz's avatar
jslavitz committed
97 98

  /// The button disabled label color. This color is shown after the
99
  /// [SnackBarAction] is dismissed.
100
  final Color? disabledTextColor;
jslavitz's avatar
jslavitz committed
101

102
  /// The button label.
103
  final String label;
104

105
  /// The callback to be called when the button is pressed. Must not be null.
106
  ///
107
  /// This callback will be called at most once each time this action is
108
  /// displayed in a [SnackBar].
109
  final VoidCallback onPressed;
110

111
  @override
112
  State<SnackBarAction> createState() => _SnackBarActionState();
113 114 115 116 117 118 119 120 121 122 123
}

class _SnackBarActionState extends State<SnackBarAction> {
  bool _haveTriggeredAction = false;

  void _handlePressed() {
    if (_haveTriggeredAction)
      return;
    setState(() {
      _haveTriggeredAction = true;
    });
124
    widget.onPressed();
125
    Scaffold.of(context).hideCurrentSnackBar(reason: SnackBarClosedReason.action);
126 127
  }

128
  @override
Hixie's avatar
Hixie committed
129
  Widget build(BuildContext context) {
130
    Color? resolveForegroundColor(Set<MaterialState> states) {
131
      final SnackBarThemeData snackBarTheme = Theme.of(context).snackBarTheme;
132 133 134 135
      if (states.contains(MaterialState.disabled))
        return widget.disabledTextColor ?? snackBarTheme.disabledActionTextColor;
      return widget.textColor ?? snackBarTheme.actionTextColor;
    }
136

137 138
    return TextButton(
      style: ButtonStyle(
139
        foregroundColor: MaterialStateProperty.resolveWith<Color?>(resolveForegroundColor),
140
      ),
141
      onPressed: _haveTriggeredAction ? null : _handlePressed,
142
      child: Text(widget.label),
143 144 145
    );
  }
}
146

147 148 149
/// A lightweight message with an optional action which briefly displays at the
/// bottom of the screen.
///
150 151
/// {@youtube 560 315 https://www.youtube.com/watch?v=zpO6n_oZWw0}
///
152 153
/// To display a snack bar, call `ScaffoldMessenger.of(context).showSnackBar()`,
/// passing an instance of [SnackBar] that describes the message.
154 155
///
/// To control how long the [SnackBar] remains visible, specify a [duration].
156
///
157 158 159
/// A SnackBar with an action will not time out when TalkBack or VoiceOver are
/// enabled. This is controlled by [AccessibilityFeatures.accessibleNavigation].
///
160
/// {@tool dartpad --template=stateless_widget_scaffold_center}
161 162 163 164 165 166 167
///
/// Here is an example of a [SnackBar] with an [action] button implemented using
/// [SnackBarAction].
///
/// ```dart
/// Widget build(BuildContext context) {
///   return ElevatedButton(
168
///     child: const Text('Show Snackbar'),
169 170 171
///     onPressed: () {
///       ScaffoldMessenger.of(context).showSnackBar(
///         SnackBar(
172
///           content: const Text('Awesome Snackbar!'),
173
///           action: SnackBarAction(
174
///             label: 'Action',
175 176 177 178 179 180 181 182 183 184 185 186
///             onPressed: () {
///               // Code to execute.
///             },
///           ),
///         ),
///       );
///     },
///   );
/// }
/// ```
/// {@end-tool}
///
187
/// {@tool dartpad --template=stateless_widget_scaffold_center}
188 189 190 191 192 193 194 195
///
/// Here is an example of a customized [SnackBar]. It utilizes
/// [behavior], [shape], [padding], [width], and [duration] to customize the
/// location, appearance, and the duration for which the [SnackBar] is visible.
///
/// ```dart
/// Widget build(BuildContext context) {
///   return ElevatedButton(
196
///     child: const Text('Show Snackbar'),
197 198 199 200
///     onPressed: () {
///       ScaffoldMessenger.of(context).showSnackBar(
///         SnackBar(
///           action: SnackBarAction(
201
///             label: 'Action',
202 203 204 205
///             onPressed: () {
///               // Code to execute.
///             },
///           ),
206 207
///           content: const Text('Awesome SnackBar!'),
///           duration: const Duration(milliseconds: 1500),
208
///           width: 280.0, // Width of the SnackBar.
209 210 211
///           padding: const EdgeInsets.symmetric(
///             horizontal: 8.0,  // Inner padding for SnackBar content.
///           ),
212 213 214 215 216 217 218 219 220 221 222 223
///           behavior: SnackBarBehavior.floating,
///           shape: RoundedRectangleBorder(
///             borderRadius: BorderRadius.circular(10.0),
///           ),
///         ),
///       );
///     },
///   );
/// }
/// ```
/// {@end-tool}
///
224
/// See also:
225
///
226 227 228 229 230
///  * [ScaffoldMessenger.of], to obtain the current [ScaffoldMessengerState],
///    which manages the display and animation of snack bars.
///  * [ScaffoldMessengerState.showSnackBar], which displays a [SnackBar].
///  * [ScaffoldMessengerState.removeCurrentSnackBar], which abruptly hides the
///    currently displayed snack bar, if any, and allows the next to be displayed.
231 232
///  * [SnackBarAction], which is used to specify an [action] button to show
///    on the snack bar.
233 234
///  * [SnackBarThemeData], to configure the default property values for
///    [SnackBar] widgets.
jslavitz's avatar
jslavitz committed
235
///  * <https://material.io/design/components/snackbars.html>
236
class SnackBar extends StatefulWidget {
237 238
  /// Creates a snack bar.
  ///
239 240
  /// The [content] argument must be non-null. The [elevation] must be null or
  /// non-negative.
241
  const SnackBar({
242 243
    Key? key,
    required this.content,
244
    this.backgroundColor,
245
    this.elevation,
246 247 248
    this.margin,
    this.padding,
    this.width,
249 250
    this.shape,
    this.behavior,
251
    this.action,
252
    this.duration = _snackBarDisplayDuration,
253
    this.animation,
254
    this.onVisible,
255
    this.dismissDirection = DismissDirection.down,
256 257
  }) : assert(elevation == null || elevation >= 0.0),
       assert(content != null),
258 259 260 261 262 263 264 265 266 267 268 269
       assert(
         margin == null || behavior == SnackBarBehavior.floating,
         'Margin can only be used with floating behavior',
       ),
       assert(
         width == null || behavior == SnackBarBehavior.floating,
         'Width can only be used with floating behavior',
       ),
       assert(
         width == null || margin == null,
         'Width and margin can not be used together',
       ),
270
       assert(duration != null),
271
       super(key: key);
272

273 274 275
  /// The primary content of the snack bar.
  ///
  /// Typically a [Text] widget.
276
  final Widget content;
277

278
  /// The snack bar's background color. If not specified it will use
279 280 281 282
  /// [SnackBarThemeData.backgroundColor] of [ThemeData.snackBarTheme]. If that
  /// is not specified it will default to a dark variation of
  /// [ColorScheme.surface] for light themes, or [ColorScheme.onSurface] for
  /// dark themes.
283
  final Color? backgroundColor;
284

285 286 287 288 289
  /// The z-coordinate at which to place the snack bar. This controls the size
  /// of the shadow below the snack bar.
  ///
  /// Defines the card's [Material.elevation].
  ///
290 291 292
  /// If this property is null, then [SnackBarThemeData.elevation] of
  /// [ThemeData.snackBarTheme] is used, if that is also null, the default value
  /// is 6.0.
293
  final double? elevation;
294

295 296 297 298 299 300 301
  /// Empty space to surround the snack bar.
  ///
  /// This property is only used when [behavior] is [SnackBarBehavior.floating].
  /// It can not be used if [width] is specified.
  ///
  /// If this property is null, then the default is
  /// `EdgeInsets.fromLTRB(15.0, 5.0, 15.0, 10.0)`.
302
  final EdgeInsetsGeometry? margin;
303 304 305 306 307 308 309 310

  /// The amount of padding to apply to the snack bar's content and optional
  /// action.
  ///
  /// If this property is null, then the default depends on the [behavior] and
  /// the presence of an [action]. The start padding is 24 if [behavior] is
  /// [SnackBarBehavior.fixed] and 16 if it is [SnackBarBehavior.floating]. If
  /// there is no [action], the same padding is added to the end.
311
  final EdgeInsetsGeometry? padding;
312 313 314 315 316 317 318 319 320

  /// The width of the snack bar.
  ///
  /// If width is specified, the snack bar will be centered horizontally in the
  /// available space. This property is only used when [behavior] is
  /// [SnackBarBehavior.floating]. It can not be used if [margin] is specified.
  ///
  /// If this property is null, then the snack bar will take up the full device
  /// width less the margin.
321
  final double? width;
322

323 324 325 326
  /// The shape of the snack bar's [Material].
  ///
  /// Defines the snack bar's [Material.shape].
  ///
327 328 329 330 331 332
  /// If this property is null then [SnackBarThemeData.shape] of
  /// [ThemeData.snackBarTheme] is used. If that's null then the shape will
  /// depend on the [SnackBarBehavior]. For [SnackBarBehavior.fixed], no
  /// overriding shape is specified, so the [SnackBar] is rectangular. For
  /// [SnackBarBehavior.floating], it uses a [RoundedRectangleBorder] with a
  /// circular corner radius of 4.0.
333
  final ShapeBorder? shape;
334 335 336 337 338 339 340

  /// This defines the behavior and location of the snack bar.
  ///
  /// Defines where a [SnackBar] should appear within a [Scaffold] and how its
  /// location should be adjusted when the scaffold also includes a
  /// [FloatingActionButton] or a [BottomNavigationBar]
  ///
341 342 343
  /// If this property is null, then [SnackBarThemeData.behavior] of
  /// [ThemeData.snackBarTheme] is used. If that is null, then the default is
  /// [SnackBarBehavior.fixed].
344
  final SnackBarBehavior? behavior;
345

346 347 348 349
  /// (optional) An action that the user can take based on the snack bar.
  ///
  /// For example, the snack bar might let the user undo the operation that
  /// prompted the snackbar. Snack bars can have at most one action.
350 351
  ///
  /// The action should not be "dismiss" or "cancel".
352
  final SnackBarAction? action;
353 354

  /// The amount of time the snack bar should be displayed.
355
  ///
jslavitz's avatar
jslavitz committed
356
  /// Defaults to 4.0s.
357 358 359
  ///
  /// See also:
  ///
360
  ///  * [ScaffoldMessengerState.removeCurrentSnackBar], which abruptly hides the
361 362
  ///    currently displayed snack bar, if any, and allows the next to be
  ///    displayed.
jslavitz's avatar
jslavitz committed
363
  ///  * <https://material.io/design/components/snackbars.html>
Hixie's avatar
Hixie committed
364
  final Duration duration;
365 366

  /// The animation driving the entrance and exit of the snack bar.
367
  final Animation<double>? animation;
368

369
  /// Called the first time that the snackbar is visible within a [Scaffold].
370
  final VoidCallback? onVisible;
371

372 373 374 375 376
  /// The direction in which the SnackBar can be dismissed.
  ///
  /// Cannot be null, defaults to [DismissDirection.down].
  final DismissDirection dismissDirection;

377
  // API for ScaffoldMessengerState.showSnackBar():
378 379

  /// Creates an animation controller useful for driving a snack bar's entrance and exit animation.
380
  static AnimationController createAnimationController({ required TickerProvider vsync }) {
381 382 383 384 385 386 387 388 389 390 391
    return AnimationController(
      duration: _snackBarTransitionDuration,
      debugLabel: 'SnackBar',
      vsync: vsync,
    );
  }

  /// Creates a copy of this snack bar but with the animation replaced with the given animation.
  ///
  /// If the original snack bar lacks a key, the newly created snack bar will
  /// use the given fallback key.
392
  SnackBar withAnimation(Animation<double> newAnimation, { Key? fallbackKey }) {
393 394 395 396 397
    return SnackBar(
      key: key ?? fallbackKey,
      content: content,
      backgroundColor: backgroundColor,
      elevation: elevation,
398 399 400
      margin: margin,
      padding: padding,
      width: width,
401 402 403 404 405 406
      shape: shape,
      behavior: behavior,
      action: action,
      duration: duration,
      animation: newAnimation,
      onVisible: onVisible,
407
      dismissDirection: dismissDirection,
408 409 410 411 412 413 414 415 416 417 418 419 420
    );
  }

  @override
  State<SnackBar> createState() => _SnackBarState();
}

class _SnackBarState extends State<SnackBar> {
  bool _wasVisible = false;

  @override
  void initState() {
    super.initState();
421
    widget.animation!.addStatusListener(_onAnimationStatusChanged);
422 423 424 425 426
  }

  @override
  void didUpdateWidget(SnackBar oldWidget) {
    if (widget.animation != oldWidget.animation) {
427 428
      oldWidget.animation!.removeStatusListener(_onAnimationStatusChanged);
      widget.animation!.addStatusListener(_onAnimationStatusChanged);
429 430 431 432 433 434
    }
    super.didUpdateWidget(oldWidget);
  }

  @override
  void dispose() {
435
    widget.animation!.removeStatusListener(_onAnimationStatusChanged);
436 437 438 439 440 441 442 443 444 445 446
    super.dispose();
  }

  void _onAnimationStatusChanged(AnimationStatus animationStatus) {
    switch (animationStatus) {
      case AnimationStatus.dismissed:
      case AnimationStatus.forward:
      case AnimationStatus.reverse:
        break;
      case AnimationStatus.completed:
        if (widget.onVisible != null && !_wasVisible) {
447
          widget.onVisible!();
448 449 450 451 452
        }
        _wasVisible = true;
    }
  }

453
  @override
454
  Widget build(BuildContext context) {
455
    assert(debugCheckHasMediaQuery(context));
456
    final MediaQueryData mediaQueryData = MediaQuery.of(context);
457
    assert(widget.animation != null);
458
    final ThemeData theme = Theme.of(context);
459
    final ColorScheme colorScheme = theme.colorScheme;
460
    final SnackBarThemeData snackBarTheme = theme.snackBarTheme;
461
    final bool isThemeDark = theme.brightness == Brightness.dark;
462
    final Color buttonColor = isThemeDark ? colorScheme.primaryVariant : colorScheme.secondary;
463 464 465 466 467 468 469

    // SnackBar uses a theme that is the opposite brightness from
    // the surrounding theme.
    final Brightness brightness = isThemeDark ? Brightness.light : Brightness.dark;
    final Color themeBackgroundColor = isThemeDark
      ? colorScheme.onSurface
      : Color.alphaBlend(colorScheme.onSurface.withOpacity(0.80), colorScheme.surface);
470
    final ThemeData inverseTheme = theme.copyWith(
471 472 473 474 475
      colorScheme: ColorScheme(
        primary: colorScheme.onPrimary,
        primaryVariant: colorScheme.onPrimary,
        // For the button color, the spec says it should be primaryVariant, but for
        // backward compatibility on light themes we are leaving it as secondary.
476
        secondary: buttonColor,
477 478 479 480 481 482 483 484 485 486 487
        secondaryVariant: colorScheme.onSecondary,
        surface: colorScheme.onSurface,
        background: themeBackgroundColor,
        error: colorScheme.onError,
        onPrimary: colorScheme.primary,
        onSecondary: colorScheme.secondary,
        onSurface: colorScheme.surface,
        onBackground: colorScheme.background,
        onError: colorScheme.error,
        brightness: brightness,
      ),
488
    );
489

490
    final TextStyle? contentTextStyle = snackBarTheme.contentTextStyle ?? ThemeData(brightness: brightness).textTheme.subtitle1;
491
    final SnackBarBehavior snackBarBehavior = widget.behavior ?? snackBarTheme.behavior ?? SnackBarBehavior.fixed;
492
    final bool isFloatingSnackBar = snackBarBehavior == SnackBarBehavior.floating;
493 494 495
    final double horizontalPadding = isFloatingSnackBar ? 16.0 : 24.0;
    final EdgeInsetsGeometry padding = widget.padding
      ?? EdgeInsetsDirectional.only(start: horizontalPadding, end: widget.action != null ? 0 : horizontalPadding);
496

497 498
    final double actionHorizontalMargin = (widget.padding?.resolve(TextDirection.ltr).right ?? horizontalPadding) / 2;

499 500
    final CurvedAnimation heightAnimation = CurvedAnimation(parent: widget.animation!, curve: _snackBarHeightCurve);
    final CurvedAnimation fadeInAnimation = CurvedAnimation(parent: widget.animation!, curve: _snackBarFadeInCurve);
501
    final CurvedAnimation fadeOutAnimation = CurvedAnimation(
502
      parent: widget.animation!,
503 504 505 506
      curve: _snackBarFadeOutCurve,
      reverseCurve: const Threshold(0.0),
    );

507 508
    Widget snackBar = Padding(
      padding: padding,
509
      child: Row(
510
        crossAxisAlignment: CrossAxisAlignment.center,
511 512 513 514 515
        children: <Widget>[
          Expanded(
            child: Container(
              padding: const EdgeInsets.symmetric(vertical: _singleLineVerticalPadding),
              child: DefaultTextStyle(
516
                style: contentTextStyle!,
517
                child: widget.content,
518 519 520
              ),
            ),
          ),
521
          if (widget.action != null)
522 523 524 525 526 527 528 529
            Padding(
              padding: EdgeInsets.symmetric(horizontal: actionHorizontalMargin),
              child: TextButtonTheme(
                data: TextButtonThemeData(
                  style: TextButton.styleFrom(
                    primary: buttonColor,
                    padding: EdgeInsets.symmetric(horizontal: horizontalPadding),
                  ),
530
                ),
531
                child: widget.action!,
532
              ),
533
            ),
534
        ],
535 536
      ),
    );
537

538 539 540 541 542 543 544
    if (!isFloatingSnackBar) {
      snackBar = SafeArea(
        top: false,
        child: snackBar,
      );
    }

545
    final double elevation = widget.elevation ?? snackBarTheme.elevation ?? 6.0;
546
    final Color backgroundColor = widget.backgroundColor ?? snackBarTheme.backgroundColor ?? inverseTheme.colorScheme.background;
547
    final ShapeBorder? shape = widget.shape
548 549 550 551 552 553 554 555
      ?? snackBarTheme.shape
      ?? (isFloatingSnackBar ? RoundedRectangleBorder(borderRadius: BorderRadius.circular(4.0)) : null);

    snackBar = Material(
      shape: shape,
      elevation: elevation,
      color: backgroundColor,
      child: Theme(
556
        data: inverseTheme,
557 558 559 560 561 562 563 564 565 566
        child: mediaQueryData.accessibleNavigation
            ? snackBar
            : FadeTransition(
                opacity: fadeOutAnimation,
                child: snackBar,
              ),
      ),
    );

    if (isFloatingSnackBar) {
567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590
      const double topMargin = 5.0;
      const double bottomMargin = 10.0;
      // If width is provided, do not include horizontal margins.
      if (widget.width != null) {
        snackBar = Container(
          margin: const EdgeInsets.only(top: topMargin, bottom: bottomMargin),
          width: widget.width,
          child: snackBar,
        );
      } else {
        const double horizontalMargin = 15.0;
        snackBar = Padding(
          padding: widget.margin ?? const EdgeInsets.fromLTRB(
            horizontalMargin,
            topMargin,
            horizontalMargin,
            bottomMargin,
          ),
          child: snackBar,
        );
      }
      snackBar = SafeArea(
        top: false,
        bottom: false,
591 592 593 594 595
        child: snackBar,
      );
    }

    snackBar = Semantics(
596 597 598
      container: true,
      liveRegion: true,
      onDismiss: () {
599
        Scaffold.of(context).removeCurrentSnackBar(reason: SnackBarClosedReason.dismiss);
600
      },
601
      child: Dismissible(
602
        key: const Key('dismissible'),
603
        direction: widget.dismissDirection,
604 605
        resizeDuration: null,
        onDismissed: (DismissDirection direction) {
606
          Scaffold.of(context).removeCurrentSnackBar(reason: SnackBarClosedReason.swipe);
607
        },
608
        child: snackBar,
609 610
      ),
    );
611

612
    final Widget snackBarTransition;
613 614 615 616 617 618 619 620 621
    if (mediaQueryData.accessibleNavigation) {
      snackBarTransition = snackBar;
    } else if (isFloatingSnackBar) {
      snackBarTransition = FadeTransition(
        opacity: fadeInAnimation,
        child: snackBar,
      );
    } else {
      snackBarTransition = AnimatedBuilder(
622
        animation: heightAnimation,
623
        builder: (BuildContext context, Widget? child) {
624
          return Align(
625
            alignment: AlignmentDirectional.topStart,
626
            heightFactor: heightAnimation.value,
627
            child: child,
628
          );
629
        },
630 631 632
        child: snackBar,
      );
    }
633

634 635
    return Hero(
      tag: '<SnackBar Hero tag - ${widget.content}>',
636
      child: ClipRect(child: snackBarTransition),
637
    );
638
  }
639
}