Created
January 5, 2026 11:13
-
-
Save ChrisMarxDev/98d70bf137fa5fd4f908da9bb60de46b to your computer and use it in GitHub Desktop.
swap animation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import 'package:flutter/widgets.dart'; | |
| class MoveSwapAnimation extends StatelessWidget { | |
| const MoveSwapAnimation({ | |
| required this.child, | |
| super.key, | |
| this.duration = const Duration(milliseconds: 300), | |
| }); | |
| final Widget child; | |
| final Duration duration; | |
| @override | |
| Widget build(BuildContext context) { | |
| return AnimatedSwitcher( | |
| duration: duration, | |
| child: child, | |
| transitionBuilder: (animationChild, animation) { | |
| final isCurrent = animationChild.key == child.key; | |
| return FadeTransition( | |
| opacity: Tween<double>( | |
| begin: isCurrent ? 0.1 : 0, | |
| end: 1, | |
| ).animate(animation), | |
| child: SlideTransition( | |
| position: Tween<Offset>( | |
| begin: isCurrent ? const Offset(0, -1) : const Offset(0, 1), | |
| end: Offset.zero, | |
| ).animate(animation), | |
| child: animationChild, | |
| ), | |
| ); | |
| }, | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment