New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Theme.of(context).platform running on web returns macOS instead of iOS when accessed from Safari on iPad #128943
Comments
Thanks for filing this issue @rocboronat . I am able to reproduce this issue when built on web on iPad. |
It seems that the code that Flutter (web) is using to determine the flutter/packages/flutter/lib/src/foundation/_platform_web.dart Lines 42 to 46 in 12f2cbc
Since macOS 13, iPads identify as "MacIntel" and further checks are required to tell them apart from a laptop machine. |
Nuance to consider:
Checked on IPad Air 4 Flutter 3.13.7Flutter 3.13.7 • channel stable • https://github.com/flutter/flutter.git |
Safari and GoogleChrome has different userAgent strings:
As a result, calling the function
code exampleconditionally import file where you want to use it
user_agent_info_web.dart
file user_agent_info.dart is just a stub
|
Thanks for these findings, @nailgilaziev! I updated the issue title and body to match them 👍 |
It'd be nice if this api was more widely supported: https://developer.mozilla.org/en-US/docs/Web/API/User-Agent_Client_Hints_API |
Reproduced this issue on iPad Air 5th, iOS 17.0.3. flutter doctor -v (stable and master)[✓] Flutter (Channel stable, 3.13.9, on macOS 14.1 23B74 darwin-x64, locale en-VN)
• Flutter version 3.13.9 on channel stable at /Users/huynq/Documents/GitHub/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision d211f42860 (11 days ago), 2023-10-25 13:42:25 -0700
• Engine revision 0545f8705d
• Dart version 3.1.5
• DevTools version 2.25.0
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
• Android SDK at /Users/huynq/Library/Android/sdk
• Platform android-34, build-tools 34.0.0
• ANDROID_HOME = /Users/huynq/Library/Android/sdk
• Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 15.0.1)
• Xcode at /Users/huynq/Downloads/Xcode.app/Contents/Developer
• Build 15A507
• CocoaPods version 1.13.0
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2022.3)
• Android Studio at /Applications/Android Studio Giraffe.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)
[✓] Android Studio (version 2022.2)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• android-studio-dir = /Applications/Android Studio.app/
• Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
[✓] VS Code (version 1.84.0)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.76.0
[✓] Connected device (4 available)
• RMX2001 (mobile) • EUYTFEUSQSRGDA6D • android-arm64 • Android 11 (API 30)
• iPhone (mobile) • d9a94afe2b649fef56ba0bfeb052f0f2a7dae95e • ios • iOS 15.7.9 19H365
• macOS (desktop) • macos • darwin-x64 • macOS 14.1 23B74 darwin-x64
• Chrome (web) • chrome • web-javascript • Google Chrome 118.0.5993.117
[✓] Network resources
• All expected network resources are available.
• No issues found! [!] Flutter (Channel master, 3.17.0-5.0.pre.19, on macOS 14.1 23B74 darwin-x64, locale en-VN)
• Flutter version 3.17.0-5.0.pre.19 on channel master at /Users/huynq/Documents/GitHub/flutter_master
! Warning: `flutter` on your path resolves to /Users/huynq/Documents/GitHub/flutter/bin/flutter, which is not inside your current Flutter SDK checkout at /Users/huynq/Documents/GitHub/flutter_master. Consider adding /Users/huynq/Documents/GitHub/flutter_master/bin to the front of your path.
! Warning: `dart` on your path resolves to /Users/huynq/Documents/GitHub/flutter/bin/dart, which is not inside your current Flutter SDK checkout at /Users/huynq/Documents/GitHub/flutter_master. Consider adding /Users/huynq/Documents/GitHub/flutter_master/bin to the front of your path.
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision 2f62af423a (55 minutes ago), 2023-11-08 20:38:07 -0500
• Engine revision 8b490a9f16
• Dart version 3.3.0 (build 3.3.0-107.0.dev)
• DevTools version 2.30.0-dev.1
• If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and upgrades.
[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
• Android SDK at /Users/huynq/Library/Android/sdk
• Platform android-34, build-tools 34.0.0
• ANDROID_HOME = /Users/huynq/Library/Android/sdk
• Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 15.0.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Build 15A507
• CocoaPods version 1.13.0
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 2022.3)
• Android Studio at /Applications/Android Studio Giraffe.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)
[!] Android Studio (version unknown)
• Android Studio at /Applications/Android Studio Preview.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
✗ Unable to determine Android Studio version.
• Java version OpenJDK Runtime Environment (build 17.0.8+0-17.0.8b1000.22-10799086)
[✓] Android Studio (version 2022.2)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• android-studio-dir = /Applications/Android Studio.app/
• Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
[✓] VS Code (version 1.84.0)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.76.0
[✓] Connected device (3 available)
• RMX2001 (mobile) • EUYTFEUSQSRGDA6D • android-arm64 • Android 11 (API 30)
• macOS (desktop) • macos • darwin-x64 • macOS 14.1 23B74 darwin-x64
• Chrome (web) • chrome • web-javascript • Google Chrome 119.0.6045.105
[✓] Network resources
• All expected network resources are available.
! Doctor found issues in 2 categories. |
Reproduced the issue on iPad Pro 4th, iOS 17.2 |
Maybe is related with TargetPlatform? I have this code in my app in any desktop browser it is returning true, in any android return false, so that's ok. But in iOS, tested with an iphone 15 pro and 13 its returning true |
We have slightly different browser detection in the Flutter Web engine; I'm going to try to expose the engine code to the flutter framework, to make the That way, fixes on the source code of the engine will propagate to the framework as well. |
Still not fixed, we need to use the browser detection in the framework. Reopening. |
Hey @ditman, that's excellent news! ❤️ I tried with physical phones and everything works as it should:
Thanks a lot!! 👌 |
Thanks for verifying @rocboronat! I'm breaking a few internal google tests (around 20 thousand 💀), but it seems that the internal system hasn't picked up the engine changes yet. Once it does, I'll see the real extent of the breakage. |
If it was 18 or 19 thousand it wouldn't be that bad... but 20K... let's wait, haha! Thanks a lot fot the effort 🙇 |
(The extent of the breakage is "none", so once it gets reviewed it should land easily) |
> [!IMPORTANT] > Requires the following engine PR: > * flutter/engine#52380 > ---- This PR refactors Flutter `foundation`'s library `platform` for the web with the same code we use to detect platforms in the engine. ## Issues * Fixes: #128943 ## Testing Demo app deployed here: * https://dit-browser-detect.web.app
Is there an existing issue for this?
Steps to reproduce
Theme.of(context).platform
in the middle of the screenIf you want to see the bug by yourself in a quick fashion, for convenience, a website that reproduces the issue has been published here: https://flutterthemeplatform.codemagic.app/
Expected results
It should print
iOS
Actual results
It prints
macOS
Code sample
Code sample
Here's the repo of this code: https://github.com/fewlaps/theme-platform-flutter
Screenshots or Video
Screenshots / Video demonstration
Logs
Logs
Flutter Doctor output
Doctor output
The text was updated successfully, but these errors were encountered: