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

[QUESTION] How can i use raw string with variable? #1209

Closed nitinf22labs closed 1 year ago

nitinf22labs commented 1 year ago

Type question here.

How can i use raw string with variable? I want to use string coming from api or variable as raw.

 String equation =
        "The number of distinct solutions of the equation &nbsp;&nbsp;&nbsp;<tex>\frac{4}{5}</tex>&nbsp;&nbsp;&nbsp;";

Html(
              shrinkWrap: true,
            data: equation
            //  I want to append r""" before  $equation var
             //  data: r"""<tex>\frac 4 5</tex>""",
              customRenders: {
                texMatcher(): CustomRender.widget(
                    widget: (context, buildChildren) => Math.tex(
                          context.tree.element?.innerHtml ?? '',
                          mathStyle: MathStyle.display,
                          textStyle: context.style.generateTextStyle(),
                          onErrorFallback: (FlutterMathException e) {
                            //optionally try and correct the Tex string here
                            return Text(e.message);
                          },
                        )),
              },
              tagsList: Html.tags..add('tex'),

)

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

Sub6Resources commented 1 year ago

Raw strings don't allow variable input. I'm afraid the only option is using non-raw strings and escaping \ characters as needed.

See https://stackoverflow.com/a/55125624/6243324

Closing, since this is a dart syntax issue, not directly related to our package.