Commit a7d2f835 authored by Mehmet Fidanboylu's avatar Mehmet Fidanboylu Committed by GitHub

Notify the completer after the close animation completes on the snackbar (#11688)

* Notify the completer after the close animation completes on the snackbar

* Review comments

* Fix tests and analyzer warnings

* Fix analyzer warnings
parent 6aae6764
......@@ -605,14 +605,18 @@ class ScaffoldState extends State<Scaffold> with TickerProviderStateMixin {
}
/// Removes the current [SnackBar] by running its normal exit animation.
///
/// The closed completer is called after the animation is complete.
void hideCurrentSnackBar({ SnackBarClosedReason reason: SnackBarClosedReason.hide }) {
assert(reason != null);
if (_snackBars.isEmpty || _snackBarController.status == AnimationStatus.dismissed)
return;
final Completer<SnackBarClosedReason> completer = _snackBars.first._completer;
_snackBarController.reverse().then<Null>((Null _) {
assert(mounted);
if (!completer.isCompleted)
completer.complete(reason);
_snackBarController.reverse();
});
_snackBarTimer?.cancel();
_snackBarTimer = null;
}
......
......@@ -374,7 +374,11 @@ void main() {
expect(actionPressed, isFalse);
await tester.tap(find.text('ACTION'));
expect(actionPressed, isTrue);
await tester.pump(const Duration(seconds: 1));
// Closed reason is only set when the animation is complete.
await tester.pump(const Duration(milliseconds:250));
expect(closedReason, isNull);
// Wait for animation to complete.
await tester.pumpAndSettle(const Duration(seconds: 1));
expect(closedReason, equals(SnackBarClosedReason.action));
// Pop up the snack bar and then swipe downwards to dismiss it.
......@@ -382,21 +386,21 @@ void main() {
await tester.pump(const Duration(milliseconds: 750));
await tester.pump(const Duration(milliseconds: 750));
await tester.drag(find.text('snack'), const Offset(0.0, 50.0));
await tester.pump();
await tester.pumpAndSettle(const Duration(seconds: 1));
expect(closedReason, equals(SnackBarClosedReason.swipe));
// Pop up the snack bar and then remove it.
await tester.tap(find.text('X'));
await tester.pump(const Duration(milliseconds: 750));
scaffoldKey.currentState.removeCurrentSnackBar();
await tester.pump(const Duration(seconds: 1));
await tester.pumpAndSettle(const Duration(seconds: 1));
expect(closedReason, equals(SnackBarClosedReason.remove));
// Pop up the snack bar and then hide it.
await tester.tap(find.text('X'));
await tester.pump(const Duration(milliseconds: 750));
scaffoldKey.currentState.hideCurrentSnackBar();
await tester.pump(const Duration(seconds: 1));
await tester.pumpAndSettle(const Duration(seconds: 1));
expect(closedReason, equals(SnackBarClosedReason.hide));
// Pop up the snack bar and then let it time out.
......@@ -405,7 +409,7 @@ void main() {
await tester.pump(const Duration(milliseconds: 750));
await tester.pump(const Duration(milliseconds: 1500));
await tester.pump(); // begin animation
await tester.pump(const Duration(milliseconds: 750));
await tester.pumpAndSettle(const Duration(seconds: 1));
expect(closedReason, equals(SnackBarClosedReason.timeout));
});
......
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