的默认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)
优缺点都有什么?在特定情况下何时使用一种或另一种有什么建议吗?
据我了解,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)
它们之间的渲染没有区别。他们的目的是什么变化。
字体大小通常是每个组件的值。而比例因子更全球化。您可以直接在上覆盖比例因子的事实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作为缩放选项。字体大小用于将标题与内容分开。
| 归档时间: |
|
| 查看次数: |
1992 次 |
| 最近记录: |