【发布时间】:2021-05-25 17:09:51
【问题描述】:
这是创建一个脉动圈的尝试。它不起作用。此外,当我尝试退出它所在的页面时,它会给出错误:“ 'package:flutter/src/widgets/framework.dart': 断言失败: line 5098 pos 14: '_dependents.isEmpty': is not true."。这个小部件可能有什么问题?
import 'package:flutter/material.dart';
import 'package:flutter/animation.dart';
class BlinkingCircle extends StatefulWidget {
BlinkingCircle({Key key, @required this.size}) : super(key: key);
final size;
@override
_BlinkingCircleState createState() => _BlinkingCircleState();
}
class _BlinkingCircleState extends State<BlinkingCircle>
with SingleTickerProviderStateMixin {
Animation<double> animation;
AnimationController controller;
@override
void initState() {
super.initState();
controller = AnimationController(
vsync: this, duration: const Duration(microseconds: 5000));
animation = Tween<double>(begin: 0, end: 20).animate(controller)
..addListener(() {
setState(() {});
});
controller.forward();
}
@override
Widget build(BuildContext context) {
return Container(
color: Colors.blue,
width: animation.value,
height: animation.value,
decoration: BoxDecoration(
shape: BoxShape.circle,
),
);
}
@override
void dispose() {
controller.dispose();
super.dispose();
}
}
【问题讨论】: