专业的编程技术博客社区

网站首页 > 博客文章 正文

Flutter 自定义统一Button组件、可配置背景色、圆角、宽高等

baijin 2024-08-29 12:30:11 博客文章 5 ℃ 0 评论
class CustomRoundRectButton extends StatelessWidget {
  Function() p;
  String text;
  Color backgroundColor;
  Color txtColor;
  double height;
  double width;
  double borderCircle;
  static const Color c = Color.fromARGB(255, 62, 139, 202);

  CustomRoundRectButton(
      {Key? key,
      this.backgroundColor = c,
      this.txtColor = Colors.white,
      this.height = 30,
      this.width = 0,
      this.borderCircle = 30,
      required this.text,
      required this.p})
      : super(key: key);

  // HexColor("#0073b0")
  @override
  Widget build(BuildContext context) {
    return SizedBox(
      width: width == 0 ? MediaQuery.of(context).size.width : width,
      child: ElevatedButton(
        onPressed: () {
          p();
        },
        style: ElevatedButton.styleFrom(
            backgroundColor: backgroundColor,
            minimumSize: Size(double.infinity, height),
            shape: RoundedRectangleBorder(
                borderRadius: BorderRadius.circular(borderCircle))),
        child: Text(
          text,
          style: TextStyle(color: txtColor),
        ),
      ),
    );
  }
}

Tags:

本文暂时没有评论,来添加一个吧(●'◡'●)

欢迎 发表评论:

最近发表
标签列表