我需要一个包含一些文本的容器来自动展开。我有一个 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
),),
],
),
),
],
),
),
],
),
),
我只需要容器扩展,但保持小/变大
最佳答案
您是否尝试过完全不指定 height
?在这种情况下,Container
应该根据 child 包装。
Otherwise, the widget has a child but no height, no width, no constraints, and no alignment, and the Container passes the constraints from the parent to the child and sizes itself to match the child.
以上是 Container
官方 flutter 文档的摘录。
这里是 flutter 的官方文档 link .
关于flutter - flutter 中的自动扩展容器——适用于所有设备,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55609811/