Changed duration (#19015)
* Changed duration * Fixed column width for ios build error messages * fixed a couple things * fixed a couple things * accidental changes * added spaces * added spaces * Added test for default snackbar duration * Fixed link: * Final commit * Final commit2 * Actual final commit
This commit is contained in:
@@ -11,7 +11,6 @@ import 'scaffold.dart';
|
||||
import 'theme.dart';
|
||||
import 'theme_data.dart';
|
||||
|
||||
// https://material.google.com/components/snackbars-toasts.html#snackbars-toasts-specs
|
||||
const double _kSnackBarPadding = 24.0;
|
||||
const double _kSingleLineVerticalPadding = 14.0;
|
||||
const Color _kSnackBackground = const Color(0xFF323232);
|
||||
@@ -23,7 +22,7 @@ const Color _kSnackBackground = const Color(0xFF323232);
|
||||
// TODO(ianh): Implement the Tablet version of snackbar if we're "on a tablet".
|
||||
|
||||
const Duration _kSnackBarTransitionDuration = const Duration(milliseconds: 250);
|
||||
const Duration _kSnackBarDisplayDuration = const Duration(milliseconds: 1500);
|
||||
const Duration _kSnackBarDisplayDuration = const Duration(milliseconds: 4000);
|
||||
const Curve _snackBarHeightCurve = Curves.fastOutSlowIn;
|
||||
const Curve _snackBarFadeCurve = const Interval(0.72, 1.0, curve: Curves.fastOutSlowIn);
|
||||
|
||||
@@ -71,7 +70,7 @@ enum SnackBarClosedReason {
|
||||
/// See also:
|
||||
///
|
||||
/// * [SnackBar]
|
||||
/// * <https://material.google.com/components/snackbars-toasts.html>
|
||||
/// * <https://material.io/design/components/snackbars.html>
|
||||
class SnackBarAction extends StatefulWidget {
|
||||
/// Creates an action for a [SnackBar].
|
||||
///
|
||||
@@ -136,7 +135,7 @@ class _SnackBarActionState extends State<SnackBarAction> {
|
||||
/// 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.io/design/components/snackbars.html>
|
||||
class SnackBar extends StatelessWidget {
|
||||
/// Creates a snack bar.
|
||||
///
|
||||
@@ -169,14 +168,14 @@ class SnackBar extends StatelessWidget {
|
||||
|
||||
/// The amount of time the snack bar should be displayed.
|
||||
///
|
||||
/// Defaults to 1.5s.
|
||||
/// Defaults to 4.0s.
|
||||
///
|
||||
/// 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>
|
||||
/// * <https://material.io/design/components/snackbars.html>
|
||||
final Duration duration;
|
||||
|
||||
/// The animation driving the entrance and exit of the snack bar.
|
||||
|
||||
@@ -482,4 +482,52 @@ void main() {
|
||||
expect(closedReason, equals(SnackBarClosedReason.timeout));
|
||||
});
|
||||
|
||||
testWidgets('SnackBar default display duration test', (WidgetTester tester) async {
|
||||
const String helloSnackBar = 'Hello SnackBar';
|
||||
const Key tapTarget = const Key('tap-target');
|
||||
await tester.pumpWidget(new MaterialApp(
|
||||
home: new Scaffold(
|
||||
body: new Builder(
|
||||
builder: (BuildContext context) {
|
||||
return new GestureDetector(
|
||||
onTap: () {
|
||||
Scaffold.of(context).showSnackBar(const SnackBar(
|
||||
content: const Text(helloSnackBar)
|
||||
));
|
||||
},
|
||||
behavior: HitTestBehavior.opaque,
|
||||
child: new Container(
|
||||
height: 100.0,
|
||||
width: 100.0,
|
||||
key: tapTarget
|
||||
)
|
||||
);
|
||||
}
|
||||
)
|
||||
)
|
||||
));
|
||||
expect(find.text(helloSnackBar), findsNothing);
|
||||
await tester.tap(find.byKey(tapTarget));
|
||||
expect(find.text(helloSnackBar), findsNothing);
|
||||
await tester.pump(); // schedule animation
|
||||
expect(find.text(helloSnackBar), findsOneWidget);
|
||||
await tester.pump(); // begin animation
|
||||
expect(find.text(helloSnackBar), findsOneWidget);
|
||||
await tester.pump(const Duration(milliseconds: 750)); // 0.75s // animation last frame; four second timer starts here
|
||||
expect(find.text(helloSnackBar), findsOneWidget);
|
||||
await tester.pump(const Duration(milliseconds: 750)); // 1.50s
|
||||
expect(find.text(helloSnackBar), findsOneWidget);
|
||||
await tester.pump(const Duration(milliseconds: 750)); // 2.25s
|
||||
expect(find.text(helloSnackBar), findsOneWidget);
|
||||
await tester.pump(const Duration(milliseconds: 750)); // 3.00s
|
||||
expect(find.text(helloSnackBar), findsOneWidget);
|
||||
await tester.pump(const Duration(milliseconds: 750)); // 3.75s
|
||||
expect(find.text(helloSnackBar), findsOneWidget);
|
||||
await tester.pump(const Duration(milliseconds: 1000)); // 4.75s // timer triggers to dismiss snackbar, reverse animation is scheduled
|
||||
await tester.pump(); // begin animation
|
||||
expect(find.text(helloSnackBar), findsOneWidget); // frame 0 of dismiss animation
|
||||
await tester.pump(const Duration(milliseconds: 750)); // 5.50s // last frame of animation, snackbar removed from build
|
||||
expect(find.text(helloSnackBar), findsNothing);
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user