首页 > 解决方案 > 有没有 *?飞镖中的操作员?

问题描述

*?飞镖中有操作员吗?

我正在使用copy_with_extension生成代码,目前我有类似的错误

[SEVERE] copy_with_extension_gen:copy_with_extension_gen on lib/models/my_model.dart:
An error `FormatterException` occurred while formatting the generated source for
  `package:app/models/my_model.dart`
which was output to
  `lib/models/my_model.copyWith.g.part`.
This may indicate an issue in the generator, the input source code, or in the
source formatter.
Could not format because the source could not be parsed:

line 8, column 51 of .: Expected to find '}'.
  ╷
8 │               MyModel copyWith({ String*? myField})
{
  │                                                   ^
  ╵

*?很奇怪,?是可以为空的,是什么*

由于我正在使用sdk: ">=2.7.0 <3.0.0"并且忙于迁移空安全性,我想分叉并更改为不健全的空安全性

标签: dart

解决方案


Dart中没有*?运算符。您的代码生成器正在生成无效代码,*它不会发生在它发生的地方。

这很可能是代码生成器被分析器的更改绊倒了。该类型String*可以是不健全的可空类型的内部表示String( pre-nullsafetyp 代码中的经典类型可以是null,而不是空安全String的不能)。代码生成器应该发出正确的源名称,而不是内部表示。我会向该代码生成器提出问题。


推荐阅读