@@ -15,6 +15,7 @@ import 'package:flutter/services.dart';
15
15
import 'package:flutter/widgets.dart' ;
16
16
import 'package:stack_trace/stack_trace.dart' as stack_trace;
17
17
import 'package:test_api/expect.dart' show fail;
18
+ import 'package:test_api/scaffolding.dart' ; // ignore: deprecated_member_use
18
19
import 'package:test_api/test_api.dart' as test_package show Timeout; // ignore: deprecated_member_use
19
20
import 'package:vector_math/vector_math_64.dart' ;
20
21
@@ -919,6 +920,13 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
919
920
// So that we can assert that it remains the same after the test finishes.
920
921
_beforeTestCheckIntrinsicSizes = debugCheckIntrinsicSizes;
921
922
923
+ bool shouldTearDownVerifyInvariants = false ;
924
+ addTearDown (() {
925
+ if (shouldTearDownVerifyInvariants) {
926
+ _verifyTearDownInvariants ();
927
+ }
928
+ });
929
+
922
930
runApp (Container (key: UniqueKey (), child: _preTestMessage)); // Reset the tree to a known state.
923
931
await pump ();
924
932
// Pretend that the first frame produced in the test body is the first frame
@@ -949,6 +957,7 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
949
957
_verifyErrorWidgetBuilderUnset (errorWidgetBuilderBeforeTest);
950
958
_verifyShouldPropagateDevicePointerEventsUnset (shouldPropagateDevicePointerEventsBeforeTest);
951
959
_verifyInvariants ();
960
+ shouldTearDownVerifyInvariants = true ;
952
961
}
953
962
954
963
assert (inTest);
@@ -958,6 +967,11 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
958
967
late bool _beforeTestCheckIntrinsicSizes;
959
968
960
969
void _verifyInvariants () {
970
+ // subclasses such as AutomatedTestWidgetsFlutterBinding overrides this
971
+ // to perform more verifications.
972
+ }
973
+
974
+ void _verifyTearDownInvariants () {
961
975
assert (debugAssertNoTransientCallbacks (
962
976
'An animation is still running even after the widget tree was disposed.'
963
977
));
0 commit comments