Flutter InAppWebview 无法检测 Web 应用程序的路由变化

问题描述 投票:0回答:1

Flutter InAppWebview 无法检测使用react-router-dom 的useNavigate 的Web 应用程序的路由更改。

我尝试过此操作,但无法检测网页路由更改。

React webapp 中用于路由的库是 useNavigate(),但它无法读取 Flutter InAppWebview 上的路由更改。 使用的 Flutter 插件是 flutter_inappwebview

   InAppWebView(
                initialSettings: initalSetting.value,
                initialUrlRequest:
                    URLRequest(url: WebUri(viewModel.prefillData!.bookingUrl)),
                onWebViewCreated: (controller) {
                  webviewController.value = controller;
                },
                onReceivedError: (controller, request, error) {
                  Logger.log.severe(error);
                },
                onCloseWindow: (controller) {
                  context.pop();
                },
                onCreateWindow: (controller, createWindowAction) async {
                  await Navigator.push(
                    context,
                    MaterialPageRoute(
                      builder: (context) => InAppWebViewWindow(
                        windowId: createWindowAction.windowId,
                        windowRequest: createWindowAction.request,
                      ),
                    ),
                  );

                  return Future.value(true);
                },
                onNavigationResponse: (controller, navigationResponse) async {
                  Logger.log.info('onConsoleMessage: $navigationResponse ');
                },
                onReceivedHttpError:
                    (controller, request, errorResponse) async {
                  AnalyticsManager.triggerEvent(
                    event: EventName.fincareErrorDebugLog,
                    filterAnalytics: [
                      AvailableAnalytics.firebaseAnalytics,
                      AvailableAnalytics.moengage,
                    ],
                    properties: {
                      'statusCode': errorResponse.statusCode,
                      'url': request.url.toString(),
                    },
                  );
                },
                onLoadStart: (controller, url) {
                  currentWebviewUri.value = url;
                },
                onLoadStop: (controller, url) async {
                  AnalyticsManager.triggerEvent(
                    event: EventName.fincareDebugLog,
                    filterAnalytics: [
                      AvailableAnalytics.firebaseAnalytics,
                      AvailableAnalytics.moengage,
                    ],
                    properties: {
                      EventProps.link: url.toString(),
                    },
                  );

                  var initialUrl = WebUri(
                    '${FlavorConfig.instance.values.ujjivanBaseUrl}apply',
                  );

                  await controller.injectCSSCode(
                    source:
                        '.navbar {visibility: hidden;display: none;} .TC {visibility:hidden;display: none;}',
                  );

                  if (!((url?.host == initialUrl.host) &&
                      (url?.path == initialUrl.path))) {
                    errorShown.value = true;
                  }
                },
              
                onProgressChanged: (controller, progress) {
                  pageProgress.value = progress;
                },
                onGeolocationPermissionsHidePrompt: (controller) {},
                onConsoleMessage: (controller, consoleMessage) {
                  Logger.log.severe(consoleMessage);
                },
                shouldOverrideUrlLoading: (controller, navigationAction) async {
                  var uri = navigationAction.request.url!;
                  return NavigationActionPolicy.ALLOW;
                },
              ),
flutter webview flutterwebviewplugin flutter-inappwebview inappwebview
1个回答
0
投票

我遇到了类似的问题,并通过在 webview 中重新加载解决了它:controller.reload());在 onLoadStop() 里面

© www.soinside.com 2019 - 2024. All rights reserved.