GitHub

    Table of contents

  1. 示例
  2. 相关链接

AnimatedDefaultTextStyle

Edit this page

Animated version of DefaultTextStyle which automatically transitions the default text style (the text style to apply to descendant Text widgets without explicit style) over a given duration whenever the given style changes.

示例

bool _first = true;

double _fontSize = 60;
Color _color = Colors.blue;


Widget build(BuildContext context) {
  return Column(
    mainAxisSize: MainAxisSize.min,
    children: <Widget>[
      Container(
        height: 120,
        child: AnimatedDefaultTextStyle(
          duration: const Duration(milliseconds: 300),
          style: TextStyle(
            fontSize: _fontSize,
            color: _color,
            fontWeight: FontWeight.bold,
          ),
          child: Text('Flutter'),
        ),
      ),
      FlatButton(
        onPressed: () {
          setState(() {
            _fontSize = _first ? 90 : 60;
            _color = _first ? Colors.blue : Colors.red;
            _first = !_first;
          });
        },
        child: Text(
          "CLICK ME!",
        ),
      )
    ],
  );
}

相关链接