Ran*_*ndy 10 expand containers flutter
我需要一个带有一些文本的容器来自动展开。我有一个 API 调用,可以是 5 个字到 500 个字。我不想只有 1 个很大的固定大小,但包含 10 个单词。
我试过 Expanded() 和 SizedBox.Expand(),但我可能用错了它们
Card(
elevation: defaultTargetPlatform ==
TargetPlatform.android ? 5.0 : 0.0,
child: Column(
children: <Widget>[
Container(
margin: const EdgeInsets.all(0.0),
padding: const EdgeInsets.all(2.0),
decoration: BoxDecoration(color: Colors.black),
width: _screenSize.width,
height: 250,
child: Column(
children: <Widget>[
Container(
color: Colors.black,
width: _screenSize.width,
height: 35,
child: Padding(
padding: const EdgeInsets.only(
left: 15, top: 11),
child: Text("Title".toUpperCase(),
style: TextStyle(
color: Colors.white
),
),
),
),
Container(
color: Colors.white,
width: _screenSize.width,
height: 210,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(top: 8, bottom: 5),
child: Text("Title of expanding text", style: TextStyle(
fontSize: 25,
),
),
),
Text("Expanding text", style: TextStyle(
fontSize: 35,
fontWeight: FontWeight.w800
),),
],
),
),
],
),
),
],
),
),
Run Code Online (Sandbox Code Playgroud)
我只需要容器扩展,但保持小/变大
Sid*_*kar 17
您是否尝试过完全不指定height?Container在这种情况下,应该根据孩子进行包装。
否则,widget 有一个孩子,但没有高度、宽度、没有约束和对齐,容器将约束从父级传递给子级,并调整自己的大小以匹配子级。
以上是 .flutter 官方文档的摘录Container。
这是官方的颤振文档链接。
Kal*_*ani 14
您可以使用FittedBox,这将根据可用区域调整文本大小。
你可以这样使用它:
FittedBox(child: Text('...............Your text...............'));
Run Code Online (Sandbox Code Playgroud)
Yog*_*odo 10
我们只需要在子项内部或子项设置的位置添加mainAxisSize: MainAxisSize.min,属性 ColumnRowContainer
例如
AnythingYourWidget(
child: Container(
child: Column( // For Example Column
mainAxisSize: MainAxisSize.min, // these properties following the children content height available.
children: [
// YourWidget
]
)
)
),
Run Code Online (Sandbox Code Playgroud)
小智 5
我建议你使用约束......这将根据文本孩子的要求设置容器高度。请看例子...
Container(
constraints: BoxConstraints(
maxHeight: double.infinity,
),
child: Column(
children: [
Text(
'Hello flutter...i like flutter...i like google...',
softWrap: true,
style: TextStyle(
color: Colors.white, fontSize: 20 , ),
),],),)
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
45933 次 |
| 最近记录: |