Repository: flutter
Issue: [Web] ServicesBinding command 'flutter/assets' does not return null when asset does not exist in web release mode
Labels: engine,a: assets,platform-web,a: release,has reproducible steps,P2,team-web,triaged-web,found in release: 3.13,found in release: 3.17

### Is there an existing issue for this?

- [X] I have searched the [existing issues](https://github.com/flutter/flutter/issues)
- [X] I have read the [guide to filing a bug](https://flutter.dev/docs/resources/bug-reports)

### Steps to reproduce

Call the ServicesBinding to get asset ('flutter/assets') with a asset path don't exist.
```dart
ServicesBinding.instance.defaultBinaryMessenger.send(
      'flutter/assets',
      encoded.buffer.asByteData(),
    )
```

Normally the call return null value but in case of web release, the function return an html file.

flutter run -d chrome --release



### Expected results

Normally if the asset not exist the ServicesBinding call return null
```dart
ServicesBinding.instance.defaultBinaryMessenger.send(
      'flutter/assets',
      encoded.buffer.asByteData(),
    )
```

### Actual results

In the case of release mode in web the ServicesBinding call return an html page (look like index.html of projet)
```html
<!DOCTYPE html>
<html>
<head>
  <!--
    If you are serving your web app in a path other than the root, change the
    href value below to reflect the base path you are serving from.

    The path provided below has to start and end with a slash "/" in order for
    it to work correctly.

    For more details:
    * https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base

    This is a placeholder for base href that will be replaced by the value of
    the `--base-href` argument provided to `flutter build`.
  -->
  <base href="/">

  <meta charset="UTF-8">
  <meta content="IE=Edge" http-equiv="X-UA-Compatible">
  <meta name="description" content="A new Flutter project.">

  <!-- iOS meta tags & icons -->
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <meta name="apple-mobile-web-app-title" content="dark_icon_error">
  <link rel="apple-touch-icon" href="icons/Icon-192.png">

  <!-- Favicon -->
  <link rel="icon" type="image/png" href="favicon.png"/>

  <title>dark_icon_error</title>
  <link rel="manifest" href="manifest.json">

  <script>
    // The value below is injected by flutter build, do not touch.
    const serviceWorkerVersion = "2153810811";
  </script>
  <!-- This script adds the flutter initialization JS code -->
  <script src="flutter.js" defer></script>
</head>
<body>
  <script>
    window.addEventListener('load', function(ev) {
      // Download main.dart.js
      _flutter.loader.loadEntrypoint({
        serviceWorker: {
          serviceWorkerVersion: serviceWorkerVersion,
        },
        onEntrypointLoaded: function(engineInitializer) {
          engineInitializer.initializeEngine().then(function(appRunner) {
            appRunner.runApp();
          });
        }
      });
    });
  </script>
</body>
</html>
```

### Code sample

<details><summary>Code sample</summary>

I have create this project to reproduce problem:
https://github.com/apally-orange/bug_flutter_asset

if you launch on debug (`flutter run -d chrome`) you can see the flutter logo and if you launch on release (`flutter run -d chrome --release`), the logo not appear because asset content html data.

 The code to try resolve asset and auto rename path to "light theme" :
```dart
Future<ByteData> resolveAsset() async {
    const key = 'assets/dark/flutter.jpg';
    ByteData? asset = await _getAssetsFromKey(key);
    const darkFolder = '/dark/';
    if (asset == null && key.contains(darkFolder)) {
      final lightKey = key.replaceAll(darkFolder, '/light/');
      asset = await _getAssetsFromKey(lightKey);
    }

    if (asset == null) {
      throw FlutterError('Unable to load asset: $key');
    }

    return asset;
  }

  Future<ByteData?> _getAssetsFromKey(String key) async {
    final Uint8List encoded = utf8.encoder.convert(
      Uri(
        path: Uri.encodeFull(key),
      ).path,
    );

    return await ServicesBinding.instance.defaultBinaryMessenger.send(
      'flutter/assets',
      encoded.buffer.asByteData(),
    );
  }
```

And the code of display Image :
```dart
            FutureBuilder(
              future: resolveAsset(),
              builder: (context, result) {
                final safeData = result.data;
                if (result.hasData && safeData != null) {
                  return Image.memory(
                    safeData.buffer.asUint8List(),
                    height: 250,
                  );
                }

                return const SizedBox.shrink();
              },
            ),
```


</details>


### Screenshots or Video

<details>
<summary>Screenshots / Video demonstration</summary>

[Upload media here]

</details>


### Logs

_No response_

### Flutter Doctor output

<details><summary>Doctor output</summary>

```console
[✓] Flutter (Channel stable, 3.13.9, on macOS 13.5.2 22G91 darwin-arm64, locale fr-FR)
    • Flutter version 3.13.9 on channel stable at /Users/adrienpally/development/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision d211f42860 (3 weeks 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 33.0.0)
    • Android SDK at /Users/adrienpally/Library/Android/sdk
    • Platform android-33, build-tools 33.0.0
    • ANDROID_HOME = /Users/adrienpally/Library/Android/sdk
    • ANDROID_SDK_ROOT = /Users/adrienpally/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)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15A240d
    ✗ CocoaPods installed but not working.
        You appear to have CocoaPods installed but it is not working.
        This can happen if the version of Ruby that CocoaPods was installed with is different from the one being used to invoke it.
        This can usually be fixed by re-installing CocoaPods.
      To re-install see https://guides.cocoapods.org/using/getting-started.html#installation for instructions.

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] 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
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)

[✓] VS Code (version 1.84.1)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.76.0

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-arm64   • macOS 13.5.2 22G91 darwin-arm64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 119.0.6045.123

[✓] Network resources
    • All expected network resources are available.
```

</details>