【发布时间】:2021-06-12 19:06:12
【问题描述】:
这对我来说有点棘手。因为我们不能再在构造函数中传递空值,所以我有这个
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)});
...
icon 和 onpressed 函数出现错误。虽然
文档在说
参数 'onPressed' & 'icon' 不能有值 'null' 因为它的类型,但隐含的默认值是 '空值'。尝试添加显式的非“null”默认值或 “必需”修饰符。
我想我错过了一些东西,请介意分享
【问题讨论】: