Flutter中的fontSize和textScaleFactor有什么区别?

Tob*_*eck 3 flutter

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

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)),
          ],
        )
      )
    );
  }
}
Run Code Online (Sandbox Code Playgroud)

在此处输入图片说明

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

bof*_*mer 8

据我了解,textScaleFactor用于可访问性。

Android 系统有一个选项可以增加文本大小(而不是整体 UI 比例)。

技术上似乎没有区别。

来自TextStyle文档:

  /// During painting, the [fontSize] is multiplied by the current
  /// `textScaleFactor` to let users make it easier to read text by increasing
  /// its size.
Run Code Online (Sandbox Code Playgroud)


Rém*_*let 6

它们之间的渲染没有区别。他们的目的是什么变化。

字体大小通常是每个组件的值。而比例因子更全球化。您可以直接在上覆盖比例因子的事实Text只是一个奖励。

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

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

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

  • 实际上textScaleFactor可以由用户在手机的“设置”菜单中处理。如果覆盖此属性,用户更改将无效。但如果您使用 FontSize,那么当用户更改他(或她)的设置时,大小将会改变。 (3认同)