daohoangson / flutter_widget_from_html

Flutter package to render html as widgets that supports hyperlink, image, audio, video, iframe and many other tags.
https://pub.dev/packages/flutter_widget_from_html
MIT License
629 stars 232 forks source link

Strange inconsistent unmounted (memory) error: #834

Closed bksubhuti closed 1 year ago

bksubhuti commented 1 year ago

Strange inconsistent memory error:

throw FlutterError(
          'This widget has been unmounted, so the State no longer has a context (and should be considered defunct). \n'
          'Consider canceling any active work during "dispose" or using the "mounted" getter to determine if the State is still active.',
        );

our production code seems to work fine. I'm working to add some more books but there seems to be a problem and it is inconsistent for this above error message.

We implement our own clickable because HtmlWidget does not (yet?) support clickable and multiple formatting (like css) on the same line at the same time. To fix this we make every single word a "<a href>"

String makeClickable(String html) {
  final regexPaliWord = RegExp(r'[a-zA-ZāīūṅñṭḍṇḷṃĀĪŪṄÑṬḌHṆḶṂ]+(?![^<>]*>)');
  return html.replaceAllMapped(regexPaliWord,
      (match) => '<a href="${match.group(0)}">${match.group(0)}</a>');
}

I have included zip file with vanilla sample code for this issue. No db, no async, with a simple list view builder.

Steps to Reproduce

A vanilla app was created for testing and also reporting. During my testing I also removed all special characters but it still gave this message. Simply run the program in debug mode and scroll down 30 pages or so. You will get the message.. But you will get the message at various scroll points. At first we thought it was an async error, but there are no async calls in this sample app.

See attachment: Anchor.zip

anchor.zip

HTML
Tesing environment Linux for me desktop.. also reproducible maybe in mac with my other dev. https://github.com/bksubhuti/tipitaka-pali-reader This code and the database data link is found on the readme does not crash. You can find that in the pages dir. ``` flutter doctor -v [✓] Flutter (Channel stable, 3.3.7, on Ubuntu 22.04.1 LTS 5.15.0-52-generic, locale en_US.UTF-8) • Flutter version 3.3.7 on channel stable at /home/bhante/development/flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision e99c9c7cd9 (2 weeks ago), 2022-11-01 16:59:00 -0700 • Engine revision 857bd6b74c • Dart version 2.18.4 • DevTools version 2.15.0 Checking Android licenses is taking an unexpectedly long time...[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0) • Android SDK at /home/bhante/Android/Sdk • Platform android-33, build-tools 33.0.0 • Java binary at: /home/bhante/development/android-studio/jre/bin/java • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866) • All Android licenses accepted. [✓] Chrome - develop for the web • Chrome at google-chrome [✓] Linux toolchain - develop for Linux desktop • Ubuntu clang version 14.0.0-1ubuntu1 • cmake version 3.22.1 • ninja version 1.10.1 • pkg-config version 0.29.2 [✓] Android Studio (version 2021.3) • Android Studio at /home/bhante/development/android-studio • Flutter plugin version 71.0.3 • Dart plugin version 213.7433 • Java version OpenJDK Runtime Environment (build 11.0.13+0-b1751.21-8125866) [✓] VS Code (version 1.73.1) • VS Code at /usr/share/code • Flutter extension version 3.52.0 [✓] Connected device (2 available) • Linux (desktop) • linux • linux-x64 • Ubuntu 22.04.1 LTS 5.15.0-52-generic • Chrome (web) • chrome • web-javascript • Google Chrome 107.0.5304.110 [✓] HTTP Host Availability • All required HTTP hosts are available • No issues found! ``` ``` ```
## Expected results You can run the same code with https://pub.dev/packages/flutter_html and it will not throw this error.
daohoangson commented 1 year ago

Thank you for the detailed report. I'll see what can be done.

daohoangson commented 1 year ago

Updating to v0.9.0+1 should fix your issue.

bksubhuti commented 1 year ago

Confirmed as fixed in local attached anchor app zip in linux and also in our main real app tipitaka pali reader. Now we can continue with adding other translated books in our downloader.

I just wish I contacted you sooner.. this was very fast for the widget release. We appreciate your work on the html_widget and eagerly await your clickable improvements which we use for the dictionary but not the main reading page. For now, we are using the <A HREF>hack which "works" especially now. Eventually of course, we want to remove that. sadhu x 3 (well done)