【发布时间】:2019-12-11 17:04:53
【问题描述】:
我想在 MaterialApp 主题中设置 MediaQuery,以便在用户更改设置时 FontSize 尊重用户设置。
我尝试创建最终 curlScale = MediaQuery.of(context).textScaleFactor; 并相应地使用在 MaterialApp 中设置 fontSize: 20 * curlScale 但由于“使用不包含 MediaQuery 的上下文调用 MediaQuery.of()”而出现错误。 我该如何解决这个问题。
Widget build(BuildContext context) {
final curlScale = MediaQuery.of(context).textScaleFactor;
return MaterialApp(
title: 'Expense Tracker App',
theme: ThemeData(
primarySwatch: Colors.orange,
accentColor: Colors.limeAccent,
fontFamily: 'QuickSand',
errorColor: Colors.red,
appBarTheme: AppBarTheme(textTheme: ThemeData.light().textTheme.copyWith(
title: TextStyle(fontFamily: 'Open Sans', fontSize: 16 * curlScale),
button: TextStyle(color: Colors.white),
)
)
),
home: HomePage(),
);
当用户更改字体设置时,字体大小应尊重用户设置。
【问题讨论】:
-
我看到我们一直在研究同一个教程;) Max 应该更详细地介绍这个主题
标签: flutter