Last active
December 29, 2025 19:41
-
-
Save loic-sharma/8c6208cd3bec5cb3024c8e862dd1f746 to your computer and use it in GitHub Desktop.
Sliding using RepeatingAnimationBuilder
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/material.dart'; | |
| void main() { | |
| runApp(const MaterialApp(home: SlidingSquarePage())); | |
| } | |
| class SlidingSquarePage extends StatelessWidget { | |
| const SlidingSquarePage({super.key}); | |
| @override | |
| Widget build(BuildContext context) { | |
| return Scaffold( | |
| body: Center( | |
| child: RepeatingAnimationBuilder<Offset>( | |
| animatable: Tween<Offset>( | |
| begin: const Offset(-1.0, 0.0), | |
| end: const Offset(1.0, 0.0), | |
| ), | |
| duration: const Duration(seconds: 1), | |
| repeatMode: RepeatMode.reverse, | |
| curve: Curves.easeInOut, | |
| builder: (context, offset, child) { | |
| return FractionalTranslation( | |
| translation: offset, | |
| child: child, | |
| ); | |
| }, | |
| child: const ColoredBox( | |
| color: Colors.green, | |
| child: SizedBox.square(dimension: 100), | |
| ), | |
| ), | |
| ), | |
| ); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment