Flutter:从扩展窗口小部件创建自定义窗口小部件

时间:2020-09-20 17:43:17

标签: flutter widget extends

如何创建自定义窗口小部件以扩展现有窗口小部件,使其具有相同的参数但具有一些不同的默认值?

class CustomRaisedButton extends RaisedButton {
  final ShapeBorder shape;
  final double elevation;

  CutstomRaisedButton({this.shape = RoundedRectangleBorder(borderRadius: BorderRadius.circular(25)), this.elevation = 16})
}

1 个答案:

答案 0 :(得分:1)

应该创建一个自定义的无状态窗口小部件,以返回所需的按钮。传递“ 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,
       );
    }
}