Flutter:如何将数学方程包装在容器中?

标签 flutter word-wrap flutter-text

我想制作一个测验应用程序,其问题中可能包含数学方程。我检查了一些库(例如 flutter_mathcatex ),它们非常适合渲染方程,但我面临的一个问题是没有文本换行选项

举个例子,假设我有一个问题:“二次方程 X^2 + 6X + 8 = 0 的解是什么?”。我希望将完整的文本与方程一起包装在一个容器中。

你能给我一个解决这个问题的好方法吗?

这是一个使用 flutter_math 包的示例。

Center(
      child: SizedBox(
        width: 300,
        height: 200,
        child: Math.tex(
          r'\text {What are the solutions of the quadratic equation } x^2+6x+8=0 \text { this is some question text following the equation.}',
          textStyle: TextStyle(fontSize: 25, color: Colors.black),
        ),
      ),
    )

此代码不会换行问题文本。相反,它会修剪文本。可能该包不支持包装。 我只需要一种在实际文本之间添加方程的好方法。

最佳答案

我想这就是你想要的。要在多行上显示文本和方程,请使用以下代码。

Center(
      child: SizedBox(
        width: 300,
        height: 200,
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.stretch,
          children: [
            Text('What are the solutions of the quadratic equation'),
            SizedBox(height: 2),
            Math.tex(
              r'x^2+6x+8=0',
              textStyle: TextStyle(fontSize: 25, color: Colors.black),
            ),
            SizedBox(height: 2),
            Text('this is some question text following the equation'),
          ],
        ),
      ),
    );

要在一行中使用文本和方程,请使用此

Center(
      child: SizedBox(
        width: 300,
        height: 200,
        child: Wrap(
          direction: Axis.horizontal,
          children: [
            Text('What are the solutions of the quadratic equation '),
            Math.tex(
              r'x^2+6x+8=0',
              textStyle: TextStyle(fontSize: 25, color: Colors.black),
            ),
            Text(' this is some question text following the equation'),
          ],
        ),
      ),
    );
  

关于Flutter:如何将数学方程包装在容器中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65038810/

相关文章:

iOS:使用 Word Wrap 以编程方式创建标签

flutter - body2 已弃用,不应使用。这是 2014 版 Material 设计中使用的术语。 - flutter 中的警告消息

Flutter:如何为Selectable Text构建自定义工具栏~

dart - 有没有办法始终在页面中禁用键盘?

flutter - 是否有稳定的小部件列表?

html - 防止在动态加载的 OPTION 中换行

jquery - 页面内容不居中,css,jquery

flutter - 布局: Text overflowing in Flutter

flutter - 使用 'GeoLocator' 包时无法获取纬度和经度

android - flutter : How to Fix SuffixIcon at the bottom of the Multiline Enable TextField?