xxxxxxxxxx
import 'package:flutter/material.dart';
class TextAnimationScreen extends StatefulWidget {
@override
_TextAnimationScreenState createState() => _TextAnimationScreenState();
}
class _TextAnimationScreenState extends State<TextAnimationScreen>
with SingleTickerProviderStateMixin {
AnimationController _animationController;
Animation<double> _animation;
@override
void initState() {
super.initState();
_animationController = AnimationController(
duration: Duration(seconds: 2),
vsync: this,
);
_animation = Tween<double>(begin: 0, end: 1).animate(_animationController);
_animationController.repeat(reverse: true);
}
@override
void dispose() {
_animationController.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Text Animation'),
),
body: Center(
child: AnimatedBuilder(
animation: _animationController,
builder: (BuildContext context, Widget child) {
return Opacity(
opacity: _animation.value,
child: Text(
'Animated Text',
style: TextStyle(fontSize: 24),
),
);
},
),
),
);
}
}
void main() {
runApp(MaterialApp(
home: TextAnimationScreen(),
));
}
xxxxxxxxxx
Row(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
const SizedBox(width: 20.0, height: 100.0),
const Text(
'Be',
style: TextStyle(fontSize: 43.0),
),
const SizedBox(width: 20.0, height: 100.0),
DefaultTextStyle(
style: const TextStyle(
fontSize: 40.0,
fontFamily: 'Horizon',
),
child: AnimatedTextKit(
animatedTexts: [
RotateAnimatedText('AWESOME'),
RotateAnimatedText('OPTIMISTIC'),
RotateAnimatedText('DIFFERENT'),
],
onTap: () {
print("Tap Event");
},
),
),
],
);
xxxxxxxxxx
import 'package:flutter/material.dart';
class AnimatedTextExample extends StatefulWidget {
@override
_AnimatedTextExampleState createState() => _AnimatedTextExampleState();
}
class _AnimatedTextExampleState extends State<AnimatedTextExample>
with SingleTickerProviderStateMixin {
AnimationController _controller;
Animation<double> _fadeAnimation;
@override
void initState() {
super.initState();
// Create a controller for managing the animation
_controller = AnimationController(
duration: const Duration(seconds: 2),
vsync: this,
);
// Create a fade animation for the text
_fadeAnimation = Tween<double>(begin: 0, end: 1).animate(_controller);
// Start the animation
_controller.forward();
}
@override
void dispose() {
// Dispose the controller
_controller.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Animated Text Example'),
),
body: Center(
child: FadeTransition(
opacity: _fadeAnimation,
child: Text(
'Hello, Flutter!',
style: TextStyle(fontSize: 24),
),
),
),
);
}
}
void main() {
runApp(MaterialApp(home: AnimatedTextExample()));
}
xxxxxxxxxx
Following are the types of text animations available with the animated_text_kit package:
RotatedAnimatedText(),ScaleAnimatedText(),FadeAnimatedText(),
TyperAnimatedText(),WavyAnimatedText(),FlickerAnimatedText().
Add animated_text_kit package to the pubspec.yaml file.
Then configure it using pub get. You can also install the package from the command line by running the following command:
flutter pub add animated_text_kit
Now, in main.dart file, import the package to use it.
import 'package:animated_text_kit/animated_text_kit.dart';