Repository: flutter
Issue: Scaling Issue with Native UiKitView on External Displays with Different Scale Factors
Labels: platform-mac,a: platform-views,has reproducible steps,team-macos,found in release: 3.27,found in release: 3.29

### Environment:

- MacOS Version: 14.6.1 (23G93)
- Display Configuration: 1728 x 1117 (main), 3820 x 1600 (external)
- Flutter Version: 3.27.3

### Analysis: 
A potential cause of the issue lies within the [FlutterPlatformViewController](https://github.com/flutter/flutter/blob/master/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsController.mm) implementation. It appears the view controller obtains the screenScale from the possibly deprecated [mainScreen](https://developer.apple.com/documentation/uikit/uiscreen/main?language=objc) property. Consequently, the [scaleX](https://github.com/flutter/flutter/blob/74ade4334155a71dbfdfa019af940f3df666e652/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsController.mm#L49) and [scaleY](https://github.com/flutter/flutter/blob/74ade4334155a71dbfdfa019af940f3df666e652/engine/src/flutter/shell/platform/darwin/ios/framework/Source/FlutterPlatformViewsController.mm#L55) values are calculated incorrectly for external displays with a different scale factor. This mismatch results in the observed rendering issues.

### Steps to reproduce

1. Connect a Mac to an external monitor with a different scale factor than the Mac's main display.
2. Run the attached Flutter application on the Mac in iPad mode.
3. Observe the scaling of the UiKitView on the external display.

### Expected results

The `UiKitView` should render at the correct size and scale consistently, regardless of the external monitor's scale factor.

### Actual results

The `UiKitView` scales incorrectly on the external display, as seen in the screenshot provided. The rendered view is noticeably smaller than expected, occupying only a quarter of the expected area.

### Code sample

<details open><summary>Code sample</summary>

https://github.com/ogBurzmali/window_scale_bug

</details>



### Screenshots or Video

<details open>
<summary>Screenshots</summary>

![Image](https://github.com/user-attachments/assets/a6b29a4d-f135-4c84-8ba6-ffac4580f40d)

</details>

### Suggested Fix:
Update the `FlutterPlatformViewController` to use the correct display's `screenScale` when rendering views on external monitors. This may involve dynamically obtaining the scale factor for the specific screen where the `UiKitView` is being displayed, instead of relying on the `mainScreen` property.

### Flutter Doctor output

<details open><summary>Doctor output</summary>

```console
[✓] Flutter (Channel stable, 3.27.3, on macOS 14.6.1 23G93 darwin-arm64, locale en-US)
    • Flutter version 3.27.3 on channel stable at /Users/thomasariston/dev/sdks/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision c519ee916e (3 days ago), 2025-01-21 10:32:23 -0800
    • Engine revision e672b006cb
    • Dart version 3.6.1
    • DevTools version 2.40.2

[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
    • Android SDK at /Users/thomasariston/Library/Android/sdk
    • Platform android-34, build-tools 35.0.0
    • Java binary at: /opt/homebrew/opt/openjdk/bin/java
    • Java version OpenJDK Runtime Environment Homebrew (build 23.0.2)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 16.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 16C5032a
    • CocoaPods version 1.16.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[!] Android Studio (not installed)
    • Android Studio not found; download from https://developer.android.com/studio/index.html
      (or visit https://flutter.dev/to/macos-android-setup for detailed instructions).

[✓] VS Code (version 1.95.3)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.102.0

[✓] Connected device (3 available)
    • macOS (desktop)                 • macos                 • darwin-arm64   • macOS 14.6.1 23G93 darwin-arm64
    • Mac Designed for iPad (desktop) • mac-designed-for-ipad • darwin         • macOS 14.6.1 23G93 darwin-arm64
    • Chrome (web)                    • chrome                • web-javascript • Google Chrome 131.0.6778.265

[✓] Network resources
    • All expected network resources are available.

! Doctor found issues in 1 category.

```

</details>