我正在使用web (Chrome)
运行我的应用程序。但是,我收到一个错误。错误如下:
══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
The following assertion was thrown building Builder:
Assertion failed:
file:///Users/name/development/flutter/packages/flutter/lib/src/foundation/stack_frame.dart:192:7
line != '===== asynchronous gap ==========================='
"Got a stack frame from package:stack_trace, where a vm or web frame was expected. This can happen
if FlutterError.demangleStackTrace was not set in an environment that propagates non-standard stack
traces to the framework, such as during tests."
The relevant error-causing widget was:
MaterialApp
MaterialApp:file:///Users/name/development/projects/flutter/hello_world/lib/src/hello_world.dart:12:12
When the exception was thrown, this was the stack:
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 251:49 throw_
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/errors.dart 29:3 assertFailed
packages/flutter/src/foundation/stack_frame.dart 192:15 fromStackTraceLine
dart-sdk/lib/internal/iterable.dart 391:20 moveNext
dart-sdk/lib/internal/iterable.dart 869:20 moveNext
dart-sdk/lib/_internal/js_dev_runtime/private/ddc_runtime/operations.dart 748:20 next
dart-sdk/lib/_internal/js_dev_runtime/patch/core_patch.dart 586:14 of
dart-sdk/lib/core/iterable.dart 470:12 toList
packages/flutter/src/foundation/stack_frame.dart 87:37 fromStackString
packages/flutter/src/foundation/assertions.dart 1066:54 defaultStackFilter
packages/flutter/src/foundation/assertions.dart 1260:43 _applyStackFilter
packages/flutter/src/foundation/assertions.dart 1235:17 new
packages/flutter/src/foundation/assertions.dart 725:22 debugFillProperties
packages/flutter/src/foundation/diagnostics.dart 2992:17 <fn>
packages/flutter/src/foundation/diagnostics.dart 2994:16 get builder
packages/flutter/src/foundation/assertions.dart 1285:56 get builder
packages/flutter/src/foundation/diagnostics.dart 3009:105 getProperties
packages/flutter/src/foundation/diagnostics.dart 1244:62 [_debugRender]
packages/flutter/src/foundation/diagnostics.dart 1121:14 render
packages/flutter/src/foundation/assertions.dart 1013:44 dumpErrorToConsole
packages/app/main.dart 28:69 <fn>
packages/flutter/src/foundation/assertions.dart 1177:14 reportError
packages/flutter/src/widgets/framework.dart 6408:16 _debugReportException
packages/flutter/src/widgets/framework.dart 4815:9 performRebuild
packages/flutter/src/widgets/framework.dart 4977:11 performRebuild
packages/flutter/src/widgets/framework.dart 4529:5 rebuild
packages/flutter/src/widgets/framework.dart 4787:5 [_firstBuild]
packages/flutter/src/widgets/framework.dart 4968:11 [_firstBuild]
packages/flutter/src/widgets/framework.dart 4781:5 mount
packages/flutter/src/widgets/framework.dart 3817:15 inflateWidget
packages/flutter/src/widgets/framework.dart 3551:18 updateChild
packages/flutter/src/widgets/framework.dart 6215:14 mount
packages/flutter/src/widgets/framework.dart 3817:15 inflateWidget
packages/flutter/src/widgets/framework.dart 3551:18 updateChild
packages/flutter/src/widgets/framework.dart 4832:16 performRebuild
packages/flutter/src/widgets/framework.dart 4529:5 rebuild
packages/flutter/src/widgets/framework.dart 4787:5 [_firstBuild]
packages/flutter/src/widgets/framework.dart 4781:5 mount
packages/flutter/src/widgets/framework.dart 3817:15 inflateWidget
packages/flutter/src/widgets/framework.dart 3551:18 updateChild
packages/flutter/src/widgets/framework.dart 6215:14 mount
packages/flutter/src/widgets/framework.dart 3817:15 inflateWidget
packages/flutter/src/widgets/framework.dart 3551:18 updateChild
packages/flutter/src/widgets/framework.dart 6215:14 mount
packages/flutter/src/widgets/framework.dart 3817:15 inflateWidget
packages/flutter/src/widgets/framework.dart 3551:18 updateChild
packages/flutter/src/widgets/framework.dart 4832:16 performRebuild
packages/flutter/src/widgets/framework.dart 4977:11 performRebuild
packages/flutter/src/widgets/framework.dart 4529:5 rebuild
packages/flutter/src/widgets/framework.dart 4787:5 [_firstBuild]
packages/flutter/src/widgets/framework.dart 4968:11 [_firstBuild]
packages/flutter/src/widgets/framework.dart 4781:5 mount
packages/flutter/src/widgets/framework.dart 3817:15 inflateWidget
packages/flutter/src/widgets/framework.dart 6350:36 inflateWidget
packages/flutter/src/widgets/framework.dart 6362:32 mount
packages/flutter/src/widgets/framework.dart 3817:15 inflateWidget
packages/flutter/src/widgets/framework.dart 3551:18 updateChild
packages/flutter/src/widgets/framework.dart 4832:16 performRebuild
packages/flutter/src/widgets/framework.dart 4977:11 performRebuild
packages/flutter/src/widgets/framework.dart 4529:5 rebuild
packages/flutter/src/widgets/framework.dart 4787:5 [_firstBuild]
packages/flutter/src/widgets/framework.dart 4968:11 [_firstBuild]
packages/flutter/src/widgets/framework.dart 4781:5 mount
packages/flutter/src/widgets/framework.dart 3817:15 inflateWidget
packages/flutter/src/widgets/framework.dart 3551:18 updateChild
packages/flutter/src/widgets/framework.dart 6215:14 mount
packages/flutter/src/widgets/framework.dart 3817:15 inflateWidget
packages/flutter/src/widgets/framework.dart 3551:18 updateChild
packages/flutter/src/widgets/framework.dart 4832:16 performRebuild
packages/flutter/src/widgets/framework.dart 4977:11 performRebuild
packages/flutter/src/widgets/framework.dart 4529:5 rebuild
packages/flutter/src/widgets/framework.dart 4787:5 [_firstBuild]
packages/flutter/src/widgets/framework.dart 4968:11 [_firstBuild]
packages/flutter/src/widgets/framework.dart 4781:5 mount
packages/flutter/src/widgets/framework.dart 3817:15 inflateWidget
packages/flutter/src/widgets/framework.dart 3551:18 updateChild
packages/flutter/src/widgets/framework.dart 6215:14 mount
packages/flutter/src/widgets/framework.dart 3817:15 inflateWidget
packages/flutter/src/widgets/framework.dart 3551:18 updateChild
packages/flutter/src/widgets/framework.dart 4832:16 performRebuild
packages/flutter/src/widgets/framework.dart 4977:11 performRebuild
packages/flutter/src/widgets/framework.dart 4529:5 rebuild
packages/flutter/src/widgets/framework.dart 4787:5 [_firstBuild]
packages/flutter/src/widgets/framework.dart 4968:11 [_firstBuild]
packages/flutter/src/widgets/framework.dart 4781:5 mount
packages/flutter/src/widgets/framework.dart 3817:15 inflateWidget
packages/flutter/src/widgets/framework.dart 3551:18 updateChild
packages/flutter/src/widgets/framework.dart 6215:14 mount
packages/flutter/src/widgets/framework.dart 3817:15 inflateWidget
packages/flutter/src/widgets/framework.dart 3551:18 updateChild
packages/flutter/src/widgets/framework.dart 4832:16 performRebuild
packages/flutter/src/widgets/framework.dart 4977:11 performRebuild
packages/flutter/src/widgets/framework.dart 4529:5 rebuild
packages/flutter/src/widgets/framework.dart 4787:5 [_firstBuild]
packages/flutter/src/widgets/framework.dart 4968:11 [_firstBuild]
packages/flutter/src/widgets/framework.dart 4781:5 mount
packages/flutter/src/widgets/framework.dart 3817:15 inflateWidget
packages/flutter/src/widgets/framework.dart 3551:18 updateChild
packages/flutter/src/widgets/framework.dart 4832:16 performRebuild
packages/flutter/src/widgets/framework.dart 4529:5 rebuild
packages/flutter/src/widgets/framework.dart 4787:5 [_firstBuild]
packages/flutter/src/widgets/framework.dart 4781:5 mount
packages/flutter/src/widgets/framework.dart 3817:15 inflateWidget
packages/flutter/src/widgets/framework.dart 3551:18 updateChild
packages/flutter/src/widgets/framework.dart 4832:16 performRebuild
packages/flutter/src/widgets/framework.dart 4977:11 performRebuild
packages/flutter/src/widgets/framework.dart 4529:5 rebuild
packages/flutter/src/widgets/framework.dart 4787:5 [_firstBuild]
packages/flutter/src/widgets/framework.dart 4968:11 [_firstBuild]
packages/flutter/src/widgets/framework.dart 4781:5 mount
packages/flutter/src/widgets/framework.dart 3817:15 inflateWidget
packages/flutter/src/widgets/framework.dart 3551:18 updateChild
packages/flutter/src/widgets/framework.dart 6215:14 mount
packages/flutter/src/widgets/framework.dart 3817:15 inflateWidget
packages/flutter/src/widgets/framework.dart 3551:18 updateChild
packages/flutter/src/widgets/framework.dart 6215:14 mount
packages/flutter/src/widgets/framework.dart 3817:15 inflateWidget
packages/flutter/src/widgets/framework.dart 3551:18 updateChild
packages/flutter/src/widgets/framework.dart 4832:16 performRebuild
packages/flutter/src/widgets/framework.dart 4529:5 rebuild
packages/flutter/src/widgets/framework.dart 4787:5 [_firstBuild]
packages/flutter/src/widgets/framework.dart 4781:5 mount
packages/flutter/src/widgets/framework.dart 3817:15 inflateWidget
packages/flutter/src/widgets/framework.dart 3551:18 updateChild
packages/flutter/src/widgets/framework.dart 6215:14 mount
此错误仅在使用web (Chrome)
运行我的应用时发生。如果我使用Android Emulator
,则不会出现此错误。
我参考了一些帖子,如Widget test fails with No MediaQuery widget found,No MediaQuery widget ancestor found,No MediaQuery ancestor could be found?和其他帖子,但仍然不能解决这个错误。
部分代码片段:
主省道:
import 'dart:async';
import 'package:flutter/material.dart';
......
Future<void> main() async {
await runZonedGuarded(
() async {
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
GoRouter.setUrlPathStrategy(UrlPathStrategy.path);
runApp(const ProviderScope(child: MaterialApp(home: HelloWorld())));
......
},
(Object error, StackTrace stack) {
debugPrint(error.toString());
debugPrint(stack.toString());
},
);
}
您好_世界。dart:
import 'package:flutter/material.dart';
import 'package:hello_world/src/app.dart';
......
class HelloWorld extends StatelessWidget {
const HelloWorld({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) => MaterialApp(
theme: ......,
home: const App(),
);
}
应用省道:
import 'package:flutter/material.dart';
......
class App extends ConsumerStatefulWidget {
const App({Key? key}) : super(key: key);
@override
ConsumerState<App> createState() => _AppState();
}
class _AppState extends ConsumerState<App> {
@override
void initState() {
super.initState();
kIsWeb ? null : ......;
}
@override
Widget build(BuildContext context) {
......
return Scaffold(
body: ......,
);
}
}
我不太确定这个错误是否源于这一行:
runApp(const ProviderScope(child: MaterialApp(home: HelloWorld())));
我如何修复这个错误?如果有人能提供建议,我将不胜感激。提前感谢!
3条答案
按热度按时间rdlzhqv91#
我通过设置
FlutterError.demangleStackTrace
解决了这个错误:第一个
lokaqttq2#
我的一个同事也有类似的错误,那是由于一个空字符串给了一个网络映像。我可以看到在你的stacktrace中有一个错误抛出在
iterable.dart
〉moveNext
。所以它让我认为你的问题是由一个无效的循环或类似的东西引起的。6pp0gazn3#
我也犯了同样的错误,做了这些事情,它起作用了。
1.使用
demangleStackTrace
函数1.在终端中运行
flutter clean
命令,然后将Firebase依赖项升级到新版本。