======== 小部件库捕获异常==================================== ===================== 构建 MyApp(dirty) 时抛出以下断言: 无法在调用 TextTheme() 构造函数时混合 2018 年和 2021 年术语。 '包:flutter/src/material/text_theme.dart': 断言失败:第 118 行 pos 10:'(displayLarge == null && displayMedium == null && displaySmall == null && headerMedium == null && headerSmall == null && titleLarge == null && titleMedium == null && titleSmall == null && bodyLarge == null && bodyMedium == null && bodySmall == null && labelLarge == null && labelSmall == null) || (标题1 == null && 标题2 == null && 标题3 == null && 标题4 == null && 标题5 == null && 标题6 == null && 副标题1 == null && 副标题2 == null && bodyText1 == null && bodyText2 == null && 标题 == null && 按钮 == null && 上划线 == null)'
D/EGL_emulation(6728): app_time_stats: avg=92344.32ms min=92344.32ms max=92344.32ms count=1
任何人都可以帮助解决这个问题的含义吗?
最佳答案
我猜你试图实例化 TextTheme()
通过指定所有可能的构造函数参数来创建对象。但是,如果您看到构造函数的 documentation ,它(不清楚)指定:
Please note that you can not mix and match the 2018 styles with the 2021 styles. Only one or the other is allowed in this constructor. The 2018 styles will be deprecated and removed eventually.
文档中不清楚的是哪些文本样式属性是自 2018 年以来(并已弃用)以及哪些是 2021 年更新的替代品。
避免混合已弃用和较新的文本样式选项的快速方法是使用:
- 以
Large
结尾的/Medium
/Small
(例如bodyLarge
或labelSmall
...)。
或者:
- 其余样式选项(例如
bodyText1
、headline2
、caption
、button
、overline
...)
更推荐的方法是使用现成的排版样式定义应用程序范围的文本样式,并在其顶部添加几何图形,如下所示:
const typeTheme = Typography.whiteMountainView;
TextTheme txtTheme = Typography.whiteMountainView.copyWith(
bodyText1: typeTheme.bodyText1?.copyWith(fontSize: 16),
bodyText2: typeTheme.bodyText2?.copyWith(fontSize: 14),
headline1: typeTheme.headline1?.copyWith(fontSize: 32),
headline2: typeTheme.headline2?.copyWith(fontSize: 28),
headline3: typeTheme.headline3?.copyWith(fontSize: 24),
headline4: typeTheme.headline4?.copyWith(fontSize: 21),
headline5: typeTheme.headline5?.copyWith(fontSize: 18),
headline6: typeTheme.headline6?.copyWith(fontSize: 16),
subtitle1: typeTheme.subtitle1?.copyWith(fontSize: 24),
subtitle2: typeTheme.subtitle2?.copyWith(fontSize: 21),
);
关于flutter - 断言失败 : line 118 pos 10: '(displayLarge == null && displayMedium == null && displaySmall == null && headlineMedium == null &&,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71682660/