Repository: flutter/flutter
File: packages/flutter_tools/lib/src/build_system/targets/web.dart (Dart)

Code before:
    if (await inputFlutterBootstrapJs.exists()) {
      inputBootstrapContent = await inputFlutterBootstrapJs.readAsString();
    } else {
      inputBootstrapContent = generateDefaultFlutterBootstrapScript(
        includeServiceWorkerSettings: includeServiceWorkerSettings,
      );
    }
    final bootstrapTemplate = WebTemplate(inputBootstrapContent);
    for (final WebTemplateWarning warning in bootstrapTemplate.getWarnings()) {
      _emitWebTemplateWarning(environment, 'flutter_bootstrap.js', warning);
    }

    final FileSystem fileSystem = environment.fileSystem;
    final File flutterJsFile = fileSystem.file(
      fileSystem.path.join(
        globals.artifacts!.getHostArtifact(HostArtifact.flutterJsDirectory).path,
        'flutter.js',
      ),
    );

    final String buildConfig = buildConfigString(environment);

    // Extract web-define variables from the environment. These are stored with
    // the [kWebDefinePrefix] prefix by [WebBuilder.buildWeb].
    final webDefines = <String, String>{
      for (final MapEntry<String, String> entry in environment.defines.entries)
        if (entry.key.startsWith(kWebDefinePrefix))
          entry.key.substring(kWebDefinePrefix.length): entry.value,
    };

    // Insert a random hash into the requests for service_worker.js. This is not a content hash,
    // because it would need to be the hash for the entire bundle and not just the resource
    // in question.
    final String? serviceWorkerVersion = includeServiceWorkerSettings
        ? Random().nextInt(1 << 32).toString()
        : null;
    final String bootstrapContent = bootstrapTemplate.withSubstitutions(
      baseHref: '',
      serviceWorkerVersion: serviceWorkerVersion,
      flutterJsFile: flutterJsFile,
      buildConfig: buildConfig,
      webDefines: webDefines,
    );

    final File outputFlutterBootstrapJs = fileSystem.file(
      fileSystem.path.join(environment.outputDir.path, 'flutter_bootstrap.js'),
    );
    await outputFlutterBootstrapJs.writeAsString(bootstrapContent);

    await for (final FileSystemEntity file in webResources.list(recursive: true)) {
      if (file is File && file.basename == 'index.html') {

Review comment (suggestion):
Nit: consider using pattern matching here:

```dart
for (final MapEntry(:final key, :final value) in environment.defines.entries)) {
  if (key.startsWith(...))
    key.substring(...): value,
}
```

Code after:
    if (await inputFlutterBootstrapJs.exists()) {
      inputBootstrapContent = await inputFlutterBootstrapJs.readAsString();
    } else {
      inputBootstrapContent = generateDefaultFlutterBootstrapScript(
        includeServiceWorkerSettings: includeServiceWorkerSettings,
      );
    }
    final bootstrapTemplate = WebTemplate(inputBootstrapContent);
    for (final WebTemplateWarning warning in bootstrapTemplate.getWarnings()) {
      _emitWebTemplateWarning(environment, 'flutter_bootstrap.js', warning);
    }

    final FileSystem fileSystem = environment.fileSystem;
    final File flutterJsFile = fileSystem.file(
      fileSystem.path.join(
        globals.artifacts!.getHostArtifact(HostArtifact.flutterJsDirectory).path,
        'flutter.js',
      ),
    );

    final String buildConfig = buildConfigString(environment);

    // Extract web-define variables from the environment. These are stored with
    // the [kWebDefinePrefix] prefix by [WebBuilder.buildWeb].
    final webDefines = <String, String>{
      for (final MapEntry(:key, :value) in environment.defines.entries)
        if (key.startsWith(kWebDefinePrefix)) key.substring(kWebDefinePrefix.length): value,
    };

    // Insert a random hash into the requests for service_worker.js. This is not a content hash,
    // because it would need to be the hash for the entire bundle and not just the resource
    // in question.
    final String? serviceWorkerVersion = includeServiceWorkerSettings
        ? Random().nextInt(1 << 32).toString()
        : null;
    final String bootstrapContent = bootstrapTemplate.withSubstitutions(
      baseHref: '',
      serviceWorkerVersion: serviceWorkerVersion,
      flutterJsFile: flutterJsFile,
      buildConfig: buildConfig,
      webDefines: webDefines,
    );

    final File outputFlutterBootstrapJs = fileSystem.file(
      fileSystem.path.join(environment.outputDir.path, 'flutter_bootstrap.js'),
    );
    await outputFlutterBootstrapJs.writeAsString(bootstrapContent);

    await for (final FileSystemEntity file in webResources.list(recursive: true)) {
      if (file is File && file.basename == 'index.html') {
        final indexHtmlTemplate = WebTemplate(file.readAsStringSync());