Repository: flutter
Issue: Attempt to write to field 'int android.view.ViewGroup$LayoutParams.width' on a null object reference in method
Labels: c: crash,platform-android,a: platform-views,a: production,P2,needs repro info,team-android,triaged-android

### Steps to reproduce

There are no steps to reproduce.
Crash came from a user on crashlytics. 
Maybe it's device-specific. The crash happened on **Motorola Moto G32 Android 13**.  
There is the reported issue related to crashlytics plugin with the same stacktrace https://github.com/firebase/flutterfire/issues/12448.

My assumptions:
The issue starts in `platform_views.dart` file next code:
```
final Map<Object?, Object?>? meta = await SystemChannels.platform_views.invokeMapMethod<Object?, Object?>(
      'resize',
      <String, dynamic>{
        'id': viewId,
        'width': size.width,
        'height': size.height,
      },
    );
```

After we go to [PlatformViewsController.java](https://github.com/flutter/engine/blob/3588d31a98f6c2a1949132e1cf610265b04185a1/shell/platform/android/io/flutter/plugin/platform/PlatformViewsController.java#L157) `resize` method.
There is a code where theoretically NPE can happen. Because `getLayoutParams()` can return null object.
```
          final ViewGroup.LayoutParams viewWrapperLayoutParams = viewWrapper.getLayoutParams();
          viewWrapperLayoutParams.width = physicalWidth;
```


### Expected results

Calling `LayoutParams.width` only on the non-null object.

### Actual results

Attempt to write to field 'int android.view.ViewGroup$LayoutParams.width' on a null object reference in method

### Code sample

<details open><summary>Code sample</summary>

```dart
[Paste your code here]
```

</details>


### Screenshots or Video

<details open>
<summary>Screenshots / Video demonstration</summary>

[Upload media here]

</details>


### Logs

<details open><summary>Logs</summary>

```console
Fatal Exception: io.flutter.plugins.firebase.crashlytics.FlutterError: PlatformException(error, Attempt to write to field 'int android.view.ViewGroup$LayoutParams.width' on a null object reference in method 'void io.flutter.plugin.platform.v$a.h(g7.l$e, g7.l$b)', null, java.lang.NullPointerException: Attempt to write to field 'int android.view.ViewGroup$LayoutParams.width' on a null object reference in method 'void io.flutter.plugin.platform.v$a.h(g7.l$e, g7.l$b)'
	at io.flutter.plugin.platform.v$a.h(Unknown Source:125)
	at g7.l$a.h(Unknown Source:59)
	at g7.l$a.c(Unknown Source:167)
	at h7.k$a.a(Unknown Source:17)
	at w6.c.l(Unknown Source:18)
	at w6.c.m(Unknown Source:41)
	at w6.c.i(Unknown Source:0)
	at w6.b.run(Unknown Source:12)
	at android.os.Handler.handleCallback(Handler.java:984)
	at android.os.Handler.dispatchMessage(Handler.java:104)
	at android.os.Looper.loopOnce(Looper.java:238)
	at android.os.Looper.loop(Looper.java:357)
	at android.app.ActivityThread.main(ActivityThread.java:8149)
	at java.lang.reflect.Method.invoke(Native Method)
	at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548)
	at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:957)
)
       at StandardMethodCodec.decodeEnvelope(message_codecs.dart:651)
       at MethodChannel._invokeMethod(platform_channel.dart:334)
       at MethodChannel.invokeMapMethod(platform_channel.dart:534)
       at _TextureAndroidViewControllerInternals.setSize(platform_views.dart:1298)
       at RenderAndroidView._sizePlatformView(platform_view.dart:176)
```

</details>


### Flutter Doctor output

<details open><summary>Doctor output</summary>

```console
[!] Flutter (Channel stable, 3.19.4, on macOS 14.3 23D56 darwin-arm64, locale en-UA)
    • Flutter version 3.19.4 on channel stable at /Users/ymka/development/flutter
    ! Warning: `dart` on your path resolves to /opt/homebrew/Cellar/dart/3.3.0/libexec/bin/dart, which is not inside your current Flutter SDK checkout at /Users/ymka/development/flutter. Consider adding
      /Users/ymka/development/flutter/bin to the front of your path.
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 68bfaea224 (10 days ago), 2024-03-20 15:36:31 -0700
    • Engine revision a5c24f538d
    • Dart version 3.3.2
    • DevTools version 2.31.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/ymka/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • ANDROID_HOME = /Users/ymka/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15C500b
    • CocoaPods version 1.15.2

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2023.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
    • Java version OpenJDK Runtime Environment (build 17.0.9+0-17.0.9b1087.7-11185874)

[✓] IntelliJ IDEA Community Edition (version 2021.2.4)
    • IntelliJ at /Applications/IntelliJ IDEA CE.app
    • 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

[✓] VS Code (version 1.79.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.66.0

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-arm64   • macOS 14.3 23D56 darwin-arm64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 123.0.6312.87

[✓] Network resources
    • All expected network resources are available.
```

</details>