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] 进行动画处理。这个高度需要在构建时进行动画处理。
我正在使用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也是不可能的。
非常感谢任何建议,谢谢