【发布时间】:2021-05-31 05:53:26
【问题描述】:
我有一个这样的小部件
class googleMapComponent extends StatefulWidget {
Function(LatLng pos) OnPositionChangeCallback;
googleMapComponent({
this.OnPositionChangeCallback,})
使用 nullsafety 我得到这个错误
The parameter 'OnPositionChangeCallback' can't have a value of 'null' because of its type, but the implicit default value is 'null'.
我知道使用 required 会修复它,但我不希望它是必需的
【问题讨论】:
-
您可以使用
Function(LatLang? pos)来允许空值或在传递值时使用!运算符。 -
@DarShan 第一个解决方案不起作用,第二个解决方案我不想发送值,因为这个小部件有很多回调函数