|
2 | 2 | // Use of this source code is governed by a BSD-style license that can be |
3 | 3 | // found in the LICENSE file. |
4 | 4 |
|
| 5 | +import 'package:flutter/foundation.dart'; |
5 | 6 | import 'package:flutter/gestures.dart' show PointerDeviceKind, kSecondaryButton; |
6 | 7 | import 'package:flutter/material.dart'; |
7 | 8 | import 'package:flutter/rendering.dart'; |
@@ -399,6 +400,29 @@ void main() { |
399 | 400 | expect(dismissCallbackCalled, true); |
400 | 401 | }); |
401 | 402 |
|
| 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 | + |
402 | 426 | testWidgets('will not pop when given an onDismiss callback', (WidgetTester tester) async { |
403 | 427 | final Map<String, WidgetBuilder> routes = <String, WidgetBuilder>{ |
404 | 428 | '/': (BuildContext context) => const FirstWidget(), |
|
0 commit comments