Flutter:从扩展小部件创建自定义小部件
Flutter: create custom widget from extended widget
如何创建自定义小部件来扩展现有小部件,使其具有相同的参数但具有一些不同的默认值?
class CustomRaisedButton extends RaisedButton {
final ShapeBorder shape;
final double elevation;
CutstomRaisedButton({this.shape = RoundedRectangleBorder(borderRadius: BorderRadius.circular(25)), this.elevation = 16})
}
应该创建一个自定义的无状态小部件,returns 您想要的按钮。传递一个 'OnPressed' 函数,以便您可以处理主页上的按钮按下!
class CustomRaisedButton extends StatelessWidget {
CustomRaisedButton({this.onPressed});
final Function onPressed;
@override
Widget build(BuildContext context) {
return RaisedButton(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(25)),
elevation: 16,
onPressed: onPressed,
);
}
}
如何创建自定义小部件来扩展现有小部件,使其具有相同的参数但具有一些不同的默认值?
class CustomRaisedButton extends RaisedButton {
final ShapeBorder shape;
final double elevation;
CutstomRaisedButton({this.shape = RoundedRectangleBorder(borderRadius: BorderRadius.circular(25)), this.elevation = 16})
}
应该创建一个自定义的无状态小部件,returns 您想要的按钮。传递一个 'OnPressed' 函数,以便您可以处理主页上的按钮按下!
class CustomRaisedButton extends StatelessWidget {
CustomRaisedButton({this.onPressed});
final Function onPressed;
@override
Widget build(BuildContext context) {
return RaisedButton(
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(25)),
elevation: 16,
onPressed: onPressed,
);
}
}