Commit 2e0e6aa4 authored by Hixie's avatar Hixie

OverlayRoute.finished()

Rather than have delayed calls to super.didPop(), which raises my
eyebrow every time I see it, this provides a separate finished()
function to call, and uses the convention that if you want to call it
yourself, you just don't call super.didPop().
parent 5722c96b
...@@ -153,16 +153,12 @@ class _ModalBottomSheetRoute extends OverlayRoute { ...@@ -153,16 +153,12 @@ class _ModalBottomSheetRoute extends OverlayRoute {
super.didPush(overlay, insertionPoint); super.didPush(overlay, insertionPoint);
} }
void _finish(dynamic result) {
super.didPop(result); // clear the overlay entries
completer.complete(result);
}
void didPop(dynamic result) { void didPop(dynamic result) {
completer.complete(result);
if (performance.isDismissed) if (performance.isDismissed)
_finish(result); finished();
else else
performance.reverse().then((_) { _finish(result); }); performance.reverse().then((_) { finished(); });
} }
Widget _buildModalBarrier(BuildContext context) { Widget _buildModalBarrier(BuildContext context) {
......
...@@ -74,7 +74,7 @@ class _DrawerRoute extends OverlayRoute { ...@@ -74,7 +74,7 @@ class _DrawerRoute extends OverlayRoute {
Navigator.of(context).pop(); Navigator.of(context).pop();
break; break;
case _DrawerState.popped: case _DrawerState.popped:
super.didPop(null); finished();
break; break;
case _DrawerState.closed: case _DrawerState.closed:
assert(false); assert(false);
...@@ -87,6 +87,8 @@ class _DrawerRoute extends OverlayRoute { ...@@ -87,6 +87,8 @@ class _DrawerRoute extends OverlayRoute {
} }
void didPop(dynamic result) { void didPop(dynamic result) {
// we don't call the superclass because we want to control the timing of the
// call to finished().
switch (_state) { switch (_state) {
case _DrawerState.showing: case _DrawerState.showing:
_drawerKey.currentState?._close(); _drawerKey.currentState?._close();
...@@ -96,7 +98,7 @@ class _DrawerRoute extends OverlayRoute { ...@@ -96,7 +98,7 @@ class _DrawerRoute extends OverlayRoute {
assert(false); assert(false);
break; break;
case _DrawerState.closed: case _DrawerState.closed:
super.didPop(null); finished();
break; break;
} }
} }
......
...@@ -45,7 +45,19 @@ abstract class OverlayRoute extends Route { ...@@ -45,7 +45,19 @@ abstract class OverlayRoute extends Route {
} }
} }
// Subclasses shouldn't call this if they want to delay the finished() call.
void didPop(dynamic result) { void didPop(dynamic result) {
finished();
}
/// Clears out the overlay entries.
///
/// This method is intended to be used by subclasses who don't call
/// super.didPop() because they want to have control over the timing of the
/// overlay removal.
///
/// Do not call this method outside of this context.
void finished() {
for (OverlayEntry entry in _overlayEntries) for (OverlayEntry entry in _overlayEntries)
entry.remove(); entry.remove();
_overlayEntries.clear(); _overlayEntries.clear();
...@@ -84,7 +96,7 @@ abstract class TransitionRoute extends OverlayRoute { ...@@ -84,7 +96,7 @@ abstract class TransitionRoute extends OverlayRoute {
overlayEntries.first.opaque = false; overlayEntries.first.opaque = false;
break; break;
case PerformanceStatus.dismissed: case PerformanceStatus.dismissed:
super.didPop(_result); // clear the overlays super.finished(); // clear the overlays
completer?.complete(_result); completer?.complete(_result);
break; break;
} }
......
...@@ -36,13 +36,14 @@ void main() { ...@@ -36,13 +36,14 @@ void main() {
tester.pump(); // bottom sheet show animation starts tester.pump(); // bottom sheet show animation starts
tester.pump(new Duration(seconds: 1)); // animation done tester.pump(new Duration(seconds: 1)); // animation done
expect(tester.findText('BottomSheet'), isNotNull); expect(tester.findText('BottomSheet'), isNotNull);
expect(showBottomSheetThenCalled, isFalse);
// Tap on the the bottom sheet itself to dismiss it // Tap on the the bottom sheet itself to dismiss it
tester.tap(tester.findText('BottomSheet')); tester.tap(tester.findText('BottomSheet'));
tester.pump(); // bottom sheet dismiss animation starts tester.pump(); // bottom sheet dismiss animation starts
expect(showBottomSheetThenCalled, isTrue);
tester.pump(new Duration(seconds: 1)); // last frame of animation (sheet is entirely off-screen, but still present) tester.pump(new Duration(seconds: 1)); // last frame of animation (sheet is entirely off-screen, but still present)
tester.pump(new Duration(seconds: 1)); // frame after the animation (sheet has been removed) tester.pump(new Duration(seconds: 1)); // frame after the animation (sheet has been removed)
expect(showBottomSheetThenCalled, isTrue);
expect(tester.findText('BottomSheet'), isNull); expect(tester.findText('BottomSheet'), isNull);
showModalBottomSheet(context: context, builder: (BuildContext context) => new Text('BottomSheet')); showModalBottomSheet(context: context, builder: (BuildContext context) => new Text('BottomSheet'));
......
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