Skip to content

Instantly share code, notes, and snippets.

@sixtusagbo
Last active July 16, 2024 15:29
Show Gist options
  • Save sixtusagbo/3f905c7b774057e32ee5485ec97c15d2 to your computer and use it in GitHub Desktop.
Save sixtusagbo/3f905c7b774057e32ee5485ec97c15d2 to your computer and use it in GitHub Desktop.
Text slide animation in Flutter (No external package)
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(title: Text('Text Slide Animation')),
body: TextSlideAnimation(),
),
);
}
}
class TextSlideAnimation extends StatefulWidget {
@override
_TextSlideAnimationState createState() => _TextSlideAnimationState();
}
class _TextSlideAnimationState extends State<TextSlideAnimation>
with SingleTickerProviderStateMixin {
late AnimationController _controller;
late Animation<Offset> _animation;
@override
void initState() {
super.initState();
_controller = AnimationController(
duration: const Duration(seconds: 10),
vsync: this,
)..repeat(reverse: false);
_animation = Tween<Offset>(
begin: Offset(1.0, 0.0),
end: Offset(-1.0, 0.0),
).animate(CurvedAnimation(
parent: _controller,
curve: Curves.linear,
));
}
@override
void dispose() {
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return ClipRRect(
child: SlideTransition(
position: _animation,
child: Align(
alignment: Alignment.centerLeft,
child: Text(
'Hi, I\'m Sixtus Agbo',
style: Theme.of(context).textTheme.displayMedium,
overflow: TextOverflow.visible,
softWrap: false,
),
),
),
);
}
}
@sixtusagbo
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment