Flutter Animate Text Style
import 'dart:math';
import 'package:flutter/material.dart';
class TextAnimation extends StatefulWidget {
const TextAnimation({Key? key}) : super(key: key);
@override
State<TextAnimation> createState() => _TextAnimationState();
}
class _TextAnimationState extends State<TextAnimation> {
Color _color = Colors.black;
double _fontSize = 24;
final Random _random = Random();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(),
body: Center(
child: Column(
children: [
const SizedBox(height: 50,),
AnimatedDefaultTextStyle(
style: TextStyle(
color: _color,
fontSize: _fontSize
),
duration: const Duration(milliseconds: 800),
curve: Curves.bounceIn,
child: const Text('I am animated text style'),
),
const SizedBox(
height: 8,
),
ElevatedButton(
onPressed: () {
setState(() {
_fontSize = _random.nextDouble() * 24;
_color = Color.fromRGBO(
_random.nextInt(256),
_random.nextInt(256),
_random.nextInt(256),
1,
);
});
},
child: const Text('Click Me!'),
)
],
),
),
);
}
}