Animated Default Text Style Flutter – Widget Tutorial



Animated Default text style for flutter.

AnimatedDefaultTextStyle(
                  duration: const Duration(milliseconds: 300),
                  style: TextStyle(
                    fontSize: 25,  //Set Your Value
                    color: Colors.blue,  // Set Your Color
                    fontWeight:FontWeight.bold,  // Set your Value
                  ),
                  child: Text('Animated'),
                ),

Flutter Text Animation:-

Flutter Animation Tutorial 2022
Flutter Animation

AnimatedDefalutTextStyle() Code Example:

import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);
  @override
  _MyAppState createState() => _MyAppState();
}
class _MyAppState extends State {
  bool _myFirst = true;
  double _myFontSize = 60;
  Color _myColor = Colors.blue;
  FontWeight _myfontWeight = FontWeight.bold;
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: ""MyTestApp"",
      home: Scaffold(
        body: Center(
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              Container(
                height: 120,
                child: AnimatedDefaultTextStyle(
                  duration: const Duration(milliseconds: 300),
                  style: TextStyle(
                    fontSize: _myFontSize,
                    color: _myColor,
                    fontWeight: _myfontWeight,
                  ),
                  child: Text('Animated'),
                ),
              ),
              FlatButton(
                onPressed: () {
                  setState(() {
                    _myFontSize = _myFirst ? 70 : 50;
                    _myColor = _myFirst ? Colors.blue : Colors.red;
                    _myfontWeight = _myFirst ? FontWeight.bold : FontWeight.w100;
                    _myFirst = !_myFirst;
                  });
                },
                child: Text(
                  ""SHOW!"",
                ),
              )
            ],
          ),
        ),
      )
    );
  }
}

Text Animation:

Flutter Animation
Flutter Animation

Flutter Animation Code Example:

import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatefulWidget {
  const MyApp({Key? key}) : super(key: key);
  @override
  _MyAppState createState() => _MyAppState();
}
class _MyAppState extends State {
  bool _myFirst = true;
  double _myFontSize = 60;
  Color _myColor = Colors.blue;
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: ""MyTestApp"",
      home: Scaffold(
        body: Center(
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: [
              Container(
                height: 120,
                child: AnimatedDefaultTextStyle(
                  duration: const Duration(milliseconds: 300),
                  style: TextStyle(
                    fontSize: _myFontSize,
                    color: _myColor,
                    fontWeight: _myfontWeight,
                  ),
                  child: Text('Animated'),
                ),
              ),
              FlatButton(
                onPressed: () {
                  setState(() {
                    _myFontSize = _myFirst ? 70 : 50;
                    _myColor = _myFirst ? Colors.blue : Colors.red;
                    _myFirst = !_myFirst;
                  });
                },
                child: Text(
                  ""SHOW!"",
                ),
              )
            ],
          ),
        ),
      )
    );
  }
}

Leave a Comment