Sub6Resources / flutter_html

A Flutter widget for rendering static html as Flutter widgets (Will render over 80 different html tags!)
https://pub.dev/packages/flutter_html
MIT License
1.8k stars 874 forks source link

[BUG]Unhandled Exception: setState() called after dispose(): _PlatformViewLinkState#0fbe8(lifecycle state: defunct, not mounted) #1171

Closed xxofficial closed 1 year ago

xxofficial commented 2 years ago

Describe the bug:

First the paltform is Android. And I am using a HTML """, customRenders: {iframeMatcher(): iframeRender(),}, ), ``` **Screenshots:**

7C)6_IS @MHB0UL43LBY){L

Device details and Flutter/Dart/flutter_html versions:

flutter_html: 3.0.0-alpha.6 flutter_html_iframe: ^3.0.0-alpha.4 Stacktrace/Logcat

E/flutter (18011): [ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: setState() called after dispose(): _PlatformViewLinkState#2605a(lifecycle state: defunct, not mounted)
E/flutter (18011): This error happens if you call setState() on a State object for a widget that no longer appears in the widget tree (e.g., whose parent widget no longer includes the widget in its build). This error can occur when code calls setState() from a timer or an animation callback.
E/flutter (18011): The preferred solution is to cancel the timer or stop listening to the animation in the dispose() callback. Another solution is to check the "mounted" property of this object before calling setState() to ensure the object is still in the tree.
E/flutter (18011): This error might indicate a memory leak if setState() is being called because another object is retaining a reference to this State object after it has been removed from the tree. To avoid memory leaks, consider breaking the reference to this object during dispose().
E/flutter (18011): #0      State.setState.<anonymous closure> (package:flutter/src/widgets/framework.dart:1078:9)
E/flutter (18011): #1      State.setState (package:flutter/src/widgets/framework.dart:1113:6)
E/flutter (18011): #2      _PlatformViewLinkState._onPlatformViewCreated (package:flutter/src/widgets/platform_view.dart:921:5)
E/flutter (18011): #3      AndroidViewController.create (package:flutter/src/services/platform_views.dart:796:15)
E/flutter (18011): <asynchronous suspension>

A picture of a cute animal (not mandatory but encouraged)

This is cute. right? OYCP8MYEWCOFZJV7CSOHX~A

Sub6Resources commented 1 year ago

In this case, I would recommend separating out the Html widget from the StatefulWidget using some sort of bloc or StreamBuilder to pass new data to the Html widget. Adding a key to the Html widget could also be helpful, depending on how your tree is formatted.