WEB - Regression - @staticInterop classes should not contain any generative constructors

This issue has been created since 2022-11-24.

Hi,

I upgraded the framework today from 3.0.1 to 3.3.9 today and am having issues building release for Web. I also tried the latest master 3.6.0-7.0.pre.51 and it has the same error. Do you have any ideas what I can try?

Error:

Target dart2js failed: Exception: Warning: The 'dart2js' entrypoint script is deprecated, please use 'dart compile js' instead.
lib/main.dart:78:12:
Error: `@staticInterop` classes should not contain any generative constructors.
  external _ClipboardItem(dynamic args);
           ^
Error: Compilation failed.

Works: 3.0.1
CALL fvm use fb57da5 && CALL fvm flutter build web --release

Doesn't work: 3.3.9 / latest master
flutter build web --release

Code
import 'package:flutter/material.dart';
import 'dart:html';
import 'dart:typed_data';
import 'package:js/js.dart';
import 'package:js/js_util.dart';

void main() {
  runApp(const MyApp());
}

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

  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  final String title;

  @override
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            const Text('You have pushed the button this many times:'),
          ],
        ),
      ),
    );
  }
}

class ClipboardOperations {
  static void copyPNGImage(Uint8List pngBytes) async {
    final clipboard = window.navigator.clipboard as _Clipboard?;
    if (clipboard == null) {
      print('Error - No Clipboard found');
      return;
    }

//DOES not work on Firefox due to limitations in Clipboard API

    final dataMap = <dynamic, dynamic>{
      'image/png': Blob([pngBytes as Uint8List] as List<dynamic>, 'image/png')
    };

    dynamic out = jsify(dataMap);
    final item = _ClipboardItem(out);
    await clipboard.write([item]);
  }
}

@JS('ClipboardItem')
@staticInterop
class _ClipboardItem {
  external _ClipboardItem(dynamic args);
}

@JS('Clipboard')
@staticInterop
class _Clipboard {}

extension _ClipboardImpl on _Clipboard {
  @JS('write')
  external dynamic _write(List<_ClipboardItem> items);
  Future<void> write(List<_ClipboardItem> items) => promiseToFuture(_write(items) as Object);
}
flutter doctor
[!] Flutter (Channel master, 3.6.0-7.0.pre.51, on Microsoft Windows [Version 10.0.22598.1], locale en-IE)
    • Flutter version 3.6.0-7.0.pre.51 on channel master at c:\code\flutter
    ! Warning: `flutter` on your path resolves to C:\code\flutter\bin\flutter, which is not inside your current Flutter SDK checkout at
      c:\code\flutter. Consider adding c:\code\flutter\bin to the front of your path.
    ! Warning: `dart` on your path resolves to C:\code\flutter\bin\cache\dart-sdk\bin\dart.exe, which is not inside your current Flutter SDK checkout
      at c:\code\flutter. Consider adding c:\code\flutter\bin to the front of your path.
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision a41376ede2 (2 hours ago), 2022-11-24 14:28:34 -0500
    • Engine revision ad21c5adfd
    • Dart version 2.19.0 (build 2.19.0-429.0.dev)
    • DevTools version 2.19.0
    • If those were intentional, you can disregard the above warnings; however it is recommended to use "git" directly to perform update checks and
      upgrades.

[√] Windows Version (Installed version of Windows is version 10 or higher)

[X] Android toolchain - develop for Android devices
    X Unable to locate Android SDK.
      Install Android Studio from: https://developer.android.com/studio/index.html
      On first launch it will assist you in installing the Android SDK components.
      (or visit https://flutter.dev/docs/get-started/install/windows#android-setup for detailed instructions).
      If the Android SDK has been installed to a custom location, please use
      `flutter config --android-sdk` to update to that location.


[√] Chrome - develop for the web
    • CHROME_EXECUTABLE = c:\code\rocketx\chromecorsarm.bat

[X] Visual Studio - develop for Windows
    X Visual Studio not installed; this is necessary for Windows development.
      Download at https://visualstudio.microsoft.com/downloads/.
      Please install the "Desktop development with C++" workload, including all of its default components

[!] Android Studio (not installed)
    • Android Studio not found; download from https://developer.android.com/studio/index.html
      (or visit https://flutter.dev/docs/get-started/install/windows#android-setup for detailed instructions).

[√] VS Code (version 1.73.1)
    • VS Code at C:\Users\Rober\AppData\Local\Programs\Microsoft VS Code
    • Flutter extension version 3.52.0

[√] Connected device (3 available)
    • Windows (desktop) • windows • windows-x64    • Microsoft Windows [Version 10.0.22598.1]
    • Chrome (web)      • chrome  • web-javascript • Google Chrome 107.0.5304.107
    • Edge (web)        • edge    • web-javascript • Microsoft Edge 106.0.1370.37

[√] HTTP Host Availability
    • All required HTTP hosts are available

! Doctor found issues in 4 categories.
huycozy wrote this answer on 2022-11-25

Hi @zambetpentru I think this issue is caused by implementation. Below is full error message I got when running your sample code:

lib/web_dart2js_115988.dart:78:12: Error: `@staticInterop` classes should not contain any generative constructors.
Use factory constructors instead.
  external _ClipboardItem(dynamic args);
           ^
Failed to compile application.

Try updating the code to use external factory, it can run normally:

@JS('ClipboardItem')
@staticInterop
class _ClipboardItem {
  external factory _ClipboardItem(dynamic args);
}

Also, you can check this dart-lang issue dart-lang/sdk#48730 as reference. For further questions, please write a comment there or file a new issue on dart-lang/sdk repository for better support.

Closing as this is not a Flutter issue. If you disagree, please write in the comments and I will reopen it. Thank you!

zambetpentru wrote this answer on 2022-11-25

Brilliant thank you! The standard Flutter build didn't give me that extended error message about using the factory.

More Details About Repo
Owner Name flutter
Repo Name flutter
Full Name flutter/flutter
Language Dart
Created Date 2015-03-06
Updated Date 2022-12-10
Star Count 147243
Watcher Count 3561
Fork Count 23950
Issue Count 11325

YOU MAY BE INTERESTED

Issue Title Created Date Comment Count Updated Date
Non-returning insert statements 7 2021-11-05 2022-12-06
panic: negative dimension size does not make sense 0 2022-05-27 2022-09-29
"Asymmetric padding" error 0 2022-05-12 2022-09-29
JAWS does not announce that text has been marked with <del> 2 2022-02-21 2022-09-25
template_zabbix-apt.yaml 0 2022-07-11 2022-11-25
Console key listener (~) overriden in SDL2 backend 0 2021-02-21 2022-11-15
Doc improvement suggestion - the `:inner` rule examples 0 2021-10-20 2022-10-03
[BUG]11.2.3版本酷安使用模块必定闪退 4 2021-06-07 2022-02-02
"An error has occurred." Terminal, Macintosh 1 2021-08-12 2022-10-18
local subtitle file not loading and only network subtitle file loads 1 2021-07-10 2022-11-12
mapping_names_resnets can not find 1 2021-09-02 2022-11-30
A error about use tensorrt to transfer the model of SRModel with dynamic shape inputs/output 1 2021-09-06 2022-12-02
AppImage fails to launch on linux 10 2022-07-10 2022-11-26
Terminal often freezes when connecting ssh or when selecting new sessions in the sessions window 0 2022-05-05 2022-09-21
windows performance enhancements 0 2022-01-22 2022-11-12
bootstrap app from dist directory 2 2020-09-01 2022-10-24
Add test for 2D GaussianRamdomWalk logp 9 2022-04-04 2022-11-27
Feature Request: Add cooking/resting times to recipes in order to help with meal planning 1 2021-11-21 2022-11-20
Speed up filtering step 6 2020-06-10 2022-09-26
Geomorphology drawer not opening on live 1 2021-10-21 2022-10-03
Games crash on unc0ver ios 14.2 7 2021-03-01 2022-12-08
[🐛 Bug]: How to reuse firefox exist session by geckodriver? 3 2022-08-14 2022-09-09
Is Dragging CSS is only needed for the editor not front-end. 0 2022-04-08 2022-04-03
Error on https://wankgames.com/zh-hans/game/office-secretary-2/ 0 2021-12-01 2022-10-23
Error: ENOTSUP: operation not supported on socket, symlink 0 2022-06-29 2022-12-09
Add 127.0.0.1 as a host option 1 2021-06-28 2022-09-25
ServiceFabricIntegrationOptions UseUniquestServiceUrl is not possible using IHostBuilder outside this assemble 2 2022-05-06 2022-11-29
hostlist-compiler command does not work when started via cron job 1 2021-12-15 2022-11-29
emulator.read_file does not work with GitHub images (linux.iso, linux4.iso) 2 2021-05-31 2022-11-01
[CSS] Highlight of 'rem' units after float-number 2 2022-02-23 2022-10-17
Exposed event parameters indexed property 3 2021-06-29 2022-11-30
p-dropdown: onChange event is invoked even when you only navigate through the items 0 2022-07-12 2022-10-23
🐛 [BUG]g2plot 堆叠和分组条形图,colorField 为数值类型时(连续型图例),提示框内容返回不完整 2 2021-08-13 2022-11-16
java.lang.IllegalStateException: Surface was requested when the Recorder had encountered error androidx.camera.video.internal.encoder.InvalidConfigException: android.media.MediaCodec$CodecException: Error 0xffffec77 9 2021-11-02 2022-12-02
Fallback run for tests failed and it makes tests fail locally 0 2022-02-18 2022-12-09
Change the ErrorsInExternalDNS alarm to high priority 1 2022-01-25 2022-08-17
moveit_setup_assistant not posible to use setPositionTarget() 0 2022-11-15 2022-12-02
Execution of Maven plugin in Eclipse broken since 1.12.13 8 2022-09-27 2022-12-08
Is there any way to get the value of a static compile-time constant field without execute the initializer method 2 2022-05-20 2022-11-08
Merge Latest changes into 4.2.0 2 2021-08-31 2022-12-05
wazuh deployment on kubernetes with ingress controller. 2 2021-09-22 2022-12-02
SQLSTATE[40001]: Serialization failure: 1213 Deadlock found 0 2022-03-08 2022-11-28
Add reply-from reply-modes to `ra:pipeline_command/4` 0 2022-11-02 2022-11-26
[HttpClient] Improve default content-type handling 0 2022-03-23 2022-11-18
Schema-validation: missing table [member.member_flag] 1 2021-12-15 2022-09-20
Enable caching for system tests in CI 0 2021-12-14 2022-09-20
Use log4j-bom to manage log4j-to-slf4j dependency 0 2021-12-15 2022-11-07
Implement KRM alternative for dataproc-v1 snippets 0 2021-05-14 2022-11-25
Implement KRM alternative for container-v1 snippets 0 2021-05-14 2022-11-25
how to close prepare stmt in beego orm? set interpolateParams=true invaild ? 4 2021-12-20 2022-12-09