You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

执行flutter build web --release构建RustDesk Web客户端遇Dart编译错误

解决RustDesk Web客户端构建时dart2js编译错误

以下是针对构建过程中各类编译错误的具体原因和修复方案:

一、Firebase Core依赖版本不兼容

错误信息:

../../../.pub-cache/hosted/pub.dev/firebase_core-3.4.0/lib/src/firebase_app.dart:18:25:
Error: Member not found: 'FirebaseAppPlatform.verify'.
    FirebaseAppPlatform.verify(_delegate);
                        ^^^^^^

原因:firebase_core 3.4.0版本与当前Flutter/Dart版本不匹配,FirebaseAppPlatform.verify方法已被移除或重命名。
修复方案:

  • 在pubspec.yaml中调整firebase_core版本,换成与当前Flutter版本兼容的稳定版(可查看Flutter官方插件兼容表确认)。
  • 执行flutter pub get重新拉取依赖。

二、图片处理API调用错误

相关错误:

lib/pages/scan_page.dart:54:58:
Error: Member not found: 'abgr'.
                            .getBytes(format: img.Format.abgr)
                                                         ^^^^
lib/pages/scan_page.dart:54:39:
Error: No named parameter with the name 'format'.
                            .getBytes(format: img.Format.abgr)
                                      ^^^^^^

原因:使用的图片处理库(如image库)版本更新后API变更,getBytes不再支持format参数,且abgr格式定义有变化。
修复方案:

  • 对照当前图片库的官方文档调整调用方式,比如改用对应格式的编码方法(如encodePng/encodeJpg),或调整格式参数的写法。

三、scan_page.dart参数传递顺序错误

错误信息:

lib/pages/scan_page.dart:48:41:
Error: The argument type 'Uint8List' can't be assigned to the parameter type 'String'.
 - 'Uint8List' is from 'dart:typed_data'.
                        File(file.path).readAsBytesSync(), file.path)!;
                                        ^
lib/pages/scan_page.dart:48:65:
Error: The argument type 'String' can't be assigned to the parameter type 'Uint8List'.
 - 'Uint8List' is from 'dart:typed_data'.
                        File(file.path).readAsBytesSync(), file.path)!;
                                                                ^

原因:该行调用的构造函数参数顺序颠倒,第一个参数应为String类型路径,第二个为Uint8List类型字节数据。
修复方案:

  • 修改lib/pages/scan_page.dart第48行,交换两个参数位置:
    File(file.path), File(file.path).readAsBytesSync()!;
    
    (需根据实际构造函数定义调整,确保参数类型与位置匹配)

四、Dash Chat依赖版本过旧适配问题

相关错误:

../../../.pub-cache/hosted/pub.dev/dash_chat-1.1.16/lib/src/message_listview.dart:247:72:
Error: The argument type 'String?' can't be assigned to the parameter type 'String' because 'String?' is nullable and 'String' isn't.
                                                                      .text));
                                                                       ^
../../../.pub-cache/hosted/pub.dev/dash_chat-1.1.16/lib/src/widgets/message_container.dart:107:43:
Error: The getter 'accentColor' isn't defined for the class 'ThemeData'.
 - 'ThemeData' is from 'package:flutter/src/material/theme_data.dart' ('../../../rustdesk/flutter/flutter/packages/flutter/lib/src/material/theme_data.dart').
                      ? Theme.of(context).accentColor
                                          ^^^^^^^^^^^

原因:dash_chat 1.1.16版本过旧,不支持Flutter null安全特性,且依赖的ThemeData.accentColor在新版Flutter中已被移除(替换为colorScheme.secondary)。
修复方案:

  • 升级dash_chat到支持null安全的新版,比如在pubspec.yaml中指定dash_chat: ^4.0.0,执行flutter pub get更新依赖。
  • 若无法升级,手动修改dash_chat源码:
    1. 将所有Theme.of(context).accentColor替换为Theme.of(context).colorScheme.secondary。
    2. 处理null安全,给String?类型的.text添加空断言(!.text)或判空逻辑。

五、Service Worker版本变量警告

警告信息:

Warning: In index.html:97: Local variable for "serviceWorkerVersion" is deprecated. Use "{{flutter_service_worker_version}}" template token instead.

修复方案:

  • 修改web/index.html文件,将原serviceWorkerVersion变量定义替换为模板token{{flutter_service_worker_version}}。

完成以上修复后,重新执行flutter build web --release即可尝试构建。

内容的提问来源于stack exchange,提问作者Heigou

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.18 22:59:57