flutter 错误:无法将参数类型“Duration?”分配给参数类型“Duration,”因为“Duration?”可为null,而“Duration”不可为null

jyztefdp  于 2022-11-17  发布在  Flutter
关注(0)|答案(1)|浏览(230)

如何,解决这个问题?错误:无法将参数类型“Duration?”分配给参数类型“Duration,”因为“Duration?”可为null,而“Duration”不可为null.

  • '持续时间'来自'dart:core'。toastDuration:持续时间,^
pw9qyyiw

pw9qyyiw1#

如果您确定它不是这样,请将其转换为:

Duration? durationExample = Duration(seconds: 2);
methodCallExample(durationExample as Duration);

或者在它为空时设置一个替代项:

Duration? durationExample = Duration(seconds: 10);
methodCallExample(durationExample ?? Duration(seconds: 1));

相关问题