@override
void initState() {
_animationController =
AnimationController(duration: widget.duration,vsync: this)
..addStatusListener((status){
if(status == AnimationStatus.completed){
widget.onComplete('');
}
});
var begin = Offset(-1.0,.0);
var end = Offset(1.0,.0);
_animation = Tween(begin: begin,end: end).animate(_animationController);
//开始动画
_animationController.forward();
super.initState();
}
@override
Widget build(BuildContext context) {
return SlideTransition(
position: _animation,child: widget.child,);
}
_computeTop(int index,double perRowHeight) {
//第几轮弹幕
int num = (index / widget.showCount).floor();
var top;
top = (index % widget.showCount) * perRowHeight + widget.padding;
if (num % 2 == 1 && index % widget.showCount != widget.showCount - 1) {
//第二轮在第一轮2行弹幕中间
top += perRowHeight / 2;
}
if (widget.randomOffset != 0 && top > widget.randomOffset) {
top += _random.nextInt(widget.randomOffset) * 2 - widget.randomOffset;
}
return top;
}
Text(
text,style: TextStyle(color: Colors.white),);
创建一条VIP用户的弹幕,其实就是字体变下颜色:
Text(
text,style: TextStyle(color: Color(0xFFE9A33A)),)
给文字加个圆角背景:
return Center(
child: Container(
padding: EdgeInsets.only(left: 10,right: 10,top: 3,bottom: 3),decoration: BoxDecoration(
color: Colors.red.withOpacity(.8),borderRadius: BorderRadius.circular(50)),child: Text(
text,),);
创建一个送火箭的弹幕:
return Center(
child: Container(
padding: EdgeInsets.only(left: 10,child: Row(
mainAxisSize: MainAxisSize.min,children: <Widget>[
Text(
text,Image.asset('assets/images/timg.jpeg',height: 30,width: 30,Text(
'x $count',style: TextStyle(color: Colors.white,fontSize: 18),],);
火箭有点丑了,不过这不是重点。