dart 从package:stack_trace中获取了堆栈帧,其中应该是vm或web帧

qni6mghb  于 2022-12-06  发布在  其他
关注(0)|答案(3)|浏览(180)

我正在使用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 foundNo MediaQuery widget ancestor foundNo 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())));

我如何修复这个错误?如果有人能提供建议,我将不胜感激。提前感谢!

rdlzhqv9

rdlzhqv91#

我通过设置FlutterError.demangleStackTrace解决了这个错误:
第一个

lokaqttq

lokaqttq2#

我的一个同事也有类似的错误,那是由于一个空字符串给了一个网络映像。我可以看到在你的stacktrace中有一个错误抛出在iterable.dartmoveNext。所以它让我认为你的问题是由一个无效的循环或类似的东西引起的。

6pp0gazn

6pp0gazn3#

我也犯了同样的错误,做了这些事情,它起作用了。
1.使用demangleStackTrace函数
1.在终端中运行flutter clean命令,然后将Firebase依赖项升级到新版本。

相关问题