I have a container with a linear gradient background and I would like to animate the color rotation from bottom to top, like a vinyl disc effect, I tried to rotate the entire container but the height and width of the container remain the same and the result is not satisfactory. This is what I tried.
import 'package:flutter/material.dart';
class SplashPage extends StatefulWidget {
const SplashPage({super.key});
@override
State<SplashPage> createState() => _SplashPageState();
}
class _SplashPageState extends State<SplashPage>
with SingleTickerProviderStateMixin {
late final AnimationController _animationController;
final bool _isRotated = false;
@override
void initState() {
_animationController = AnimationController(
vsync: this,
duration: const Duration(milliseconds: 300),
upperBound: 0.5,
);
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
_animationController.forward();
});
super.initState();
}
@override
Widget build(BuildContext context) {
return SizedBox(
width: double.infinity,
height: double.infinity,
child: Stack(
children: [
RotationTransition(
turns: Tween(begin: 0.0, end: 1.0).animate(_animationController),
child: OverflowBox(
child: Container(
decoration: const BoxDecoration(
// shape: BoxShape.circle,
gradient: LinearGradient(
colors: [
Color(0xFF212657),
Color(0xFF28346D),
Color(0xFF33498E),
Color(0xFF3A56A1),
Color(0xFF3D5BA9),
Color(0xFF405AA7),
Color(0xFF7D538B),
Color(0xFFAE4E74),
Color(0xFFD14A64),
Color(0xFFE7475A),
Color(0xFFEF4757),
],
begin: Alignment.topLeft,
end: Alignment.bottomRight,
stops: [
0.02,
0.11,
0.28,
0.41,
0.5,
0.52,
0.73,
0.82,
0.92,
0.95,
1
]
),
),
),
),
),
// ...others widgets
],
),
);
}
}
Any suggestions?
2
Answers
I managed to do it by animating the transform parameter property of BoxDecoration:
And then:
Something like? Here.