Skip to content

Function.apply() named parameters fail when compiled to Wasm #60059

@yjbanov

Description

@yjbanov

Copied from flutter/flutter#161004:

Steps to reproduce

Use two different ways of setting container width and height:

  1. Literal symbols with #width and #height.
  2. Symbol('width') and Symbol('height').
  3. Run the code on a Wasm web build.

Wasm doesn't seem to support symbols for named parameters.
Is this working as intended?

Expected results

Both types of symbol Function.apply() works.
Two red containers should be rendered.

On non-Wasm web builds and other platforms, both methods work.

Actual results

The second container fails on Wasm.

Code sample

Code sample
import 'package:flutter/material.dart';

void main() {
  runApp(const MaterialApp(
    home: Scaffold(
      body: Center(
        child: DemoWidget(),
      ),
    ),
  ));
}

class DemoWidget extends StatelessWidget {
  const DemoWidget({super.key});

  @override
  Widget build(BuildContext context) {
    return Column(
      mainAxisAlignment: MainAxisAlignment.center,
      children: [
        // 1) Direct usage with literal named parameters (#width, #height)
        createContainerWithDirectSymbols(),
        const SizedBox(height: 20),
        // 2) Using Function.apply with Symbol-based named parameters
        createContainerWithDynamicNamedParameters(),
      ],
    );
  }

  Widget createContainerWithDirectSymbols() {
    try {
      return Function.apply(
        Container.new,
        [],
        {
          #width: 150.0,
          #height: 50.0,
          #color: Colors.red,
        },
      ) as Widget;
    } catch (e) {
      return Text('Error: $e');
    }
  }

  Widget createContainerWithDynamicNamedParameters() {
    try {
      return Function.apply(
        Container.new,
        [],
        {
          Symbol('width'): 150.0,
          Symbol('height'): 50.0,
          Symbol('color'): Colors.red,
        },
      ) as Widget;
    } catch (e) {
      return Text('Error: $e');
    }
  }
}

Screenshots or Video

Screenshots / Video demonstration image

There should be two Red containers. However, the dynamic named parameters fail on Wasm so the second container isn't visible.

Logs

Logs
[Paste your logs here]

Flutter Doctor output

Doctor output
[✓] Flutter (Channel beta, 3.28.0-0.1.pre, on macOS 15.1.1 24B2091 darwin-arm64, locale en-US)
    • Flutter version 3.28.0-0.1.pre on channel beta at /Users/ray/Development/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 3e493a3e4d (3 weeks ago), 2024-12-12 05:59:24 +0900
    • Engine revision 2ba456fd7f
    • Dart version 3.7.0 (build 3.7.0-209.1.beta)
    • DevTools version 2.41.0

[✓] Android toolchain - develop for Android devices (Android SDK version 35.0.0)
    • Android SDK at /Users/ray/Library/Android/sdk
    • Platform android-35, build-tools 35.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
      This is the JDK bundled with the latest Android Studio installation on this machine.
      To manually set the JDK path, use: `flutter config --jdk-dir="path/to/jdk"`.
    • Java version OpenJDK Runtime Environment (build 21.0.3+-79915917-b509.11)
    • All Android licenses accepted.

[!] Xcode - develop for iOS and macOS (Xcode 16.2)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 16C5032a
    ! CocoaPods 1.15.2 out of date (1.16.2 is recommended).
        CocoaPods is a package manager for iOS or macOS platform code.
        Without CocoaPods, plugins will not work on iOS or macOS.
        For more info, see https://flutter.dev/to/platform-plugins
      To update CocoaPods, see https://guides.cocoapods.org/using/getting-started.html#updating-cocoapods

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2024.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 21.0.3+-79915917-b509.11)

[✓] VS Code (version 1.96.2)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.102.0

[✓] Connected device (3 available)
    • macOS (desktop)                 • macos                 • darwin-arm64   • macOS 15.1.1 24B2091 darwin-arm64
    • Mac Designed for iPad (desktop) • mac-designed-for-ipad • darwin         • macOS 15.1.1 24B2091 darwin-arm64
    • Chrome (web)                    • chrome                • web-javascript • Google Chrome 131.0.6778.205

[✓] Network resources
    • All expected network resources are available.

Metadata

Metadata

Assignees

Labels

area-dart2wasmIssues for the dart2wasm compiler.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions