添加statuslistener时,线性进度指示器没有动画



当我添加AddStatusListener时,我的LinearProgressIndicator不会向前动画。在动画完成后,我得到构建方法重新渲染,但没有线性动画发生。我想要动画运行,就在它完成后,我需要一个小部件出现,在这里的情况下,文本小部件。

这是我的代码-

class _AuthenticationPageState extends State<AuthenticationPage> with TickerProviderStateMixin {
late AnimationController controller;
bool test = false;
@override
void initState() {
controller = AnimationController(
vsync: this,
duration: const Duration(seconds: 5),
)..addStatusListener((AnimationStatus status) {
setState(() {
if(status == AnimationStatus.completed) test = true;
});
});
controller.forward();
super.initState();
}

@override
void dispose() {
controller.dispose();
super.dispose();
}

@override
Widget build(BuildContext context) {
return Scaffold(
body: Padding(
padding: const EdgeInsets.fromLTRB(30,50,10,30),
child: Column(
children: [
const Text('Hello, Welcome', style: TextStyle(fontWeight: FontWeight.bold, fontSize: 60),),
LinearProgressIndicator(
value: controller.value,
semanticsLabel: 'Linear progress indicator',
),
if(test == true) const Text('Test is true')
],
)
),
);
}

没有什么变化,因为你不是每一次都在听,你只是在听它完成的时候,正如pskink试图在评论中解释的那样。

void initState() {
controller = AnimationController(
vsync: this,
duration: const Duration(seconds: 5),
)
..addStatusListener((AnimationStatus status) {
setState(() {
if (status == AnimationStatus.completed) test = true;
});
})
..addListener(() {
setState(() {});
});
controller.forward();
super.initState();
}

最新更新