Skip to content

[CP-stable]Fix flutter build web ignoring --web-define flag#182344

Merged
auto-submit[bot] merged 1 commit intoflutter:flutter-3.41-candidate.0from
flutteractionsbot:cp-stable-6f1d81b243538a25424f1637ecb968fcf8958211
Feb 17, 2026
Merged

[CP-stable]Fix flutter build web ignoring --web-define flag#182344
auto-submit[bot] merged 1 commit intoflutter:flutter-3.41-candidate.0from
flutteractionsbot:cp-stable-6f1d81b243538a25424f1637ecb968fcf8958211

Conversation

@flutteractionsbot
Copy link

@flutteractionsbot flutteractionsbot commented Feb 13, 2026

This pull request is created by automatic cherry pick workflow
Please fill in the form below, and a flutter domain expert will evaluate this cherry pick request.

Issue Link:

What is the link to the issue this cherry-pick is addressing?

#182076

Impact Description:

What is the impact (ex. visual jank on Samsung phones, app crash, cannot ship an iOS app)?
Does it impact development (ex. flutter doctor crashes when Android Studio is installed),
or the shipping of production apps (the app crashes on launch).
This information is for domain experts and release engineers to understand the consequences of saying yes or no to the cherry pick.

The --web-define feature works during development (i.e. flutter run), but doesn't work for production (i.e. flutter build web).

Changelog Description:

Explain this cherry pick:

  • In one line that is accessible to most Flutter developers.
  • That describes the state prior to the fix.
  • That includes which platforms are impacted.
    See best practices for examples.

Fix flutter build web ignoring --web-define flag

Workaround:

Is there a workaround for this issue?

No workaround.

Risk:

What is the risk level of this cherry-pick?

  • Low
  • Medium
  • High

Test Coverage:

Are you confident that your fix is well-tested by automated tests?

  • Yes
  • No

Validation Steps:

What are the steps to validate that this fix works?

Follow repro steps in #182076

## Summary

`flutter build web --web-define=KEY=VALUE` silently ignored the
`--web-define` flag. The option was registered via
`usesWebDefineOption()` but the values were never extracted or passed
through the build pipeline. `flutter run` was unaffected as it correctly
calls `extractWebDefines()`.

This PR threads web-define values through the full `flutter build web`
chain:

- **`build_web.dart`**: Call `extractWebDefines()` and pass the result
to `buildWeb()`.
- **`compile.dart`**: Add `kWebDefinePrefix` constant and `webDefines`
parameter to `buildWeb()`, storing prefixed entries in
`Environment.defines`.
- **`web.dart`**: In `WebTemplatedFiles.build()`, extract web-define
entries from the environment and pass them to both `withSubstitutions()`
calls (bootstrap + index.html).

Related to flutter#175805. 
Fixes flutter#182076

## Test plan

- Added 2 tests in `build_web_test.dart`:
- Verifies `--web-define` values are passed to `Environment.defines`
with `webDefine:` prefix.
- Verifies builds succeed without `--web-define` and no prefixed entries
are present.
- Added 3 tests in `web_test.dart`:
- `WebTemplatedFiles` substitutes web-define variables in `index.html`.
- `WebTemplatedFiles` substitutes web-define variables in
`flutter_bootstrap.js`.
  - `WebTemplatedFiles` works correctly with no web-define variables.
- All existing tests in `build_web_test.dart` (24/24), `web_test.dart`
(619/619), and `web_template_test.dart` (16/16) pass.

---------

Co-authored-by: Mouad Debbar <mdebbar@google.com>
@flutteractionsbot flutteractionsbot added the cp: review Cherry-picks in the review queue label Feb 13, 2026
@flutteractionsbot
Copy link
Author

@mdebbar please fill out the PR description above, afterwards the release team will review this request.

@flutter-dashboard
Copy link

This pull request was opened from and to a release candidate branch. This should only be done as part of the official Flutter release process. If you are attempting to make a regular contribution to the Flutter project, please close this PR and follow the instructions at Tree Hygiene for detailed instructions on contributing to Flutter.

Reviewers: Use caution before merging pull requests to release branches. Ensure the proper procedure has been followed.

@github-actions github-actions bot added the tool Affects the "flutter" command-line tool. See also t: labels. label Feb 13, 2026
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request is a cherry-pick to the stable branch. The changes address an issue where flutter build web was ignoring the --web-define flag. The modifications pass the --web-define values from the command line into the build environment, allowing them to be used for variable substitution in web template files such as index.html. New tests are included to verify this functionality. The changes appear correct and complete.

@LongCatIsLooong LongCatIsLooong added the autosubmit Merge PR when tree becomes green via auto submit App label Feb 17, 2026
@auto-submit auto-submit bot merged commit 2ac4854 into flutter:flutter-3.41-candidate.0 Feb 17, 2026
141 checks passed
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 20, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 20, 2026
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 21, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

autosubmit Merge PR when tree becomes green via auto submit App cp: review Cherry-picks in the review queue tool Affects the "flutter" command-line tool. See also t: labels.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants