我是使用动画旋转梯度的同时,当用户按下容器,我想增加容器的大小。
当我使用容器代替按预期工作的AnimatedContainer渐变动画时,当我用AnimatedContainer替换容器时,渐变动画不能正常工作(意思是:在将0旋转到2*math.pi之后,再次重置它,然后启动动画,我希望它继续旋转。)
import 'package:flutter/material.dart';
import 'dart:math' as math;
class Delete extends StatefulWidget {
Delete({Key key}) : super(key: key);
@override
_DeleteState createState() => _DeleteState();
}
class _DeleteState extends State<Delete> with SingleTickerProviderStateMixin {
Animation<double> _animation;
AnimationController _controller;
double _playButtonSize = 170;
@override
void initState() {
super.initState();
_controller =
AnimationController(vsync: this, duration: Duration(seconds: 10));
_animation = Tween<double>(begin: 0, end: 2 * math.pi).animate(_controller)
..addListener(() {
setState(() {});
});
_controller.repeat();
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(""),
),
body: Container(
child: GestureDetector(
onLongPress: () {
setState(() {
_playButtonSize = 185;
});
},
onLongPressEnd: (end) {
setState(() {
_playButtonSize = 170;
});
},
child: AnimatedContainer(
duration: Duration(milliseconds: 100),
width: _playButtonSize,
height: _playButtonSize,
padding: EdgeInsets.all(17.0),
decoration: BoxDecoration(
shape: BoxShape.circle,
gradient: SweepGradient(
colors: [
Colors.blue,
Colors.pink,
Colors.orange,
Colors.yellow,
Colors.blue
],
center: Alignment(-0.50, -0.0),
endAngle: _animation.value + (2 * math.pi),
startAngle: _animation.value,
tileMode: TileMode.repeated,
),
boxShadow: [
BoxShadow(
color: Colors.white,
blurRadius: 4.0,
),
],
),
child: Icon(
Icons.email,
size: 50,
)),
),
));
}
}发布于 2020-02-13 11:10:27
如果您将AnimatedContainer与另一个父Container交换,则您的两个动画都会工作:
return Scaffold(
appBar: AppBar(
title: Text(""),
),
body: AnimatedContainer(
duration: Duration(milliseconds: 100),
width: _playButtonSize,
height: _playButtonSize,
child: GestureDetector(
onLongPress: () {
setState(() {
_playButtonSize = 185;
});
},
onLongPressEnd: (end) {
setState(() {
_playButtonSize = 170;
});
},
child: Container(
padding: EdgeInsets.all(17.0),
decoration: BoxDecoration(
shape: BoxShape.circle,
gradient: SweepGradient(
colors: [
Colors.blue,
Colors.pink,
Colors.orange,
Colors.yellow,
Colors.blue
],
center: Alignment(-0.50, -0.0),
endAngle: _animation.value + (2 * math.pi),
startAngle: _animation.value,
tileMode: TileMode.repeated,
),
boxShadow: [
BoxShadow(
color: Colors.white,
blurRadius: 4.0,
),
],
),
child: Icon(
Icons.email,
size: 50,
)
),
),
)
);https://stackoverflow.com/questions/60205541
复制相似问题