Skip to content

dart2wasm compilation fails in Flutter 3.38+ due to mixed null/int switch cases #1528

@lemz90

Description

@lemz90

Steps to Reproduce

Note: This is a compilation error with Flutter 3.38's dart2wasm compiler, not a runtime HTML rendering issue.

  1. Update to Flutter 3.38.0 or later
  2. Attempt to build a web app using WASM: flutter build web --release --wasm
  3. The build fails during dart2wasm compilation
HTML
N/A - This is a build-time compilation error
`HtmlWidget` configuration
N/A - This is a build-time compilation error
Testing environment
[✓] Flutter (Channel stable, 3.38.2, on macOS 15.4.0 darwin-arm64)
    • Flutter version 3.38.2 on channel stable
    • Dart version 3.10.0
    • Package: flutter_widget_from_html_core 0.17.0

Building with: flutter build web --release --wasm

Expected results

The app should compile successfully with WASM as it did in Flutter 3.35 and earlier versions.

Actual results

Build fails with compilation error:

Target dart2wasm failed: ProcessException: Process exited abnormally with exit code 255:
Exception in SwitchStatement at
file:///.../.pub-cache/hosted/pub.dev/flutter_widget_from_html_core-0.17.0/lib/src/data/build_op.dart:172:17

Unhandled exception:
type 'NullConstant' is not a subtype of type 'IntConstant' in type cast
#0      new SwitchInfo (package:dart2wasm/code_generator.dart:4543)
#1      AstCodeGenerator.visitSwitchStatement (package:dart2wasm/code_generator.dart:1368)

Root cause: The switch statement at build_op.dart:172-183 mixes null and integer case values:

switch (children?.length) {
  case null:    // NullConstant
    return placeholder;
  case 0:       // IntConstant
    return widget0;
  case 1:       // IntConstant
    return children?.first ?? widget0;
  default:
    throw UnsupportedError(...);
}

The dart2wasm compiler in Flutter 3.38+ is stricter and no longer allows mixing NullConstant and IntConstant types in the same switch statement.

Proposed fix: Refactor to use if-else logic instead of a switch statement.

Metadata

Metadata

Assignees

No one assigned

    Labels

    questionFurther information is requested

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions