defaultTargetPlatform top-level property

TargetPlatform defaultTargetPlatform

The TargetPlatform that matches the platform on which the framework is currently executing.

In a test environment, the platform returned is regardless of the host platform. (Android was chosen because the tests were originally written assuming Android-like behavior, and we added platform adaptations for iOS later). Tests can check iOS behavior by using the platform override APIs (such as ThemeData.platform in the material library) or by setting debugDefaultTargetPlatformOverride. The value can only be explicitly set in debug mode.


TargetPlatform get defaultTargetPlatform {
  TargetPlatform result;
  if (Platform.isIOS || Platform.isMacOS) {
    result = TargetPlatform.iOS;
  } else if (Platform.isAndroid || Platform.isLinux) {
    result =;
  } else if (Platform.operatingSystem == 'fuchsia') {
    result = TargetPlatform.fuchsia;
  assert(() {
    if (Platform.environment.containsKey('FLUTTER_TEST'))
      result =;
    if (debugDefaultTargetPlatformOverride != null)
      result = debugDefaultTargetPlatformOverride;
    return true;
  if (result == null) {
    throw new FlutterError(
      'Unknown platform.\n'
      '${Platform.operatingSystem} was not recognized as a target platform. '
      'Consider updating the list of TargetPlatforms to include this platform.'
  return result;