Skip to content

MarkdownElementBuilder.visitElementAfter produces assertion error #139130

Open
@Repox

Description

Is there an existing issue for this?

Steps to reproduce

Create an extended class of MarkdownElementBuilder and override the visitElementAfter method.

Run it.

Expected results

In my code sample, the p paragraph containing the "Hello World" shouldbe replaced with a Text widget containing the text replaced "Replaced".

Actual results

An exception is fired:

The following assertion was thrown building Container(padding: EdgeInsets.all(20.0), bg: BoxDecoration(color: Color(0xfffbfcfe), borderRadius: BorderRadius.circular(10.0))):
'package:flutter_markdown/src/builder.dart': Failed assertion: line 199 pos 12: '_inlines.isEmpty': is not true.

Code sample

Code sample

Build a widget containing MarkdownBody:

SizedBox(
    width: 400,
    child: MarkdownBody(
        data: '## Prompt\n\nHello World\n',
        selectable: true,
       builders: {
           'p': ParagraphBuilder(),
       },
    ),
)

ParagraphBuilder:

class ParagraphBuilder extends MarkdownElementBuilder {
  @override
  Widget visitElementAfter(md.Element element, _) {
    return Text('Replaced');
  }
}

Screenshots or Video

Screenshots / Video demonstration

Skærmbillede 2023-11-28 kl  11 11 04

Logs

Logs
======== Exception caught by widgets library =======================================================
The following assertion was thrown building Container(padding: EdgeInsets.all(20.0), bg: BoxDecoration(color: Color(0xfffbfcfe), borderRadius: BorderRadius.circular(10.0))):
'package:flutter_markdown/src/builder.dart': Failed assertion: line 199 pos 12: '_inlines.isEmpty': is not true.

The relevant error-causing widget was: 
  Container Container:file:///Users/danstorm/StudioProjects/ollamaui/lib/screens/partials/new_chat.dart:32:12
When the exception was thrown, this was the stack: 
#2      MarkdownBuilder.build (package:flutter_markdown/src/builder.dart:199:12)
#3      _MarkdownWidgetState._parseMarkdown (package:flutter_markdown/src/widget.dart:360:25)
#4      _MarkdownWidgetState.didUpdateWidget (package:flutter_markdown/src/widget.dart:313:7)
#5      StatefulElement.update (package:flutter/src/widgets/framework.dart:5652:55)
#6      Element.updateChild (package:flutter/src/widgets/framework.dart:3824:15)
#7      SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6765:14)
#8      Element.updateChild (package:flutter/src/widgets/framework.dart:3824:15)
#9      Element.updateChildren (package:flutter/src/widgets/framework.dart:3973:32)
#10     MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6918:17)
#11     Element.updateChild (package:flutter/src/widgets/framework.dart:3824:15)
#12     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6765:14)
#13     Element.updateChild (package:flutter/src/widgets/framework.dart:3824:15)
#14     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6765:14)
#15     Element.updateChild (package:flutter/src/widgets/framework.dart:3824:15)
#16     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5505:16)
#17     Element.rebuild (package:flutter/src/widgets/framework.dart:5196:7)
#18     StatelessElement.update (package:flutter/src/widgets/framework.dart:5556:5)
#19     Element.updateChild (package:flutter/src/widgets/framework.dart:3824:15)
#20     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5505:16)
#21     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5643:11)
#22     Element.rebuild (package:flutter/src/widgets/framework.dart:5196:7)
#23     StatefulElement.update (package:flutter/src/widgets/framework.dart:5666:5)
#24     Element.updateChild (package:flutter/src/widgets/framework.dart:3824:15)
#25     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5505:16)
#26     Element.rebuild (package:flutter/src/widgets/framework.dart:5196:7)
#27     ProxyElement.update (package:flutter/src/widgets/framework.dart:5809:5)
#28     Element.updateChild (package:flutter/src/widgets/framework.dart:3824:15)
#29     Element.updateChildren (package:flutter/src/widgets/framework.dart:3973:32)
#30     MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6918:17)
#31     Element.updateChild (package:flutter/src/widgets/framework.dart:3824:15)
#32     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6765:14)
#33     Element.updateChild (package:flutter/src/widgets/framework.dart:3824:15)
#34     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5505:16)
#35     Element.rebuild (package:flutter/src/widgets/framework.dart:5196:7)
#36     ProxyElement.update (package:flutter/src/widgets/framework.dart:5809:5)
#37     Element.updateChild (package:flutter/src/widgets/framework.dart:3824:15)
#38     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5505:16)
#39     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5643:11)
#40     Element.rebuild (package:flutter/src/widgets/framework.dart:5196:7)
#41     StatefulElement.update (package:flutter/src/widgets/framework.dart:5666:5)
#42     Element.updateChild (package:flutter/src/widgets/framework.dart:3824:15)
#43     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5505:16)
#44     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5643:11)
#45     Element.rebuild (package:flutter/src/widgets/framework.dart:5196:7)
#46     StatefulElement.update (package:flutter/src/widgets/framework.dart:5666:5)
#47     Element.updateChild (package:flutter/src/widgets/framework.dart:3824:15)
#48     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5505:16)
#49     Element.rebuild (package:flutter/src/widgets/framework.dart:5196:7)
#50     StatelessElement.update (package:flutter/src/widgets/framework.dart:5556:5)
#51     Element.updateChild (package:flutter/src/widgets/framework.dart:3824:15)
#52     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5505:16)
#53     Element.rebuild (package:flutter/src/widgets/framework.dart:5196:7)
#54     StatelessElement.update (package:flutter/src/widgets/framework.dart:5556:5)
#55     Element.updateChild (package:flutter/src/widgets/framework.dart:3824:15)
#56     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5505:16)
#57     Element.rebuild (package:flutter/src/widgets/framework.dart:5196:7)
#58     ProxyElement.update (package:flutter/src/widgets/framework.dart:5809:5)
#59     Element.updateChild (package:flutter/src/widgets/framework.dart:3824:15)
#60     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5505:16)
#61     Element.rebuild (package:flutter/src/widgets/framework.dart:5196:7)
#62     ProxyElement.update (package:flutter/src/widgets/framework.dart:5809:5)
#63     Element.updateChild (package:flutter/src/widgets/framework.dart:3824:15)
#64     Element.updateChildren (package:flutter/src/widgets/framework.dart:3973:32)
#65     MultiChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6918:17)
#66     Element.updateChild (package:flutter/src/widgets/framework.dart:3824:15)
#67     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5505:16)
#68     Element.rebuild (package:flutter/src/widgets/framework.dart:5196:7)
#69     ProxyElement.update (package:flutter/src/widgets/framework.dart:5809:5)
#70     Element.updateChild (package:flutter/src/widgets/framework.dart:3824:15)
#71     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5505:16)
#72     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5643:11)
#73     Element.rebuild (package:flutter/src/widgets/framework.dart:5196:7)
#74     StatefulElement.update (package:flutter/src/widgets/framework.dart:5666:5)
#75     Element.updateChild (package:flutter/src/widgets/framework.dart:3824:15)
#76     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5505:16)
#77     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5643:11)
#78     Element.rebuild (package:flutter/src/widgets/framework.dart:5196:7)
#79     StatefulElement.update (package:flutter/src/widgets/framework.dart:5666:5)
#80     Element.updateChild (package:flutter/src/widgets/framework.dart:3824:15)
#81     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5505:16)
#82     Element.rebuild (package:flutter/src/widgets/framework.dart:5196:7)
#83     ProxyElement.update (package:flutter/src/widgets/framework.dart:5809:5)
#84     Element.updateChild (package:flutter/src/widgets/framework.dart:3824:15)
#85     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5505:16)
#86     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5643:11)
#87     Element.rebuild (package:flutter/src/widgets/framework.dart:5196:7)
#88     StatefulElement.update (package:flutter/src/widgets/framework.dart:5666:5)
#89     Element.updateChild (package:flutter/src/widgets/framework.dart:3824:15)
#90     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6765:14)
#91     Element.updateChild (package:flutter/src/widgets/framework.dart:3824:15)
#92     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5505:16)
#93     Element.rebuild (package:flutter/src/widgets/framework.dart:5196:7)
#94     ProxyElement.update (package:flutter/src/widgets/framework.dart:5809:5)
#95     Element.updateChild (package:flutter/src/widgets/framework.dart:3824:15)
#96     SingleChildRenderObjectElement.update (package:flutter/src/widgets/framework.dart:6765:14)
#97     Element.updateChild (package:flutter/src/widgets/framework.dart:3824:15)
#98     ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5505:16)
#99     StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5643:11)
#100    Element.rebuild (package:flutter/src/widgets/framework.dart:5196:7)
#101    StatefulElement.update (package:flutter/src/widgets/framework.dart:5666:5)
#102    Element.updateChild (package:flutter/src/widgets/framework.dart:3824:15)
#103    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5505:16)
#104    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5643:11)
#105    Element.rebuild (package:flutter/src/widgets/framework.dart:5196:7)
#106    StatefulElement.update (package:flutter/src/widgets/framework.dart:5666:5)
#107    Element.updateChild (package:flutter/src/widgets/framework.dart:3824:15)
#108    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5505:16)
#109    Element.rebuild (package:flutter/src/widgets/framework.dart:5196:7)
#110    ProxyElement.update (package:flutter/src/widgets/framework.dart:5809:5)
#111    Element.updateChild (package:flutter/src/widgets/framework.dart:3824:15)
#112    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5505:16)
#113    Element.rebuild (package:flutter/src/widgets/framework.dart:5196:7)
#114    ProxyElement.update (package:flutter/src/widgets/framework.dart:5809:5)
#115    Element.updateChild (package:flutter/src/widgets/framework.dart:3824:15)
#116    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5505:16)
#117    Element.rebuild (package:flutter/src/widgets/framework.dart:5196:7)
#118    ProxyElement.update (package:flutter/src/widgets/framework.dart:5809:5)
#119    Element.updateChild (package:flutter/src/widgets/framework.dart:3824:15)
#120    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5505:16)
#121    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5643:11)
#122    Element.rebuild (package:flutter/src/widgets/framework.dart:5196:7)
#123    StatefulElement.update (package:flutter/src/widgets/framework.dart:5666:5)
#124    Element.updateChild (package:flutter/src/widgets/framework.dart:3824:15)
#125    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5505:16)
#126    Element.rebuild (package:flutter/src/widgets/framework.dart:5196:7)
#127    ProxyElement.update (package:flutter/src/widgets/framework.dart:5809:5)
#128    Element.updateChild (package:flutter/src/widgets/framework.dart:3824:15)
#129    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5505:16)
#130    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5643:11)
#131    Element.rebuild (package:flutter/src/widgets/framework.dart:5196:7)
#132    StatefulElement.update (package:flutter/src/widgets/framework.dart:5666:5)
#133    Element.updateChild (package:flutter/src/widgets/framework.dart:3824:15)
#134    ComponentElement.performRebuild (package:flutter/src/widgets/framework.dart:5505:16)
#135    StatefulElement.performRebuild (package:flutter/src/widgets/framework.dart:5643:11)
#136    Element.rebuild (package:flutter/src/widgets/framework.dart:5196:7)
#137    BuildOwner.buildScope (package:flutter/src/widgets/framework.dart:2904:19)
#138    WidgetsBinding.drawFrame (package:flutter/src/widgets/binding.dart:989:21)
#139    RendererBinding._handlePersistentFrameCallback (package:flutter/src/rendering/binding.dart:448:5)
#140    SchedulerBinding._invokeFrameCallback (package:flutter/src/scheduler/binding.dart:1386:15)
#141    SchedulerBinding.handleDrawFrame (package:flutter/src/scheduler/binding.dart:1311:9)
#142    SchedulerBinding.scheduleWarmUpFrame.<anonymous closure> (package:flutter/src/scheduler/binding.dart:1034:7)
#146    _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)
(elided 5 frames from class _AssertionError, class _Timer, and dart:async-patch)
====================================================================================================

Flutter Doctor output

Doctor output
[✓] Flutter (Channel master, 3.17.0-16.0.pre.7, on macOS 14.1.1 23B81 darwin-arm64, locale da-DK)
    • Flutter version 3.17.0-16.0.pre.7 on channel master at /Users/danstorm/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision c45f583799 (29 hours ago), 2023-11-27 00:04:28 -0500
    • Engine revision 292a92166a
    • Dart version 3.3.0 (build 3.3.0-152.0.dev)
    • DevTools version 2.30.0-dev.4

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/danstorm/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 15.0)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 15A240d
    • CocoaPods version 1.14.3

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.3)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b829.9-10027231)

[✓] IntelliJ IDEA Ultimate Edition (version 2023.2.5)
    • IntelliJ at /Applications/IntelliJ IDEA.app
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin version 232.10248

[✓] IntelliJ IDEA Ultimate Edition (version EAP IU-233.9802.14)
    • IntelliJ at /Applications/IntelliJ IDEA 2023.3 EAP.app
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart

[✓] Connected device (2 available)
    • macOS (desktop) • macos  • darwin-arm64   • macOS 14.1.1 23B81 darwin-arm64
    • Chrome (web)    • chrome • web-javascript • Google Chrome 119.0.6045.159

[✓] Network resources
    • All expected network resources are available.

• No issues found!

Metadata

Assignees

No one assigned

    Labels

    P3Issues that are less important to the Flutter projectc: crashStack traces logged to the consolefound in release: 3.16Found to occur in 3.16found in release: 3.17Found to occur in 3.17has reproducible stepsThe issue has been confirmed reproducible and is ready to work onp: flutter_markdownflutter/packages flutter_markdownpackageflutter/packages repository. See also p: labels.team-ecosystemOwned by Ecosystem teamtriaged-ecosystemTriaged by Ecosystem team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions