[英]Malfunction of the onPressed Flutter property
I created an extended class from a RaisedButton.我从 RaisedButton 创建了一个扩展类。 When passing the onPressed parameter, the class rejects saying that the drive is null.当传递 onPressed 参数时,类拒绝说驱动器为空。
The Class班上
class VecRaisedButton extends RaisedButton {
VecRaisedButton({
text,
elevation,
onPressed,
colorButton = CorPrimaria,
colorFont,
splashColor: CorBranca
}) :
super(
child:VecText(text: text, textAlign: TextAlign.center, color: colorFont),
shape:RoundedRectangleBorder( borderRadius: BordaArredondadaApenas4(10, 10, 10, 10)),
splashColor:splashColor,
elevation:elevation,
onPressed: () => onPressed,
color:colorButton,
);
}
child: VecRaisedButton(
text: "Enviar",
colorFont: CorBranca,
onPressed: Navigator.push(context, MaterialPageRoute(builder: (context) => Layout_Menu())),
)
Can anybody help me?有谁能够帮助我?
Change:改变:
elevation:elevation,
onPressed: () => onPressed,
to:到:
elevation: elevation,
onPressed: onPressed, // just pass along the Function
and, this:和这个:
colorFont: CorBranca,
onPressed: Navigator.push(context,
to this:对此:
colorFont: CorBranca,
onPressed: () => Navigator.push(context, // onPressed takes a Function
However, in general you should compose new widgets rather than extending.但是,通常您应该编写新的小部件而不是扩展。 That means making a class that extends StatelessWidget
and then returning a correctly styled raised button in your new widget's build
.这意味着创建一个扩展StatelessWidget
的类,然后在新小部件的build
返回一个样式正确的凸起按钮。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.