flutter - 断言失败 : line 118 pos 10: '(displayLarge == null && displayMedium == null && displaySmall == null && headlineMedium == null &&

标签 flutter

======== 小部件库捕获异常==================================== ===================== 构建 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

任何人都可以帮助解决这个问题的含义吗?

enter image description here

最佳答案

我猜你试图实例化 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 年更新的替代品。

避免混合已弃用和较新的文本样式选项的快速方法是使用:

  1. Large结尾的/Medium/Small (例如 bodyLargelabelSmall ...)。

或者:

  • 其余样式选项(例如 bodyText1headline2captionbuttonoverline ...)
  • 更推荐的方法是使用现成的排版样式定义应用程序范围的文本样式,并在其顶部添加几何图形,如下所示:

    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/

    相关文章:

    c++ - 我可以将 C++ 代码(或用 C++ 编写的库)与混合移动应用程序代码混合使用吗?

    web - 在 flutter web 中播放视频

    flutter - 如何比较 flutter 中的时间?

    google-maps - 如何重新定位 Google map Logo 和 map 按钮

    flutter - 将数据传递到 Flutter 路由的两种方式之间的区别

    Flutter HitTest 不触发点击事件

    flutter - 如何在 Flutter 中制作 "show up"文字动画?

    javascript - 无法建立项目

    dart - 可点击图像的抖动列表

    flutter - 在企业(私有(private))环境中托管 dart/flutter 包的官方方式是什么?