Flutter中的fontSize和textScaleFactor有什么区别? [英] What is the difference between fontSize and textScaleFactor in Flutter?

查看:810
本文介绍了Flutter中的fontSize和textScaleFactor有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

fontSize的默认值为14.0.因此,如我的代码示例所示,textScaleFactor: 2.0似乎与fontSize: 28.0相同:

The default for fontSize is 14.0. Therefore, textScaleFactor: 2.0 appears to be the same as fontSize: 28.0 as seen in my code example:

class MyApp extends StatelessWidget {

  @override
  Widget build(BuildContext context) {
    return new MaterialApp(
      home: Scaffold(
        appBar: AppBar(title: Text('Title')),
        body: Row(
          children: <Widget>[
            new Text("Jane", textScaleFactor: 2.0),
            new Text(" Doe", style: new TextStyle(fontSize: 28.0)),
          ],
        )
      )
    );
  }
}

优缺点是什么?在特定情况下何时使用一种或另一种有什么建议?

What are the pros and cons? Are there any recommendations when to use one or another in specific cases?

推荐答案

在呈现方式上它们之间没有区别.他们的目的是什么变化.

There's no difference between them in the rendering. What changes are their purpose.

字体大小通常是每个组件的值.而比例因子则更具全局性.您可以直接在Text上覆盖比例因子的事实只是一个好处.

Font-size is usually a per-component value. While the scale factor is more global. The fact that you can override the scale factor directly on the Text is just a bonus.

在典型的应用程序中,您将具有以下内容:

In your typical application, you'll have the following:

MediaQuery(
  data: MediaQuery.of(context).copyWith(textScaleFactor: 2.0),
  child: Whatever(
    child: Text("Foo", style: Theme.of(context).textTheme.headline),
  ),
);

基本上,将textScaleFactor作为缩放选项.字体大小用于将标题与内容分开.

Basically, consider textScaleFactor as a zoom option. While font-size is used to separate a title from its content.

这篇关于Flutter中的fontSize和textScaleFactor有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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