如何在 flutter 中显示 Html 数学

问题描述 投票:0回答:2

这是我的 Html 文本

<p>hello</p>
    <div class="mathjax-equation">
        \(x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}\)
    </div>

我想在没有 Webview 包的情况下在 flutter 移动屏幕上显示这个数学视图。我该怎么办?

html flutter web math webview
2个回答
0
投票

检查这个包flutter_tex


class MathJaxExample extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('MathJax Example'),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: <Widget>[
              Text('Hello'),
              Mathjax(
                mathjaxText: r'$$x = \frac{-b \pm \sqrt{b^2 - 4ac}}{2a}$$',
                textStyle: TextStyle(fontSize: 24.0),
              ),
            ],
          ),
        ),
      ),
    );
  }
}

但我也建议你阅读该文档。


0
投票

您可以使用 math_tex_package 来显示数学方程,因为您将重新格式化编写公式的方式

TeXView(
    child: TeXViewColumn(children: [
      TeXViewInkWell(
        id: "id_0",
        child: TeXViewColumn(children: [
          TeXViewDocument(r"""<h2>Flutter \( \rm\\TeX \)</h2>""",
              style: TeXViewStyle(textAlign: TeXViewTextAlign.Center)),
          TeXViewContainer(
            child: TeXViewImage.network(
                'https://raw.githubusercontent.com/shah-xad/flutter_tex/master/example/assets/flutter_tex_banner.png'),
            style: TeXViewStyle(
              margin: TeXViewMargin.all(10),
              borderRadius: TeXViewBorderRadius.all(20),
            ),
          ),
          TeXViewDocument(r"""<p>                                
                       When \(a \ne 0 \), there are two solutions to \(ax^2 + bx + c = 0\) and they are
                       $$x = {-b \pm \sqrt{b^2-4ac} \over 2a}.$$</p>""",
              style: TeXViewStyle.fromCSS(
                  'padding: 15px; color: white; background: green'))
        ]),
      )
    ]),
    style: TeXViewStyle(
      elevation: 10,
      borderRadius: TeXViewBorderRadius.all(25),
      border: TeXViewBorder.all(TeXViewBorderDecoration(
          borderColor: Colors.blue,
          borderStyle: TeXViewBorderStyle.solid,
          borderWidth: 5)),
      backgroundColor: Colors.white,
    ),
   ),
  )
我仍然需要 html,您可以使用 在此处输入链接描述

© www.soinside.com 2019 - 2024. All rights reserved.