overrideCorrectTargetPlatform function

  1. @visibleForTesting
void overrideCorrectTargetPlatform()

Override defaultTargetPlatform to correct TargetPlatform during test.

Since defaultTargetPlatform will return TargetPlatform.android when executing Flutter test that device_vendor_info should throw UnsupportedError. This MUST BE called in setUpAll as immediate as possible.

void main() {
  setUpAll(() {
    overrideCorrectTargetPlatform();
  });

  // Writing test below
}

Implementation

@visibleForTesting
void overrideCorrectTargetPlatform() {
  if (Platform.isWindows) {
    debugDefaultTargetPlatformOverride = TargetPlatform.windows;
  }

  if (Platform.isMacOS) {
    debugDefaultTargetPlatformOverride = TargetPlatform.macOS;
  }

  if (Platform.isLinux) {
    debugDefaultTargetPlatformOverride = TargetPlatform.linux;
  }
}