@@ -15,6 +15,7 @@ import 'package:flutter/services.dart';
1515import 'package:flutter/widgets.dart' ;
1616import 'package:stack_trace/stack_trace.dart' as stack_trace;
1717import 'package:test_api/expect.dart' show fail;
18+ import 'package:test_api/scaffolding.dart' ; // ignore: deprecated_member_use
1819import 'package:test_api/test_api.dart' as test_package show Timeout; // ignore: deprecated_member_use
1920import 'package:vector_math/vector_math_64.dart' ;
2021
@@ -919,6 +920,13 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
919920 // So that we can assert that it remains the same after the test finishes.
920921 _beforeTestCheckIntrinsicSizes = debugCheckIntrinsicSizes;
921922
923+ bool shouldTearDownVerifyInvariants = false ;
924+ addTearDown (() {
925+ if (shouldTearDownVerifyInvariants) {
926+ _verifyTearDownInvariants ();
927+ }
928+ });
929+
922930 runApp (Container (key: UniqueKey (), child: _preTestMessage)); // Reset the tree to a known state.
923931 await pump ();
924932 // Pretend that the first frame produced in the test body is the first frame
@@ -949,6 +957,7 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
949957 _verifyErrorWidgetBuilderUnset (errorWidgetBuilderBeforeTest);
950958 _verifyShouldPropagateDevicePointerEventsUnset (shouldPropagateDevicePointerEventsBeforeTest);
951959 _verifyInvariants ();
960+ shouldTearDownVerifyInvariants = true ;
952961 }
953962
954963 assert (inTest);
@@ -958,6 +967,11 @@ abstract class TestWidgetsFlutterBinding extends BindingBase
958967 late bool _beforeTestCheckIntrinsicSizes;
959968
960969 void _verifyInvariants () {
970+ // subclasses such as AutomatedTestWidgetsFlutterBinding overrides this
971+ // to perform more verifications.
972+ }
973+
974+ void _verifyTearDownInvariants () {
961975 assert (debugAssertNoTransientCallbacks (
962976 'An animation is still running even after the widget tree was disposed.'
963977 ));
0 commit comments