flutter - 如何在颤动中为容器设置动画边框
问题描述
我想用颤动的发光效果为我的容器的边框设置动画,你知道吗?
解决方案
下面的代码将为边框的宽度设置动画
class Test extends StatefulWidget {
@override
_TestState createState() => _TestState();
}
class _TestState extends State<Test> with TickerProviderStateMixin {
AnimationController _resizableController;
AnimatedBuilder getContainer() {
return new AnimatedBuilder(
animation: _resizableController,
builder: (context, child) {
return Container(
padding: EdgeInsets.all(24),
child: Text("SAMPLE"),
decoration: BoxDecoration(
shape: BoxShape.rectangle,
borderRadius: BorderRadius.all(Radius.circular(12)),
border: Border.all(
color: Colors.blue, width: _resizableController.value * 10),
),
);
});
}
@override
void initState() {
_resizableController = new AnimationController(
vsync: this,
duration: new Duration(
milliseconds: 1000,
),
);
_resizableController.addStatusListener((animationStatus) {
switch (animationStatus) {
case AnimationStatus.completed:
_resizableController.reverse();
break;
case AnimationStatus.dismissed:
_resizableController.forward();
break;
case AnimationStatus.forward:
break;
case AnimationStatus.reverse:
break;
}
});
_resizableController.forward();
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
title: Text("Test"),
centerTitle: true,
),
body: Center(child: getContainer()));
}
}
推荐阅读
- javascript - 如何防止嵌套的映射元素触发两次 onClick 事件
- c# - 以随机间隔使用随机数填充堆栈(自己的堆栈类)的程序
- mysql - 带有 Thymeleaf、Spring 引导、Mysql 的 Ckeditor
- solr - Solr 6:如何按标题分组并返回包含至少 5 个 numFound 的组
- javascript - 使用正则表达式获取数据
- wordpress - Wordpress 中的“Before Header Content hook”到底在哪里?
- php - Laravel Mix 包内热重载
- scala - Scala 不是基于 Java 10 构建的
- python - 如何使用python在同一个工作簿中组合选定的工作表
- mysql - 如何使用位于其他服务器上的 wordpress 数据库