'!_debugLocked':不正确

发布于 2025-01-16 10:56:00 字数 1225 浏览 0 评论 0原文

功能:

    navigateToAudioScreen(file, aPlay) async {
//    await Future.delayed(Duration(seconds: 3));
    WidgetsBinding.instance!.addPostFrameCallback((_) async {
      await Future.delayed(Duration(seconds: 3));
      Navigator.pop(context, MaterialPageRoute(builder: (context) {
         return AudioPlayerScreen(
          a_play: aPlay,
          a_file: file,
        );
      }));
    }
    );
  }

错误:

flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: 'package:flutter/src/widgets/navigato
r.dart': Failed assertion: line 4842 pos 12: '!_debugLocked': is not true.
E/flutter (11069): #0      _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:47:61)
E/flutter (11069): #1      _AssertionError._throwNew (dart:core-patch/errors_patch.dart:36:5)
E/flutter (11069): #2      NavigatorState.pop (package:flutter/src/widgets/navigator.dart:4842:12)
E/flutter (11069): #3      Navigator.pop (package:flutter/src/widgets/navigator.dart:2432:27)
E/flutter (11069): #4      _HomePageState.navigateToAudioScreen.<anonymous closure> (/Screens/Home.dart:95
:17)

尝试:

  1. 尝试添加调度程序绑定
  2. 尝试添加小部件绑定
  3. 尝试添加未来延迟

Function:

    navigateToAudioScreen(file, aPlay) async {
//    await Future.delayed(Duration(seconds: 3));
    WidgetsBinding.instance!.addPostFrameCallback((_) async {
      await Future.delayed(Duration(seconds: 3));
      Navigator.pop(context, MaterialPageRoute(builder: (context) {
         return AudioPlayerScreen(
          a_play: aPlay,
          a_file: file,
        );
      }));
    }
    );
  }

Error:

flutter/lib/ui/ui_dart_state.cc(209)] Unhandled Exception: 'package:flutter/src/widgets/navigato
r.dart': Failed assertion: line 4842 pos 12: '!_debugLocked': is not true.
E/flutter (11069): #0      _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:47:61)
E/flutter (11069): #1      _AssertionError._throwNew (dart:core-patch/errors_patch.dart:36:5)
E/flutter (11069): #2      NavigatorState.pop (package:flutter/src/widgets/navigator.dart:4842:12)
E/flutter (11069): #3      Navigator.pop (package:flutter/src/widgets/navigator.dart:2432:27)
E/flutter (11069): #4      _HomePageState.navigateToAudioScreen.<anonymous closure> (/Screens/Home.dart:95
:17)

Attempts:

  1. Tried adding Scheduler Bind
  2. Tried adding Widget Bind
  3. Tried adding Future Delay

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

许你一世情深 2025-01-23 10:56:00

此错误可能是因为 Navigator.pop() 方法不将 MaterialPageRoute 作为参数,因此引发此错误。
您可以在以下位置查看更多信息: https://api.flutter.dev/ flutter/widgets/Navigator/pop.html

This error might be because Navigator.pop() method does not take MaterialPageRoute as a parameter and hence it is throwing this error.
You can check more on this at: https://api.flutter.dev/flutter/widgets/Navigator/pop.html

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文