Flutter 3.0.3 Web开发调试遇Unexpected null value错误及跳转异常求助
Flutter Web转译后Chrome中出现Unexpected null value错误及调试跳转失败问题
我们近期基于Flutter 3.0.3(Dart 2.17.5 • DevTools 2.12.2)将现有Flutter应用转为Web版本,在Chrome中运行Web项目时触发如下错误:
Error: Unexpected null value. at Object.throw_ [as throw] (http://localhost:57060/dart_sdk.js:5080:11) at Object.nullCheck (http://localhost:57060/dart_sdk.js:5399:30) at auth_repo.AuthRepo._internal.loginUser (http://localhost:57060/packages/our_repo/modules/home/repository/our_db_search.lib.js:24349:77) at loginUser.next (<anonymous>) at http://localhost:57060/dart_sdk.js:40641:33 at _RootZone.runUnary (http://localhost:57060/dart_sdk.js:40511:59) at _FutureListener.thenAwait.handleValue (http://localhost:57060/dart_sdk.js:35438:29) at handleValueCallback (http://localhost:57060/dart_sdk.js:35999:49) at _Future._propagateToListeners (http://localhost:57060/dart_sdk.js:36037:17) at [_complete] (http://localhost:57060/dart_sdk.js:35864:25) at _SyncCompleter.new.complete (http://localhost:57060/dart_sdk.js:35355:31) at onValue (http://localhost:57060/dart_sdk.js:35118:49) at _RootZone.runUnary (http://localhost:57060/dart_sdk.js:40511:59) at _FutureListener.then.handleValue (http://localhost:57060/dart_sdk.js:35438:29) at handleValueCallback (http://localhost:57060/dart_sdk.js:35999:49) at _Future._propagateToListeners (http://localhost:57060/dart_sdk.js:36037:17) at [_completeWithValue] (http://localhost:57060/dart_sdk.js:35872:23) at async._AsyncCallbackEntry.new.callback (http://localhost:57060/dart_sdk.js:35906:35) at Object._microtaskLoop (http://localhost:57060/dart_sdk.js:40778:13) at _startMicrotaskLoop (http://localhost:57060/dart_sdk.js:40784:13) at http://localhost:57060/dart_sdk.js:36261:9
点击错误信息跳转时浏览器显示"Internal Server Error",调试难度极大。请问是否有开发者遇到过类似的Web项目问题?如需更多信息,请告知。
排查建议
- 定位
AuthRepo._internal.loginUser方法的空值点:错误栈明确指向该方法编译后的JS代码第24349行77列,检查Flutter源码中对应位置是否存在强制解包(!)或未做空判断的变量,Web环境下部分移动端API/三方库的行为可能存在差异,导致变量为空。 - 绕开跳转异常直接调试:关闭DevTools自动跳转,直接查看编译后的
our_db_search.lib.js对应行代码,或在Flutter源码的loginUser方法中添加日志,打印关键变量值确认空值来源。 - 切换编译模式验证:尝试执行
flutter build web --release编译后运行,排查是否为debug模式下的编译异常。 - 清理缓存:执行
flutter clean,同时清除Chrome浏览器缓存后重新运行项目,排除缓存导致的异常。
内容的提问来源于stack exchange,提问作者user3600064
相关产品推荐
相关产品推荐

