Flutter 动画不渲染
Flutter animation doesn't render
这是尝试创建一个脉冲圈。它没有 work.Also 当我试图退出它所在的页面时,它给出了错误:“
'package:flutter/src/widgets/framework.dart':断言失败:第 5098 行第 14 行:'_dependents.isEmpty':不正确。”。这个小部件可能有什么问题?
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();
}
}
您需要将 color:
属性 移到 Decoration
中
width: animation.value,
height: animation.value,
decoration: BoxDecoration(
color: Colors.blue,
shape: BoxShape.circle,
),
);
您还需要将 microseconds
更改为 milliseconds
这是尝试创建一个脉冲圈。它没有 work.Also 当我试图退出它所在的页面时,它给出了错误:“ 'package:flutter/src/widgets/framework.dart':断言失败:第 5098 行第 14 行:'_dependents.isEmpty':不正确。”。这个小部件可能有什么问题?
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();
}
}
您需要将 color:
属性 移到 Decoration
width: animation.value,
height: animation.value,
decoration: BoxDecoration(
color: Colors.blue,
shape: BoxShape.circle,
),
);
您还需要将 microseconds
更改为 milliseconds