_platform_io.dart 1.36 KB
Newer Older
Ian Hickson's avatar
Ian Hickson committed
1
// Copyright 2014 The Flutter Authors. All rights reserved.
2 3 4 5 6 7 8 9 10
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'dart:io';
import 'assertions.dart';
import 'platform.dart' as platform;

/// The dart:io implementation of [platform.defaultTargetPlatform].
platform.TargetPlatform get defaultTargetPlatform {
11
  platform.TargetPlatform? result;
12
  if (Platform.isAndroid) {
13
    result = platform.TargetPlatform.android;
14 15
  } else if (Platform.isIOS) {
    result = platform.TargetPlatform.iOS;
16 17
  } else if (Platform.isFuchsia) {
    result = platform.TargetPlatform.fuchsia;
18 19 20 21 22 23
  } else if (Platform.isLinux) {
    result = platform.TargetPlatform.linux;
  } else if (Platform.isMacOS) {
    result = platform.TargetPlatform.macOS;
  } else if (Platform.isWindows) {
    result = platform.TargetPlatform.windows;
24 25 26 27 28 29 30 31 32 33 34 35
  }
  assert(() {
    if (Platform.environment.containsKey('FLUTTER_TEST'))
      result = platform.TargetPlatform.android;
    return true;
  }());
  if (platform.debugDefaultTargetPlatformOverride != null)
    result = platform.debugDefaultTargetPlatformOverride;
  if (result == null) {
    throw FlutterError(
      'Unknown platform.\n'
      '${Platform.operatingSystem} was not recognized as a target platform. '
36
      'Consider updating the list of TargetPlatforms to include this platform.',
37 38
    );
  }
39
  return result!;
40
}