postTest method Null safety

void postTest()

Called by the testWidgets function after a test is executed.

Implementation

void postTest() {
  assert(inTest);
  FlutterError.onError = _oldExceptionHandler;
  FlutterError.demangleStackTrace = _oldStackTraceDemangler;
  _pendingExceptionDetails = null;
  _parentZone = null;
  buildOwner!.focusManager.dispose();

  if (TestDefaultBinaryMessengerBinding.instance!.defaultBinaryMessenger
      .checkMockMessageHandler(
          SystemChannels.accessibility.name, _announcementHandler)) {
    TestDefaultBinaryMessengerBinding.instance!.defaultBinaryMessenger
        .setMockDecodedMessageHandler(SystemChannels.accessibility, null);
    _announcementHandler = null;
  }
  _announcements = <CapturedAccessibilityAnnouncement>[];

  ServicesBinding.instance.keyEventManager.keyMessageHandler = null;
  buildOwner!.focusManager = FocusManager()..registerGlobalHandlers();

  // Disabling the warning because @visibleForTesting doesn't take the testing
  // framework itself into account, but we don't want it visible outside of
  // tests.
  // ignore: invalid_use_of_visible_for_testing_member
  RawKeyboard.instance.clearKeysPressed();
  // ignore: invalid_use_of_visible_for_testing_member
  HardwareKeyboard.instance.clearState();
  // ignore: invalid_use_of_visible_for_testing_member
  keyEventManager.clearState();
  // ignore: invalid_use_of_visible_for_testing_member
  RendererBinding.instance.initMouseTracker();
}