In this article, I'm going to share an example for AnimatedDefaultTextStyle in flutter.
Here is the full code from main.dart file.
import 'package:flutter/material.dart';
void main(List<String> args) {
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@
override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
bool _clicked = true;
@
override
Widget build(BuildContext context) {
return MaterialApp(
title: "AnimatedDefaultTextStyle",
home: Scaffold(
appBar: AppBar(
title: Text('AnimatedDefaultTextStyle'),
),
body: MyHomePage(clicked: _clicked),
floatingActionButton: FloatingActionButton(
child: _clicked ? Icon(Icons.toggle_on) : Icon(Icons.toggle_off),
onPressed: () {
setState(() {
_clicked = !_clicked;
});
},
),
),
);
}
}
class MyHomePage extends StatefulWidget {
final bool? clicked;
const MyHomePage({Key? key, this.clicked}) : super(key: key);
@
override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@
override
Widget build(BuildContext context) {
var clicked;
clicked = widget.clicked;
return Center(
child: AnimatedDefaultTextStyle(
child: Text('Hello World'),
duration: Duration(seconds: 1),
style: TextStyle(
color: clicked ? Colors.red : Colors.green,
fontSize: clicked ? 30 : 50,
),
));
}
}
Thanks,Srikanth