[BUG]Failed Assertion when URL is rendered
Describe the bug:
When including a link (<a href=""></a>) in the html content, I am getting an ambiguous bug:
'package:flutter/src/semantics/semantics.dart': Failed assertion: line 3023 pos 16: 'node.parent == null || !node.parent!.isPartOfNodeMerging || node.isMergedIntoParent': is not true.
When I remove the tag, everything functions normally. As soon as I add it back in, the bug returns.
HTML to reproduce the issue:
Today's lesson will be streamed via the following link:<div><br></div><div><a href="https://www.apple.com" rel="nofollow">Streaming Link</a><b><u></u></b><br></div>
Html widget configuration:
Widget buildEditable(){
return Container(
padding: const EdgeInsets.fromLTRB(8,5,8,5),
child: Center(
child: GestureDetector(
onTap: (){
_documentBloc.add(EditRichText(_node));
},
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(3.0),
boxShadow: <BoxShadow>[
BoxShadow(
color: Colors.black26,
offset: Offset(1, 2),
blurRadius: 1,
spreadRadius: 1)
],
),
child: Html(
data: _node.content,
shrinkWrap: true,
onLinkTap: (url, context, attributes, element) {
_documentBloc.add(EditRichText(_node));
},
)
),
)
)
);
Device details and Flutter/Dart/flutter_html versions:
iOS Simulator iPhone 12 Pro flutter_html 3.0.0-alpha.2 (Was also produced in version 2.2.1)
Stacktrace/Logcat ======== Exception caught by scheduler library ===================================================== The following assertion was thrown during a scheduler callback: 'package:flutter/src/semantics/semantics.dart': Failed assertion: line 3023 pos 16: 'node.parent == null || !node.parent!.isPartOfNodeMerging || node.isMergedIntoParent': is not true.
Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause. In either case, please report this assertion by filing a bug on GitHub: https://github.com/flutter/flutter/issues/new?template=2_bug.md
When the exception was thrown, this was the stack: #2 SemanticsOwner.sendSemanticsUpdate (package:flutter/src/semantics/semantics.dart:3023:16) #3 PipelineOwner.flushSemantics (package:flutter/src/rendering/object.dart:1098:24) #4 RendererBinding.drawFrame (package:flutter/src/rendering/binding.dart:502:21) #5 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:883:13) #6 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:363:5) #7 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1144:15) #8 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1081:9) #9 SchedulerBinding._handleDrawFrame (package:flutter/src/scheduler/binding.dart:995:5) #13 _invoke (dart:ui/hooks.dart:151:10) #14 PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:308:5) #15 _drawFrame (dart:ui/hooks.dart:115:31) (elided 5 frames from class _AssertionError and dart:async)
Additional info:
I am rendering multiple Containers with html in each container in rows...not sure if that is a problem to have multiple instances in one page.

This is part of a MUCH larger widget tree that I didn't include due to size and complexity. I started recreating the widget tree in a test project to narrow down the problem and was able to find the perpetrator. For some reason, an html widget containing a link (a tag) when inside a standard flutter Material "Reorderable List View" will trigger the error. See the minimal reproducible example:
import 'package:flutter/material.dart';
import 'package:flutter_html/flutter_html.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key? key}) : super(key: key);
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> with SingleTickerProviderStateMixin, WidgetsBindingObserver{
final ScrollController reorderScrollController = ScrollController();
Widget renderWidget(int index){
return Container(
key: ValueKey(index),
padding: const EdgeInsets.fromLTRB(8,5,8,5),
child: Html(
data: "Today's lesson will be streamed via the following link:<div><br></div><div><a href='https://www.apple.com'>Streaming Link</a><b><u></u></b><br></div>",
shrinkWrap: true,
onLinkTap: (url, context, attributes, element) {
},
)
);
}
@override
Widget build(BuildContext context) {
return Container(
color: Colors.white,
child: ReorderableListView(
scrollController: reorderScrollController,
onReorder: (int oldIndex, int newIndex){
},
children: [
renderWidget(1),
],
),
);
}
}
Leads to:
======== Exception caught by scheduler library ===================================================== The following assertion was thrown during a scheduler callback: 'package:flutter/src/semantics/semantics.dart': Failed assertion: line 3023 pos 16: 'node.parent == null || !node.parent!.isPartOfNodeMerging || node.isMergedIntoParent': is not true.
Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause. In either case, please report this assertion by filing a bug on GitHub: https://github.com/flutter/flutter/issues/new?template=2_bug.md
When the exception was thrown, this was the stack:
#2 SemanticsOwner.sendSemanticsUpdate (package:flutter/src/semantics/semantics.dart:3023:16)
#3 PipelineOwner.flushSemantics (package:flutter/src/rendering/object.dart:1098:24)
#4 RendererBinding.drawFrame (package:flutter/src/rendering/binding.dart:502:21)
#5 WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:883:13)
#6 RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:363:5)
#7 SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1144:15)
#8 SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1081:9)
#9 SchedulerBinding.scheduleWarmUpFrame. (package:flutter/src/scheduler/binding.dart:862:7)
(elided 6 frames from class _AssertionError, class _RawReceivePortImpl, class _Timer, and dart:async-patch)
Reloaded 1 of 645 libraries in 254ms.
Thanks for the minimal reproducible example. I'll look into this. Clever app idea too, brother 😉
After some investigation, I've had to forward this issue onto the Flutter team, as it turns out to be an issue with Flutter itself.
You can follow https://github.com/flutter/flutter/issues/126840 for updates.
This issue has been fixed in the Flutter master branch. Since the assertion doesn't cause a crash and since flutter_html is not at fault, I'm closing this.