Skip to content

Instantly share code, notes, and snippets.

@Roaa94
Created April 23, 2022 22:51
Show Gist options
  • Save Roaa94/db1b7ec003279bd16d06c8f26e1dd659 to your computer and use it in GitHub Desktop.
Save Roaa94/db1b7ec003279bd16d06c8f26e1dd659 to your computer and use it in GitHub Desktop.
Explicit Animations Example
class ExplicitAnimations extends StatefulWidget {
const ExplicitAnimations({Key? key}) : super(key: key);
@override
State<ExplicitAnimations> createState() => _ExplicitAnimationsState();
}
class _ExplicitAnimationsState extends State<ExplicitAnimations>
with SingleTickerProviderStateMixin {
late AnimationController _controller;
late final Animation<AlignmentGeometry> _alignAnimation;
late final Animation<double> _rotationAnimation;
@override
void initState() {
super.initState();
_controller = AnimationController(
duration: const Duration(milliseconds: 800),
vsync: this,
)..repeat(reverse: true);
_alignAnimation = Tween<AlignmentGeometry>(
begin: Alignment.centerLeft,
end: Alignment.centerRight,
).animate(
CurvedAnimation(
parent: _controller,
curve: Curves.easeInOutCubic,
),
);
_rotationAnimation = Tween<double>(begin: 0, end: 2).animate(
CurvedAnimation(
parent: _controller,
curve: Curves.easeInOutCubic,
),
);
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return BlurContainer(
containerHeight: 200,
child: AlignTransition(
alignment: _alignAnimation,
child: RotationTransition(
turns: _rotationAnimation,
child: const Rectangle(
color1: pink,
color2: pinkDark,
width: 50,
height: 50,
),
),
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment