From 92df6f50b206c929d29f9cb58493717881aa6279 Mon Sep 17 00:00:00 2001 From: Ferhat Date: Fri, 1 May 2020 12:04:35 -0700 Subject: [PATCH] Add check for iOS/MacOS for target platform (#56081) --- .../lib/src/foundation/_platform_web.dart | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/packages/flutter/lib/src/foundation/_platform_web.dart b/packages/flutter/lib/src/foundation/_platform_web.dart index 1e284e3088..889abd8ffc 100644 --- a/packages/flutter/lib/src/foundation/_platform_web.dart +++ b/packages/flutter/lib/src/foundation/_platform_web.dart @@ -2,6 +2,7 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. +import 'dart:html' as html; import 'platform.dart' as platform; /// The dart:html implementation of [platform.defaultTargetPlatform]. @@ -9,8 +10,21 @@ platform.TargetPlatform get defaultTargetPlatform { // To getter a better guess at the targetPlatform we need to be able to // reference the window, but that won't be availible until we fix the // platforms configuration for Flutter. - platform.TargetPlatform result = platform.TargetPlatform.android; + platform.TargetPlatform result = _browserPlatform(); if (platform.debugDefaultTargetPlatformOverride != null) result = platform.debugDefaultTargetPlatformOverride; return result; } + +platform.TargetPlatform _browserPlatform() { + final String navigatorPlatform = html.window.navigator.platform.toLowerCase(); + if (navigatorPlatform.startsWith('mac')) { + return platform.TargetPlatform.macOS; + } + if (navigatorPlatform.contains('iphone') || + navigatorPlatform.contains('ipad') || + navigatorPlatform.contains('ipod')) { + return platform.TargetPlatform.iOS; + } + return platform.TargetPlatform.android; +}