【发布时间】:2020-11-10 03:31:00
【问题描述】:
您好,我正在尝试创建几个TextTheme,并根据这篇文章使用MediaQuery.of(context) 更改字体大小:
Flutter — Effectively scale UI according to different screen sizes
但我收到此错误:
使用不包含 MediaQuery 的上下文调用 MediaQuery.of()。
根据这篇文章我知道了:Flutter Error: MediaQuery.of() called with a context that does not contain a MediaQuery
我应该在我的主页上使用MediaQuery,但是我不能使用MediaQuery 创建主题?
这是我的代码:
child:
MaterialApp(
theme: ThemeData(
/// TextFields Handlers transparent
textSelectionHandleColor: Colors.transparent,
pageTransitionsTheme: const PageTransitionsTheme(
builders: <TargetPlatform, PageTransitionsBuilder>{
TargetPlatform.android: ZoomPageTransitionsBuilder(),
},
),
textTheme: TextTheme(
/// Pages Titles
headline1: textTheme(
fontSize: (MediaQuery.of(context).size.width / 100) * 1.5,
fontWeight: FontWeight.w600,
color: Globals.allColors['celeste'],
),
headline2: textTheme(
fontSize: 15,
fontWeight: FontWeight.w600,
color: Globals.allColors['cetaceanBlue']),
...
错误在:
(MediaQuery.of(context).size.width / 100) * 1.5,
提前致谢!
【问题讨论】: