From 0f68a2bac2490bf3215d2adc154f29f49fce0f96 Mon Sep 17 00:00:00 2001 From: Adam Barth Date: Mon, 25 Jul 2016 17:05:41 -0700 Subject: [PATCH] Be more explicit about the default TargetPlatform (#5034) --- .../flutter/lib/src/foundation/platform.dart | 17 +++++++++++++++++ .../flutter/lib/src/material/theme_data.dart | 3 +-- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/packages/flutter/lib/src/foundation/platform.dart b/packages/flutter/lib/src/foundation/platform.dart index 01bd4892e0..3881055e19 100644 --- a/packages/flutter/lib/src/foundation/platform.dart +++ b/packages/flutter/lib/src/foundation/platform.dart @@ -2,6 +2,10 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import 'dart:io' show Platform; + +import 'assertions.dart'; + /// The platform that user interaction should adapt to target. enum TargetPlatform { /// Android: @@ -10,3 +14,16 @@ enum TargetPlatform { /// iOS: iOS, } + +/// The [TargetPlatform] that matches the platform on which the framework is currently executing. +TargetPlatform get defaultTargetPlatform { + if (Platform.isIOS || Platform.isMacOS) + return TargetPlatform.iOS; + if (Platform.isAndroid || Platform.isLinux) + return TargetPlatform.android; + 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.' + ); +} diff --git a/packages/flutter/lib/src/material/theme_data.dart b/packages/flutter/lib/src/material/theme_data.dart index 78241fba95..3a9efc3bc7 100644 --- a/packages/flutter/lib/src/material/theme_data.dart +++ b/packages/flutter/lib/src/material/theme_data.dart @@ -2,7 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -import 'dart:io' show Platform; import 'dart:ui' show Color, hashValues; import 'package:flutter/foundation.dart'; @@ -125,7 +124,7 @@ class ThemeData { primaryTextTheme ??= primaryIsDark ? Typography.white : Typography.black; iconTheme ??= isDark ? const IconThemeData(color: Colors.white) : const IconThemeData(color: Colors.black); primaryIconTheme ??= primaryIsDark ? const IconThemeData(color: Colors.white) : const IconThemeData(color: Colors.black); - platform ??= (Platform.isIOS || Platform.isMacOS) ? TargetPlatform.iOS : TargetPlatform.android; + platform ??= defaultTargetPlatform; return new ThemeData.raw( brightness: brightness, primaryColor: primaryColor,