Container(
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 60),
child: Text(
// subCategoryName,
"This is a very Long Text takes more space",
textAlign: TextAlign.center,
maxLines: 2,
overflow: TextOverflow.fade,
style: Theme.of(context)
.textTheme
.headline3
.copyWith(color: Colors.white, fontSize: 32),
),
),
),
Run Code Online (Sandbox Code Playgroud)
我需要这条线最多为两行,如果文本变得更长,则像 FittedBox(使用 BoxFit.fitWidth)一样缩小尺寸
当我使用 FittedBox 时,它看起来像这样。但如果需要的话,我需要将其增加到 2 行。任何解决方案都会受到赞赏
我正在使用animatedContainer 在按下按钮时显示 listView.builder() 。这是一个要显示的简单子列表,但问题是我不知道 ListView 构建器的高度是否要传递给animatedContainer 高度约束。有没有办法动态获取列表视图构建器的高度或任何其他方法来实现这一点?
我需要的?
height:属性,所以它会自动环绕子容器像这样的东西: https: //getbootstrap.com/docs/4.0/components/collapse/
AnimatedContainer(
duration: Duration(milliseconds: 200),
curve: Curves.easeIn,
height: _expanded ? 150 : 0, // This height I cannot set here explicitly. I need to set dynamically like, get child's height
child: ListView.builder(
key: listViewKey,
shrinkWrap: true,
scrollDirection: Axis.vertical,
physics: const NeverScrollableScrollPhysics(),
itemCount: loadedSubCategories.length,
itemBuilder: (ctx, i) => ChangeNotifierProvider.value(
value: loadedSubCategories[i],
child: SubCategoryItem(loadedSubCategories[i].categoryId,
loadedSubCategories[i].subCategoryId)),
),
),
Run Code Online (Sandbox Code Playgroud)
当我使用普通的 Container() 时,我不会设置该height:属性,以便它自动获取孩子的高度,但我需要高度,因为我想以动画方式扩展子类别。
具有不同高度的子类别的每个元素和子类别的数量也是未知的。因此计算高度subcategories.length也是不可能的。
非常感谢任何建议,谢谢