Skip to content

Instantly share code, notes, and snippets.

@loic-sharma
Last active December 29, 2025 19:41
Show Gist options
  • Select an option

  • Save loic-sharma/8c6208cd3bec5cb3024c8e862dd1f746 to your computer and use it in GitHub Desktop.

Select an option

Save loic-sharma/8c6208cd3bec5cb3024c8e862dd1f746 to your computer and use it in GitHub Desktop.
Sliding using RepeatingAnimationBuilder
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