Last active
July 16, 2024 15:29
-
-
Save sixtusagbo/3f905c7b774057e32ee5485ec97c15d2 to your computer and use it in GitHub Desktop.
Text slide animation in Flutter (No external package)
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(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, | |
), | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Run in DartPad