java.lang.IllegalStateException:尝试创建未注册类型的平台视图:com.pichillilorenzo/flutter_inappwebview
Posted
技术标签:
【中文标题】java.lang.IllegalStateException:尝试创建未注册类型的平台视图:com.pichillilorenzo/flutter_inappwebview【英文标题】:java.lang.IllegalStateException: Trying to create a platform view of unregistered type: com.pichillilorenzo/flutter_inappwebview 【发布时间】:2020-08-12 12:35:15 【问题描述】:我使用这个库来显示一个解析的 epub 文件,它支持显示 .css。 flutter_inappwebview.
var doc = state.book.Chapters.last.htmlContent.split('<head>');
var styledTML = "\n" +
doc.first +
"\n" +
"<head>" +
"<style>" +
state.book.Content.Css['styles.css'].Content +
"</style>" +
doc.last;
return Material(
child: InAppWebView(
onWebViewCreated: (controller)
controller.loadData(data: styledTML);
,
initialOptions: InAppWebViewWidgetOptions(),
),
);
此代码在 ios 上完美运行,但在 android 上出现错误:
E/flutter ( 7880): [ERROR:flutter/lib/ui/ui_dart_state.cc(157)] Unhandled Exception: PlatformException(error, java.lang.IllegalStateException: Trying to create a platform view of unregistered type: com.pichillilorenzo/flutter_inappwebview
E/flutter ( 7880): at io.flutter.plugin.platform.PlatformViewsController$1.createPlatformView(PlatformViewsController.java:91)
E/flutter ( 7880): at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.create(PlatformViewsChannel.java:96)
E/flutter ( 7880): at io.flutter.embedding.engine.systemchannels.PlatformViewsChannel$1.onMethodCall(PlatformViewsChannel.java:60)
E/flutter ( 7880): at io.flutter.plugin.common.MethodChannel$IncomingMethodCallHandler.onMessage(MethodChannel.java:231)
E/flutter ( 7880): at io.flutter.embedding.engine.dart.DartMessenger.handleMessageFromDart(DartMessenger.java:93)
E/flutter ( 7880): at io.flutter.embedding.engine.FlutterJNI.handlePlatformMessage(FlutterJNI.java:642)
E/flutter ( 7880): at android.os.MessageQueue.nativePollOnce(Native Method)
E/flutter ( 7880): at android.os.MessageQueue.next(MessageQueue.java:326)
E/flutter ( 7880): at android.os.Looper.loop(Looper.java:160)
E/flutter ( 7880): at android.app.ActivityThread.main(ActivityThread.java:6669)
E/flutter ( 7880): at java.lang.reflect.Method.invoke(Native Method)
E/flutter ( 7880): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:493)
E/flutter ( 7880): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:858)
E/flutter ( 7880): , null)
E/flutter ( 7880): #0 StandardMethodCodec.decodeEnvelope (package:flutter/src/services/message_codecs.dart:569:7)
E/flutter ( 7880): #1 MethodChannel.invokeMethod (package:flutter/src/services/platform_channel.dart:321:33)
E/flutter ( 7880): <asynchronous suspension>
E/flutter ( 7880): #2 AndroidViewController._create (package:flutter/src/services/platform_views.dart:640:54)
E/flutter ( 7880): #3 AndroidViewController.setSize (package:flutter/src/services/platform_views.dart:557:14)
E/flutter ( 7880): #4 RenderAndroidView._sizePlatformView (package:flutter/src/rendering/platform_view.dart:174:29)
E/flutter ( 7880): #5 RenderAndroidView.performResize (package:flutter/src/rendering/platform_view.dart:155:5)
E/flutter ( 7880): #6 RenderObject.layout (package:flutter/src/rendering/object.dart:1703:9)
E/flutter ( 7880): #7 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
E/flutter ( 7880): #8 RenderObject.layout (package:flutter/src/rendering/object.dart:1724:7)
E/flutter ( 7880): #9 RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:105:13)
E/flutter ( 7880): #10 RenderObject._layoutWithoutResize (package:flutter/src/rendering/object.dart:1584:7)
E/flutter ( 7880): #11 PipelineOwner.flushLayout (package:flutter/src/rendering/object.dart:844:18)
E/flutter ( 7880): #12 RendererBinding.drawFrame (package:flutter/src/rendering/binding.dart:344:19)
E/flutter ( 7880): #13 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:774:13)
E/flutter ( 7880): #14 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:283:5)
E/flutter ( 7880): #15 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1102:15)
E/flutter ( 7880): #16 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1041:9)
E/flutter ( 7880): #17 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:957:5)
E/flutter ( 7880): #18 _rootRun (dart:async/zone.dart:1126:13)
E/flutter ( 7880): #19 _CustomZone.run (dart:async/zone.dart:1023:19)
E/flutter ( 7880): #20 _CustomZone.runGuarded (dart:async/zone.dart:925:7)
E/flutter ( 7880): #21 _invoke (dart:ui/hooks.dart:259:10)
E/flutter ( 7880): #22 _drawFrame (dart:ui/hooks.dart:217:3)
E/flutter ( 7880):
我试过flutter clean
。重启IDE。我的项目是 AndroidX 项目,我在 Manifest 中放了 Internet 权限,我的项目超过 API 21,但它仍然崩溃。我怎样才能反映这个 HTML。我感谢您的时间和想法。谢谢
【问题讨论】:
我已经更新了我的插件flutter_inappwebview!现在您可以使用版本3.0.0
+。最新版本是3.3.0
。
我有 3.3.0 仍然显示此错误。
【参考方案1】:
flutter clean
之后运行应用程序
【讨论】:
以上是关于java.lang.IllegalStateException:尝试创建未注册类型的平台视图:com.pichillilorenzo/flutter_inappwebview的主要内容,如果未能解决你的问题,请参考以下文章