Flutter Web应用无法启动:断言失败“布尔表达式不可为null”
问题详情
全新创建的Flutter项目,无任何自定义代码,执行flutter run -d chrome命令在Chrome中运行时,控制台抛出以下错误:
Unhandled error detected in the injected client.js script.
You can disable this script in webdev by passing --no-injected-client if it
is preventing your app from loading, but note that this will also prevent
all debugging and hot reload/restart functionality from working.The original error is below, please file an issue at
https://github.com/dart-lang/webdev/issues/new and attach this output:Assertion failed: "boolean expression must not be null"
Assertion failed: "boolean expression must not be null"
at Object.wrapException (http://localhost:62764/dwds/src/injected/client.js:1420:43)
[...]
at _AsyncRun__initializeScheduleImmediate_internalCallback.call$1 (http://localhost:62764/dwds/src/injected/client.js:12119:9)
已尝试过flutter clean、删除.dart_tool文件夹、更新Flutter SDK至最新版本,且项目在Android模拟器中运行正常,开发工具为Visual Studio Code。
解决步骤
1. 临时禁用注入脚本运行项目
执行以下命令跳过client.js注入,可先验证项目是否能正常加载(注意此操作会丢失调试、热重载/重启功能):
flutter run -d chrome --no-injected-client
2. 升级Chrome浏览器至最新版本
旧版Chrome可能与DWDS(Dart Web Debug Service)存在兼容性问题:
- 打开Chrome设置 → 关于Chrome,等待自动更新完成
- 重启浏览器后再次尝试运行项目
3. 重置VSCode相关配置
- 关闭VSCode,删除项目根目录下的
.vscode文件夹(若存在) - 重新打开项目,通过Run面板重新生成Flutter Web启动配置
4. 降级DWDS版本(临时兼容方案)
若最新SDK版本存在兼容性问题,可在pubspec.yaml中添加依赖覆盖:
dependency_overrides: dwds: 19.0.0
执行flutter pub get后重新运行项目。
5. 清除Chrome缓存
- 打开Chrome开发者工具(F12),右键点击刷新按钮,选择「清空缓存并硬性重新加载」
- 或在Chrome设置中清除浏览数据,勾选「缓存的图片和文件」,重启浏览器后重试
内容的提问来源于stack exchange,提问作者Kaikaison

