栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何为扑中的倒塌元素制作动画

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何为扑中的倒塌元素制作动画

如果你想折叠小部件零高度,或者有一个孩子零宽度倒塌溢出的时候,我会建议
SizeTransition 或ScaleTransition 。

这是一个ScaleTransition小部件的示例,该小部件用于折叠
四个黑色按钮和状态文本的容器。我的ExpandedSection
小部件与一列一起使用,以获取以下结构。ScaleTransition小部件的示例

一个将动画与SizeTransition小部件一起使用的小部件的示例:

class ExpandedSection extends StatefulWidget {  final Widget child;  final bool expand;  ExpandedSection({this.expand = false, this.child});  @override  _ExpandedSectionState createState() => _ExpandedSectionState();}class _ExpandedSectionState extends State<ExpandedSection> with SingleTickerProviderStateMixin {  AnimationController expandController;  Animation<double> animation;  @override  void initState() {    super.initState();    prepareAnimations();    _runExpandCheck();  }  ///Setting up the animation  void prepareAnimations() {    expandController = AnimationController(      vsync: this,      duration: Duration(milliseconds: 500)    );    animation = CurvedAnimation(      parent: expandController,      curve: Curves.fastOutSlowIn,    );  }  void _runExpandCheck() {    if(widget.expand) {      expandController.forward();    }    else {      expandController.reverse();    }  }  @override  void didUpdateWidget(ExpandedSection oldWidget) {    super.didUpdateWidget(oldWidget);    _runExpandCheck();  }  @override  void dispose() {    expandController.dispose();    super.dispose();  }  @override  Widget build(BuildContext context) {    return SizeTransition(      axisAlignment: 1.0,      sizeFactor: animation,      child: widget.child    );  }}

AnimatedContainer 也可以工作,但是如果不能将孩子的大小调整为零宽度或零高度,Flutter可能会抱怨溢出。



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/367268.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号