英文:
how to make two text widgets the same size even they have different text and different fontsize
问题
flutter如何使两个文本小部件具有相同的大小,即使它们具有不同的文本和不同的字体大小
我尝试过使用FittedBox,但不起作用
英文:
flutter how to make two text widgets the same size even they have different text and different fontsize
I have tried FittedBox but not working
答案1
得分: 0
我认为你希望它们具有相同的高度,对吗?
在这种情况下,你可以使用 IntrinsicHeight
。这将强制其子元素具有相同的高度(https://api.flutter.dev/flutter/widgets/IntrinsicHeight-class.html)
FittedBox
只在你想将一个小部件包含在另一个小部件内时使用。我建议观看YouTube视频:'FittedBox(Flutter Widget of the Week)'
以下是一个使用 IntrinsicHeight
的简单代码示例:
IntrinsicHeight(
child: Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Container(
color: Colors.blue,
child: Text(
'短但是很大的文字',
style: TextStyle(fontSize: 24),
),
),
SizedBox(width: 16),
Container(
color: Colors.red,
child: Text(
'较长的小文字与许多单词',
style: TextStyle(fontSize: 16),
),
),
],
),
),
英文:
I think, you want them to have the same height, right?
In that case you can use IntrinsicHeight
. This will will force its children to have the same height (https://api.flutter.dev/flutter/widgets/IntrinsicHeight-class.html)
FittedBox is only if you want to contain a widget inside another widget. I suggest watching on YT: 'FittedBox (Flutter Widget of the Week)'
Here is a simple Code example with IntrinsicHeight
:
IntrinsicHeight(
child: Row(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Container(
color: Colors.blue,
child: Text(
'Short but big text',
style: TextStyle(fontSize: 24),
),
),
SizedBox(width: 16),
Container(
color: Colors.red,
child: Text(
'Longer smaller text with many words',
style: TextStyle(fontSize: 16),
),
),
],
),
),
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论