Flutter:垂直文本小部件 [英] Flutter: Vertical Text widget
问题描述
我在这里查找pub.dev和flutter文档,但找不到(或无法用词表达我的查询)此简单任务的任何解决方案。
I looked up here and pub.dev and flutter docs but could not find(or could not word my query) any solution for this simple task.
我想要显示 String
时,其字母从上到下,同时保持字母方向默认。因此,旋转的 Text()
不起作用。
I want to display a String
with its letters going from up to down while keeping the letter orientations default. So a rotated Text()
would not work.
我想要的结果是:
H
E
L T
L H
O A
N
W K
O S
R ❤️
L
D
也,我需要将 String
包装到下一行(在本例中为列),必须使用height参数来限制每一列从上到下的字母数。
Also, I would need to wrap the String
to the next line(column in this case) A height parameter is necessary to limit the number of letters from top to down for each column.
如果最后一部分太难实现了,我欢迎单列解决方案。
If this last part is too hard to implement, I am open to ideas for the single column solution.
推荐答案
截屏:
代码:
// Create a custom widget like this
class MyVerticalText extends StatelessWidget {
final String text;
const MyVerticalText(this.text);
@override
Widget build(BuildContext context) {
return Wrap(
runSpacing: 30,
direction: Axis.vertical,
alignment: WrapAlignment.center,
children: text.split("").map((string) => Text(string, style: TextStyle(fontSize: 22))).toList(),
);
}
}
并像这样使用它:
MyVerticalText("HELLO WORLD THANKS❤️")
这篇关于Flutter:垂直文本小部件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!