Flutter_widget_from_html: Failed assertion data != null is not true

Created on 29 May 2019  Β·  9Comments  Β·  Source: daohoangson/flutter_widget_from_html

Since upgrading to version 0.2.1 I sometimes, but not always, get the following error:

The following assertion was thrown building HtmlWidget(dirty, dependencies: [_LocalizationsScope-[GlobalKey#b92f2], _InheritedTheme, DefaultTextStyle]):
'package:flutter_widget_from_html_core/src/data_classes.dart': Failed assertion: line 283 pos 16:
'data != null': is not true.

If I revert back to 0.2.0 the error goes away.

bug

Most helpful comment

I have tracked down the issue to cases where a link's text ends with a space. So <a href="example.com">test </a> will cause the error and <a href="example.com">test</a> will not.

So far in testing the <a> tags seem to be the only ones that have an issue with the space at the end. I also tested a leading space and that does not cause a problem.

All 9 comments

I found that if I update:

TextBit(this.block, this.data, this.style, {this.onTap})
     : assert(block != null),
      assert(data != null),
      assert(style != null);

to:

TextBit(this.block, this.data, this.style, {this.onTap});

in the core dart_classes.dart file the error stops. With these asserts removed all of the automated tests still pass. Is taking these asserts out going to cause some issue I just haven't seen yet? If not and you want me to open a PR let me know.

Have you been able to find a specific html that triggers the error?

If possible, a full stack trace would be helpful here too.

Removing the assertion doesn't affect the actual running code but they are there to catch errors early. (they are new in 0.2.1, probably why you didn't have issue with earlier version). I think this is a bug that should be tracked down and fix to avoid crashing when you release the app.

I have looked through html that does and doesn’t cause the issue but haven’t been able to find any differences. I’m away from my computer for the evening, but will post the full stack trace when I get to it in the morning.

Here is the full stack trace:

flutter: ══║ EXCEPTION CAUGHT BY WIDGETS LIBRARY β•žβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•
flutter: The following assertion was thrown building HtmlWidget(dirty, dependencies:
flutter: [_LocalizationsScope-[GlobalKey#3fcea], _InheritedTheme, DefaultTextStyle]):
flutter: 'package:flutter_widget_from_html_core/src/data_classes.dart': Failed assertion: line 283 pos 16:
flutter: 'data != null': is not true.
flutter:
flutter: Either the assertion indicates an error in the framework itself, or we should provide substantially
flutter: more information in this error message to help you determine and fix the underlying cause.
flutter: In either case, please report this assertion by filing a bug on GitHub:
flutter:   https://github.com/flutter/flutter/issues/new?template=BUG.md
flutter:
flutter: When the exception was thrown, this was the stack:
flutter: #2      new TextBit 
package:flutter_widget_from_html_core/src/data_classes.dart:283
flutter: #3      TextBit.rebuild 
package:flutter_widget_from_html_core/src/data_classes.dart:298
flutter: #4      TagA._buildBlock.<anonymous closure> 
package:flutter_widget_from_html_core/…/ops/tag_a.dart:30
flutter: #5      TextBlock.rebuildBits 
package:flutter_widget_from_html_core/src/data_classes.dart:367
flutter: #6      TextBlock.rebuildBits 
package:flutter_widget_from_html_core/src/data_classes.dart:363
flutter: #7      TagA._buildBlock 
package:flutter_widget_from_html_core/…/ops/tag_a.dart:30
flutter: #8      TagA.buildOp.<anonymous closure>.<anonymous closure> 
package:flutter_widget_from_html_core/…/ops/tag_a.dart:24
flutter: #9      MappedListIterable.elementAt  (dart:_internal/iterable.dart:414:29)
flutter: #10     ListIterator.moveNext  (dart:_internal/iterable.dart:343:26)
flutter: #11     Builder.process 
package:flutter_widget_from_html_core/src/builder.dart:133
flutter: #12     Builder.build 
package:flutter_widget_from_html_core/src/builder.dart:43
flutter: #13     Builder.process 
package:flutter_widget_from_html_core/src/builder.dart:128
flutter: #14     Builder.build 
package:flutter_widget_from_html_core/src/builder.dart:43
flutter: #15     HtmlWidget.build 
package:flutter_widget_from_html_core/src/core_html_widget.dart:53
flutter: #16     StatelessElement.build 
package:flutter/…/widgets/framework.dart:3789
flutter: #17     ComponentElement.performRebuild 
package:flutter/…/widgets/framework.dart:3739
flutter: #18     Element.rebuild 
package:flutter/…/widgets/framework.dart:3565
flutter: #19     ComponentElement._firstBuild 
package:flutter/…/widgets/framework.dart:3722
flutter: #20     ComponentElement.mount 
package:flutter/…/widgets/framework.dart:3717
flutter: #21     Element.inflateWidget 
package:flutter/…/widgets/framework.dart:2961
flutter: #22     MultiChildRenderObjectElement.mount 
package:flutter/…/widgets/framework.dart:4982
flutter: #23     Element.inflateWidget 
package:flutter/…/widgets/framework.dart:2961
flutter: #24     Element.updateChild 
package:flutter/…/widgets/framework.dart:2764
flutter: #25     SingleChildRenderObjectElement.mount 
package:flutter/…/widgets/framework.dart:4876
flutter: #26     Element.inflateWidget 
package:flutter/…/widgets/framework.dart:2961
flutter: #27     Element.updateChild 
package:flutter/…/widgets/framework.dart:2764
flutter: #28     SingleChildRenderObjectElement.mount 
package:flutter/…/widgets/framework.dart:4876
flutter: #29     Element.inflateWidget 
package:flutter/…/widgets/framework.dart:2961
flutter: #30     Element.updateChild 
package:flutter/…/widgets/framework.dart:2764
flutter: #31     SingleChildRenderObjectElement.mount 
package:flutter/…/widgets/framework.dart:4876
flutter: #32     Element.inflateWidget 
package:flutter/…/widgets/framework.dart:2961
flutter: #33     Element.updateChild 
package:flutter/…/widgets/framework.dart:2764
flutter: #34     SingleChildRenderObjectElement.mount 
package:flutter/…/widgets/framework.dart:4876
flutter: #35     Element.inflateWidget 
package:flutter/…/widgets/framework.dart:2961
flutter: #36     Element.updateChild 
package:flutter/…/widgets/framework.dart:2764
flutter: #37     SingleChildRenderObjectElement.mount 
package:flutter/…/widgets/framework.dart:4876
flutter: #38     Element.inflateWidget 
package:flutter/…/widgets/framework.dart:2961
flutter: #39     Element.updateChild 
package:flutter/…/widgets/framework.dart:2764
flutter: #40     SingleChildRenderObjectElement.mount 
package:flutter/…/widgets/framework.dart:4876
flutter: #41     Element.inflateWidget 
package:flutter/…/widgets/framework.dart:2961
flutter: #42     Element.updateChild 
package:flutter/…/widgets/framework.dart:2764
flutter: #43     ComponentElement.performRebuild 
package:flutter/…/widgets/framework.dart:3750

I have tracked down the issue to cases where a link's text ends with a space. So <a href="example.com">test </a> will cause the error and <a href="example.com">test</a> will not.

So far in testing the <a> tags seem to be the only ones that have an issue with the space at the end. I also tested a leading space and that does not cause a problem.

That's really helpful, new version is coming out soon to address this issue.

v0.2.1+1 has been released with the fix for this. Please try upgrading, thank you.

The update solved the issue. Thanks.

This exact same issue was affecting me for a while now. And it suddenly disappeared after I upgraded the package today. Thanks a lot @sanders41 for tracking it down and @daohoangson for fixing it!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ahmadkhedr picture ahmadkhedr  Β·  4Comments

LauDijksterhuis picture LauDijksterhuis  Β·  5Comments

shofi-ishraak picture shofi-ishraak  Β·  6Comments

ahmadkhedr picture ahmadkhedr  Β·  6Comments

mclark4386 picture mclark4386  Β·  3Comments