英文:
Aligning Text with Container/Icon in Row
问题
我的问题:将Text与Container / Icon在Row中对齐
当前输出:(我想要将这条蓝线与文本水平居中对齐)

预期输出:(红色水平线作为指南)

我的当前代码:
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Unit Details',
style: textTheme.bodyLarge,
),
kHorizontalSpaceS,
Container(
height: 4,
width: 42,
decoration: BoxDecoration(
color: Pallete.brandColor,
borderRadius: BorderRadius.circular(16),
),
),
],
),
我对Text的基线了解不多,但我尝试过使用CrossAxisAlignment.baseline,但它不起作用。
我如何将这个蓝色的Container与文本水平对齐?
在将Icon和Text在Row中对齐方面,我遇到了类似的问题。
英文:
My Issue: Aligning Text with Container / Icon in Row
Current Output: (I want to align this blue line with text horizontally center)

Expected Output: (Red horizontal line for a guideline)

My current code:
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Unit Details',
style: textTheme.bodyLarge,
),
kHorizontalSpaceS,
Container(
height: 4,
width: 42,
decoration: BoxDecoration(
color: Pallete.brandColor,
borderRadius: BorderRadius.circular(16),
),
),
],
),
I have less knowledge about Text baseline, but I tried with CrossAxisAlignment.baseline but it's not working.
How can I horizontally align this blue Container with the text?
I faced a similar issue with aligning Icon and Text in Row.
答案1
得分: 1
我认为你应该使用mainAxisAlignment,因为它是一行。
英文:
I think you should use mainAxisAlignment since it is a row.
答案2
得分: 1
我认为问题可能出在TextStyle上,也许您的文本样式高度大于1,因为我在我的一侧使用TextStyle(fontSize:30)运行了您的代码,它运行正常。
英文:
I think that the problem can be in TextStyle, maybe your text style height is greater than one, cause I run your code in my side with TextStyle(fontSize:30), and it works fine.
答案3
得分: -1
Container(
height: 20,
alignment: Alignment.centerLeft,
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [],
),
)
英文:
Can you wrap your code with Container and give needful height.
Container(
height: 20,
alignment: Alignment.centerLeft,
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [],
),
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。


评论