runApp inside onPressed throws an exception (#4419)

We were trying to unregister the pointer route twice. Now we only unregister it
once.

Fixes #4341
This commit is contained in:
Adam Barth 2016-06-07 13:45:06 -07:00
parent 5af67e1592
commit 69ce7f6984
3 changed files with 30 additions and 11 deletions

View File

@ -212,7 +212,7 @@ abstract class DragGestureRecognizer extends OneSequenceGestureRecognizer {
@override
void rejectGesture(int pointer) {
ensureNotTrackingPointer(pointer);
stopTrackingPointer(pointer);
}
@override

View File

@ -114,16 +114,12 @@ abstract class OneSequenceGestureRecognizer extends GestureRecognizer {
///
/// Use [startTrackingPointer] to add the routes in the first place.
void stopTrackingPointer(int pointer) {
GestureBinding.instance.pointerRouter.removeRoute(pointer, handleEvent);
_trackedPointers.remove(pointer);
if (_trackedPointers.isEmpty)
didStopTrackingLastPointer(pointer);
}
/// Calls [stopTrackingPointer] if the pointer with the given ID is being tracked by this recognizer.
void ensureNotTrackingPointer(int pointer) {
if (_trackedPointers.contains(pointer))
stopTrackingPointer(pointer);
if (_trackedPointers.contains(pointer)) {
GestureBinding.instance.pointerRouter.removeRoute(pointer, handleEvent);
_trackedPointers.remove(pointer);
if (_trackedPointers.isEmpty)
didStopTrackingLastPointer(pointer);
}
}
/// Stops tracking the pointer associated with the given event if the event is

View File

@ -0,0 +1,23 @@
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import 'package:flutter/material.dart';
import 'package:flutter_test/flutter_test.dart';
void main() {
testWidgets('runApp inside onPressed does not throw', (WidgetTester tester) async {
await tester.pumpWidget(
new Material(
child: new RaisedButton(
onPressed: () {
runApp(new Center(child: new Text('Done')));
},
child: new Text('GO')
)
)
);
await tester.tap(find.text('GO'));
expect(find.text('Done'), findsOneWidget);
});
}