gpt4 book ai didi

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

转载 作者:IT老高 更新时间:2023-10-28 12:44:07 29 4
gpt4 key购买 nike

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)),
],
)
)
);
}
}

enter image description here

有什么好处和坏处?在特定情况下何时使用一种或另一种有什么建议吗?

最佳答案

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

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

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

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

基本上,将 textScaleFactor 视为缩放选项。而 font-size 用于将标题与其内容分开。

关于flutter - Flutter 中的 fontSize 和 textScaleFactor 有什么区别?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52138524/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com