Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: 5.0.2 不兼容 PopScope #2128

Open
yang-lile opened this issue Sep 3, 2024 · 1 comment
Open

[Bug]: 5.0.2 不兼容 PopScope #2128

yang-lile opened this issue Sep 3, 2024 · 1 comment

Comments

@yang-lile
Copy link

请描述遇到的问题,以及您所期望的正确的结果

在反复 push pop 时,不引发 crash

请说明如何操作会遇到上述问题

同时点击 webview 内部的按钮打开新的 webview 页面,点击左上角返回按钮并使用flutter的路由maybePop,网页事件回调由于异步延迟,会在pop中途引发 crash。

在下面填入关键复现代码

  @override
  Widget build(BuildContext context) {
    final title = widget.title;
    return PopScope(
      canPop: false,
      onPopInvoked: (didPop) async {
        if (kDebugMode) {
          print('didPop is: $didPop');
        }

        if (didPop) {
          return;
        }
        final shouldPop = await _onBack();
        if (context.mounted && shouldPop) {
          await GetIt.I<Navigation>().pop(context); // 触发点
        }
      },
      child: title == null ? _buildWebView() : _buildWebViewWithTitle(title),
    );
  }

  Future<bool> _onBack() async {
    final backHandler = widget.backHandler;
    if (backHandler != null) {
      return backHandler(_webViewController);
    }
    return true;
  }
      appBar: AppBar(
        backgroundColor: appTheme(context).generalBackground,
        leading: IconButton(
          icon:
              Icon(Icons.arrow_back_ios, color: appTheme(context).textPrimary),
          onPressed: Navigator.of(context).maybePop,// 返回按钮
        ),
      ),

核心crash

2024-09-03 15:49:33.812 24675-24802 flutter                           I  ----------------FIREBASE CRASHLYTICS----------------
2024-09-03 15:49:33.812 24675-24802 flutter                           I  'package:flutter_boost/src/boost_container.dart': Failed assertion: line 127 pos 12: 'container.topPage == page': is not true.
2024-09-03 15:49:33.813 24675-24802 flutter                           I  #0      _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:51:61)
                                                                                                    #1      _AssertionError._throwNew (dart:core-patch/errors_patch.dart:40:5)
                                                                                                    #2      BoostContainerState._updatePagesList (package:flutter_boost/src/boost_container.dart:127:12)
                                                                                                    #3      BoostContainerState.build.<anonymous closure> (package:flutter_boost/src/boost_container.dart:161:15)
                                                                                                    #4      NavigatorState.pop (package:flutter/src/widgets/navigator.dart:5280:28)
                                                                                                    #5      NavigatorExtState.pop (package:flutter_boost/src/boost_container.dart:228:13)
                                                                                                    #6      FlutterBoostAppState.pop (package:flutter_boost/src/flutter_boost_app.dart:517:34)
                                                                                                    #7      FlutterBoostAppState.popWithResult (package:flutter_boost/src/flutter_boost_app.dart:394:18)
                                                                                                    #8      BoostNavigator.pop (package:flutter_boost/src/boost_navigator.dart:113:28)
                                                                                                    #9      FlutterBoostNavigator.pop (package:boost_navigator/flutter_boost_navigator.dart:37:36)
                                                                                                    #10     _WebViewState.build.<anonymous closure> (package:flutter_module/widgets/base_webview_widget.dart:149:39)
                                                                                                    <asynchro
2024-09-03 15:49:33.813 24675-24802 flutter                           I  ----------------------------------------------------

crash 之后伴随的其他 crash:

2024-09-03 15:49:34.906 24675-24802 flutter                           I  ----------------FIREBASE CRASHLYTICS----------------
2024-09-03 15:49:34.906 24675-24802 flutter                           I  Bad state: Future already completed
2024-09-03 15:49:34.906 24675-24802 flutter                           I  #0      _AsyncCompleter.complete (dart:async/future_impl.dart:43:31)
                                                                                                    #1      Route.didComplete (package:flutter/src/widgets/navigator.dart:423:19)
                                                                                                    #2      Route.didPop (package:flutter/src/widgets/navigator.dart:401:5)
                                                                                                    #3      OverlayRoute.didPop (package:flutter/src/widgets/routes.dart:78:36)
                                                                                                    #4      TransitionRoute.didPop (package:flutter/src/widgets/routes.dart:307:18)
                                                                                                    #5      LocalHistoryRoute.didPop (package:flutter/src/widgets/routes.dart:869:18)
                                                                                                    #6      BoostContainerState.build.<anonymous closure> (package:flutter_boost/src/boost_container.dart:159:23)
                                                                                                    #7      NavigatorState.pop (package:flutter/src/widgets/navigator.dart:5280:28)
                                                                                                    #8      NavigatorExtState.pop (package:flutter_boost/src/boost_container.dart:228:13)
                                                                                                    #9      FlutterBoostAppState.pop (package:flutter_boost/src/flutter_boost_app.dart:517:34)
                                                                                                    #10     FlutterBoostAppState.popWithResult (package:flutter_boost/src/flutter_boost_app.dart:394:18)
                                                                                                    #11     BoostNavigator.pop (package:flutter_boost/src/boost_navigator.dart:113:28)
                                                                                                    #12     Flutte
2024-09-03 15:49:34.906 24675-24802 flutter                           I  ----------------------------------------------------
2024-09-03 15:49:38.415 24675-24802 flutter                           I  ----------------FIREBASE CRASHLYTICS----------------
2024-09-03 15:49:38.415 24675-24802 flutter                           I  'package:flutter/src/widgets/navigator.dart': Failed assertion: line 5273 pos 12: '!_debugLocked': is not true.
2024-09-03 15:49:38.415 24675-24802 flutter                           I  #0      _AssertionError._doThrowNew (dart:core-patch/errors_patch.dart:51:61)
                                                                                                    #1      _AssertionError._throwNew (dart:core-patch/errors_patch.dart:40:5)
                                                                                                    #2      NavigatorState.pop (package:flutter/src/widgets/navigator.dart:5273:12)
                                                                                                    #3      NavigatorExtState.pop (package:flutter_boost/src/boost_container.dart:228:13)
                                                                                                    #4      FlutterBoostAppState.pop (package:flutter_boost/src/flutter_boost_app.dart:517:34)
                                                                                                    #5      FlutterBoostAppState.popWithResult (package:flutter_boost/src/flutter_boost_app.dart:394:18)
                                                                                                    #6      BoostNavigator.pop (package:flutter_boost/src/boost_navigator.dart:113:28)
                                                                                                    #7      FlutterBoostNavigator.pop (package:boost_navigator/flutter_boost_navigator.dart:37:36)
                                                                                                    #8      _WebViewState.build.<anonymous closure> (package:flutter_module/widgets/base_webview_widget.dart:149:39)
                                                                                                    <asynchronous suspension>
2024-09-03 15:49:38.415 24675-24802 flutter                           I  ----------------------------------------------------

复现的平台

Both

Flutter SDK版本

3.22.1

FlutterBoost版本

5.0.2

是否延迟初始化FlutterBoost

No

解决方案

@yang-lile yang-lile changed the title [Bug]: 5.0.2 仍然出现 #1863 类似问题 [Bug]: 5.0.2 不兼容 PopScope Sep 4, 2024
@yang-lile
Copy link
Author

当使用 boost 带有的 pop 方法时,会出现不兼容的情况,表现为 onPopInvoked 只回调一次,并且 didPop 为 true,推测为 boost 的 pop 方法做了不该做的 maybePop方法导致。建议移出逻辑,解耦合

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant