Skip to content

Commit 4d38f94

Browse files
authored
ModalBarrier's gesture recognizer does not call invokeCallback (#125386)
Close #125385 - please see explanations there :) If you think this PR looks OK, I will polish it (e.g. copy-and-paste-and-modify the tests shown in #125385 into here and make CI pass)
1 parent 110fe75 commit 4d38f94

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

packages/flutter/lib/src/widgets/modal_barrier.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -394,7 +394,9 @@ class _AnyTapGestureRecognizer extends BaseTapGestureRecognizer {
394394
@protected
395395
@override
396396
void handleTapUp({PointerDownEvent? down, PointerUpEvent? up}) {
397-
onAnyTapUp?.call();
397+
if (onAnyTapUp != null) {
398+
invokeCallback('onAnyTapUp', onAnyTapUp!);
399+
}
398400
}
399401

400402
@protected

packages/flutter/test/widgets/modal_barrier_test.dart

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
import 'package:flutter/foundation.dart';
56
import 'package:flutter/gestures.dart' show PointerDeviceKind, kSecondaryButton;
67
import 'package:flutter/material.dart';
78
import 'package:flutter/rendering.dart';
@@ -399,6 +400,29 @@ void main() {
399400
expect(dismissCallbackCalled, true);
400401
});
401402

403+
testWidgets('when onDismiss throws, should have correct context', (WidgetTester tester) async {
404+
final FlutterExceptionHandler? handler = FlutterError.onError;
405+
FlutterErrorDetails? error;
406+
FlutterError.onError = (FlutterErrorDetails details) {
407+
error = details;
408+
};
409+
410+
final UniqueKey barrierKey = UniqueKey();
411+
await tester.pumpWidget(MaterialApp(
412+
home: Scaffold(
413+
body: ModalBarrier(
414+
key: barrierKey,
415+
onDismiss: () => throw Exception('deliberate'),
416+
),
417+
),
418+
));
419+
await tester.tap(find.byKey(barrierKey));
420+
await tester.pump();
421+
422+
expect(error?.context.toString(), contains('handling a gesture'));
423+
FlutterError.onError = handler;
424+
});
425+
402426
testWidgets('will not pop when given an onDismiss callback', (WidgetTester tester) async {
403427
final Map<String, WidgetBuilder> routes = <String, WidgetBuilder>{
404428
'/': (BuildContext context) => const FirstWidget(),

0 commit comments

Comments
 (0)