标签: animatedcontainer

如何使 AnimatedContainer 在初始小部件构建后更改高度,而不是在单击按钮时更改高度

                Expanded(
                  flex: 1,
                  child: Padding(
                    padding: const EdgeInsets.only(bottom: 3.0, right: 1),
                    child: AnimatedContainer(
                      duration: Duration(seconds: 1),
                      height: voteCountList[0],
                      decoration: BoxDecoration(
                        color: ColorChooser.graphColors[int.parse(optionsList[0]['color'])],
                        borderRadius: BorderRadius.all(Radius.circular(2))
                      ),
                    ),
                  ),
                ),
Run Code Online (Sandbox Code Playgroud)

正如我的代码片段中所示,动画容器的高度是 voteCountList[0],如果更新值,则效果很好。然而,当小部件最初构建时,没有动画,容器的高度立即 = voteCountList[0]。我想实现 AnimatedContainer,以便看到容器的高度从 0 到 voteCountList[0] 进行动画处理。这个高度需要在构建时进行动画处理。

height duration flutter animatedcontainer

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

具有 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
查看次数

标签 统计

animatedcontainer ×2

flutter ×2

duration ×1

height ×1