Flutter 如何在具有空安全性的颤振中创建构造函数
这对我来说有点棘手。因为我们不能再在constructor中传递空值,所以我有这个Flutter 如何在具有空安全性的颤振中创建构造函数,flutter,dart,Flutter,Dart,这对我来说有点棘手。因为我们不能再在constructor中传递空值,所以我有这个 class LeadingButton extends StatelessWidget { final IconData icon; final Color color; final Color iconColor; final double iconSize; final double size; final Color backGroundColor; final VoidCall
class LeadingButton extends StatelessWidget {
final IconData icon;
final Color color;
final Color iconColor;
final double iconSize;
final double size;
final Color backGroundColor;
final VoidCallback onPressed;
final double padding;
final EdgeInsets margin;
final double rotate;
LeadingButton({
@required this.icon,
this.color = Colors.transparent,
@required this.onPressed,
this.size = 20,
this.backGroundColor = Colors.transparent,
this.iconSize = 20,
this.iconColor = darkColor,
this.rotate = 0,
this.padding = 0,
this.margin = const EdgeInsets.all(10)});
...
我在图标
和按下
功能时出错。虽然
文件上说
参数“onPressed”和“icon”不能有值
“null”的类型,但隐式默认值为
“空”。尝试添加显式非“null”默认值或
“必需”修饰符
我想我遗漏了一些东西,请介意与大家分享。我认为引导按钮的onPressed类型需要更改为VoidCallback?,以便它可以接受空值。不确定,但这可能是由于最近更改了关键字。 您是否改为尝试了
required
关键字
它的类型是
VoidCallBack
也是required修饰符
的意思不是把@required
放在front里,而是你自己的LeadingButton类?或者你无法控制的是lib?它是我的,上面是它的结构,实际上可以工作,谢谢+1