如何在Flutter中为文本的fontSize设置动画? [英] How to animate the fontSize of a Text in Flutter?

查看:118
本文介绍了如何在Flutter中为文本的fontSize设置动画?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有什么方法可以使 Text 小部件中的 fontSize 的增减动画?

Is there any way to animate the increase/decrease of the fontSize in a Text widget?

推荐答案

可能更简单的解决方案是使用 AnimatedTextStyle .

Probably an easier solution would be to use AnimatedTextStyle.

double _size = 10;
  
@override
Widget build(BuildContext context) {
  return Scaffold(
    floatingActionButton: FloatingActionButton(
      child: Icon(Icons.add),
      onPressed: () => setState(() => _size += 50),
    ),
    body: AnimatedDefaultTextStyle(
      duration: Duration(milliseconds: 400),
      style: TextStyle(fontSize: _size),
      child: Text('A'),
    ),
  );
}

这篇关于如何在Flutter中为文本的fontSize设置动画?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆