1

我想制作一个测验应用程序,其问题中可能包含数学方程式。我检查了一些库(如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),
        ),
      ),
    )

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

4

2 回答 2

1

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

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'),
          ],
        ),
      ),
    );
  
于 2020-11-27T18:54:17.250 回答
0
SingleChildScrollView(
              scrollDirection: Axis.horizontal,
              child: Container(
                padding: EdgeInsets.fromLTRB(10, 10, 10, 10),
                child: Text(
                  "What is the solutions of the quadratic equation X^2 + 6X + 8 = 0 ?",
                  //style: GoogleFonts.shortStack(color: Colors.white),
                ),
              ),
            ),
于 2020-11-27T19:50:30.730 回答