_platform_io.dart 1.42 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
// 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;

9 10
export 'platform.dart' show TargetPlatform;

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