小编MBK*_*MBK的帖子

颤振中最多有两行的 fitbox

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 行。任何解决方案都会受到赞赏

flutter fitted-box

9
推荐指数
1
解决办法
6223
查看次数

具有 dynamix 高度的动画容器 Flutter

我正在使用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也是不可能的。

非常感谢任何建议,谢谢

flutter animatedcontainer

1
推荐指数
1
解决办法
4858
查看次数

标签 统计

flutter ×2

animatedcontainer ×1

fitted-box ×1