Commit f0825a82 authored by Hans Muller's avatar Hans Muller

Merge pull request #342 from HansMuller/stocks_menu_bug

Fix Dialog and PopupMenu completion logic

It's now (just) in TransitionRoute.

Added smoke tests for showMenu() and showDialog().

Fixes #337
parents 1eb67420 45e12116
...@@ -116,9 +116,8 @@ class Dialog extends StatelessComponent { ...@@ -116,9 +116,8 @@ class Dialog extends StatelessComponent {
} }
class _DialogRoute extends ModalRoute { class _DialogRoute extends ModalRoute {
_DialogRoute({ this.completer, this.child }); _DialogRoute({ Completer completer, this.child }) : super(completer: completer);
final Completer completer;
final Widget child; final Widget child;
bool get opaque => false; bool get opaque => false;
...@@ -132,11 +131,6 @@ class _DialogRoute extends ModalRoute { ...@@ -132,11 +131,6 @@ class _DialogRoute extends ModalRoute {
child: child child: child
); );
} }
void didPop([dynamic result]) {
completer.complete(result);
super.didPop(result);
}
} }
Future showDialog({ BuildContext context, Widget child }) { Future showDialog({ BuildContext context, Widget child }) {
......
...@@ -93,9 +93,8 @@ class _PopupMenu extends StatelessComponent { ...@@ -93,9 +93,8 @@ class _PopupMenu extends StatelessComponent {
} }
class _MenuRoute extends ModalRoute { class _MenuRoute extends ModalRoute {
_MenuRoute({ this.completer, this.position, this.items, this.level }); _MenuRoute({ Completer completer, this.position, this.items, this.level }) : super(completer: completer);
final Completer completer;
final ModalPosition position; final ModalPosition position;
final List<PopupMenuItem> items; final List<PopupMenuItem> items;
final int level; final int level;
...@@ -112,11 +111,6 @@ class _MenuRoute extends ModalRoute { ...@@ -112,11 +111,6 @@ class _MenuRoute extends ModalRoute {
Duration get transitionDuration => _kMenuDuration; Duration get transitionDuration => _kMenuDuration;
Widget buildModalWidget(BuildContext context) => new _PopupMenu(route: this); Widget buildModalWidget(BuildContext context) => new _PopupMenu(route: this);
void didPop([dynamic result]) {
completer.complete(result);
super.didPop(result);
}
} }
Future showMenu({ BuildContext context, ModalPosition position, List<PopupMenuItem> items, int level: 4 }) { Future showMenu({ BuildContext context, ModalPosition position, List<PopupMenuItem> items, int level: 4 }) {
......
...@@ -2,6 +2,8 @@ ...@@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
import 'dart:async';
import 'package:flutter/animation.dart'; import 'package:flutter/animation.dart';
import 'basic.dart'; import 'basic.dart';
...@@ -103,6 +105,8 @@ class ModalPosition { ...@@ -103,6 +105,8 @@ class ModalPosition {
} }
abstract class ModalRoute extends TransitionRoute { abstract class ModalRoute extends TransitionRoute {
ModalRoute({ Completer completer }) : super(completer: completer);
ModalPosition get position => null; ModalPosition get position => null;
Color get barrierColor => _kTransparent; Color get barrierColor => _kTransparent;
Widget buildModalWidget(BuildContext context); Widget buildModalWidget(BuildContext context);
......
...@@ -78,7 +78,8 @@ abstract class TransitionRoute extends OverlayRoute { ...@@ -78,7 +78,8 @@ abstract class TransitionRoute extends OverlayRoute {
overlayEntries.first.opaque = false; overlayEntries.first.opaque = false;
break; break;
case PerformanceStatus.dismissed: case PerformanceStatus.dismissed:
super.didPop(_result); super.didPop(_result); // clear the overlays
completer?.complete(_result);
break; break;
} }
} }
...@@ -92,10 +93,7 @@ abstract class TransitionRoute extends OverlayRoute { ...@@ -92,10 +93,7 @@ abstract class TransitionRoute extends OverlayRoute {
void didPop(dynamic result) { void didPop(dynamic result) {
_result = result; _result = result;
if (completer != null) _performance.reverse();
_performance.reverse().then((_) { completer.complete(_result); });
else
_performance.reverse();
} }
String get debugLabel => '$runtimeType'; String get debugLabel => '$runtimeType';
......
...@@ -40,14 +40,20 @@ void main() { ...@@ -40,14 +40,20 @@ void main() {
} }
)); ));
// TODO(hansmuller): find a way to avoid calling pump over and over.
// https://github.com/flutter/flutter/issues/348
tester.tap(tester.findElementByKey(tapTarget)); tester.tap(tester.findElementByKey(tapTarget));
expect(tester.findText(helloSnackBar), isNull); expect(tester.findText(helloSnackBar), isNull);
tester.pump(); tester.pump(new Duration(seconds: 1));
tester.pump(new Duration(seconds: 1));
expect(tester.findText(helloSnackBar), isNotNull); expect(tester.findText(helloSnackBar), isNotNull);
Navigator.of(context).pop(); Navigator.of(context).pop();
expect(tester.findText(helloSnackBar), isNotNull); expect(tester.findText(helloSnackBar), isNotNull);
tester.pump(new Duration(seconds: 1)); tester.pump(new Duration(seconds: 1));
tester.pump(new Duration(seconds: 1));
tester.pump(new Duration(seconds: 1));
expect(showSnackBarThenCalled, isTrue); expect(showSnackBarThenCalled, isTrue);
expect(tester.findText(helloSnackBar), isNull); expect(tester.findText(helloSnackBar), isNull);
expect(placeholderKey.currentState.child, isNull); expect(placeholderKey.currentState.child, isNull);
......
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