Android Fragments InAppWebView在FlutterFragment内部无法工作

ymdaylpp  于 12个月前  发布在  Android
关注(0)|答案(1)|浏览(151)

我试图将flutter库InAppWebView集成到一个使用传统XML布局文件构建的现有Android应用程序中。如果我使用FlutterActivity,那么一切似乎都可以工作,但是如果我尝试使用FlutterFragment,那么inAppWebView中会发生错误。我的目标是在片段中使用WebView,因为我需要它只占用屏幕的一部分。
也许关于片段的生命周期还有一些我还没有理解的地方,我希望有人能指出一些明显的我做错的地方。
Here is a demo project that reproduces the issue
1.我创建了一个Android应用程序和一个Flutter模块。
1.如果我在FlutterActivity中加载flutter小部件,则一切正常
1.如果我在FlutterFragment中加载flutter小部件,则会发生以下错误:

E/OpenGLRenderer: Unable to match the desired swap behavior.
E/flutter: [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: MissingPluginException(No implementation found for method setWebContentsDebuggingEnabled on channel com.pichillilorenzo/flutter_inappwebview_manager)
    #0      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:308:7)
    <asynchronous suspension>
    #1      InAppWebViewController.setWebContentsDebuggingEnabled (package:flutter_inappwebview/src/in_app_webview/in_app_webview_controller.dart:3817:12)
    <asynchronous suspension>
    #2      main (package:flutter_web_view/main.dart:11:5)
    <asynchronous suspension>

字符串
此错误发生在我尝试调用

await InAppWebViewController.setWebContentsDebuggingEnabled(true);


作为flutter模块中我的main.dart文件的Future main()函数中的第一件事。(main.dart文件包括来自InAppWebView库文档的示例代码)
4.如果我删除这一行以避免调用setWebContentsDebuggingEnabled导致错误,则会发生以下错误:

E/flutter: [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: PlatformException(error, java.lang.IllegalStateException: Trying to create a platform view of unregistered type: com.pichillilorenzo/flutter_inappwebview
        at io.flutter.plugin.platform.PlatformViewsController$1.createPlatformView(PlatformViewsController.java:489)
        at io.flutter.plugin.platform.PlatformViewsController$1.createForPlatformViewLayer(PlatformViewsController.java:163)
        at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.create(PlatformViewsChannel.java:105)
        at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.onMethodCall(PlatformViewsChannel.java:55)
        at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:258)
        at io.flutter.embedding.engine.dart.DartMessenger.invokeHandler(DartMessenger.java:295)
        at io.flutter.embedding.engine.dart.DartMessenger.lambda$dispatchMessageToQueue$0$io-flutter-embedding-engine-dart-DartMessenger(DartMessenger.java:322)
        at io.flutter.embedding.engine.dart.DartMessenger$$ExternalSyntheticLambda0.run(Unknown Source:12)
        at android.os.Handler.handleCallback(Handler.java:958)
        at android.os.Handler.dispatchMessage(Handler.java:99)
        at android.os.Looper.loopOnce(Looper.java:205)
        at android.os.Looper.loop(Looper.java:294)
        at android.app.ActivityThread.main(ActivityThread.java:8176)
        at java.lang.reflect.Method.invoke(Native Method)
        at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:552)
        at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:971)
    , null, null)
    #0      StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:652:7)
    #1      MethodChannel._invokeMethod (package:flutter/src/services/platform_channel.dart:310:18)
    <asynchronous suspension>
    #2      ExpensiveAndroidViewController._sendCreateMessage (package:flutter/src/services/platform_views.dart:1040:5)
    <asynchronous suspension>
    #3      AndroidViewController.create (package:flutter/src/services/platform_views.dart:763:5)
    <asynchronous suspension>


1.无论哪种方式,webview都不会加载。
1.我还在Flutter库的GitHub页面上打开了一个issue
我希望有人能帮我解决这个问题。提前谢谢你,祝你有美好的一天!

wf82jlnq

wf82jlnq1#

我用Flutter活动,而不是Flutter碎片,现在工作得很好!

相关问题