flutter 错误 : Method 'copyWith' cannot be called on 'TextStyle?' because it is potentially null

标签 flutter styles dart-null-safety

哇,我有很多这些:

Error: Method 'copyWith' cannot be called on 'TextStyle?' because it is potentially null.

  • 'TextStyle' is from 'package:flutter/src/painting/text_style.dart' ('../flutter/packages/flutter/lib/src/painting/text_style.dart'). Try calling using ?. instead.

我不明白指令,我试过天真地附加 ?标记在各个地方,尝试将 'copyWith' 更改为 'apply'。

这是错误代码:

                    style: Theme.of(context)
                        .textTheme
                        .bodyText2
                        .copyWith(fontWeight: FontWeight.bold)

呃,我不明白。这个空的东西的主要项目更改,而且我觉得我在猜测相当多的时间。我的 dart 文件现在到处都是 !,这看起来非常冗长。

无论如何,如果没有这个,我的项目将无法编译,我有很多,所以感谢帮助。

最佳答案

flutter pub upgrade fwfh_text_style

帮我解决了。

关于 flutter 错误 : Method 'copyWith' cannot be called on 'TextStyle?' because it is potentially null,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71095899/

相关文章:

html - 在 HTML5 中用什么代替 div 元素

flutter - 函数 'StreamSink<dynamic>' 无法返回类型为 'assessmentSink' 的值

flutter - Dart 空安全 - 如何禁用某些文件的空安全分析?

Flutter - 火焰引擎 |碰撞 : When an object have a high velocity/speed the collision don't trigger

css - png 文件网格 - 如何只显示图像

Delphi XE2 VCL样式,更新标题会阻止其他控件失效

Dart Null 安全/断言运算符

android - Flutter - 在 ThemeData 中使用自定义颜色和主题

flutter - Flutter:使用带有http请求的Firebase实时数据库实现分页

flutter - 如何在 Flutter 中进行模块化以分离每个应用程序功能