Flutter 颤振:如何在容器中包装数学方程?
我想做一个测验应用程序,它的问题中可能有数学方程。我检查了一些库(如和),它们很适合渲染方程,但我面临的一个问题是没有文本包装选项 例如,假设我有一个问题:“二次方程X^2+6X+8=0的解是什么?”。我希望完整的文本连同方程式一起包装在一个容器中 你能给我一个解决这个问题的好方法吗 下面是一个使用flatter_数学包的示例Flutter 颤振:如何在容器中包装数学方程?,flutter,word-wrap,flutter-text,Flutter,Word Wrap,Flutter Text,我想做一个测验应用程序,它的问题中可能有数学方程。我检查了一些库(如和),它们很适合渲染方程,但我面临的一个问题是没有文本包装选项 例如,假设我有一个问题:“二次方程X^2+6X+8=0的解是什么?”。我希望完整的文本连同方程式一起包装在一个容器中 你能给我一个解决这个问题的好方法吗 下面是一个使用flatter_数学包的示例 Center( child: SizedBox( width: 300, height: 200, child
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'),
],
),
),
);
你想把整个问题放在一个容器里,方程放在一个单独的子容器里吗?你能给我们看一些你已经尝试过的代码吗?好的,我会更新这个问题。好的,包装小部件就可以了。我不知道有这么一个小部件!但它并不完美,因为方程本身无法分裂。但我可以在需要的地方手动拆分(分成不同的数组元素),并在需要时进行包装。非常感谢,当然!没问题
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),
),
),
),