import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; enum Type { primary, second, cancel, disable, } enum BtnSize { small, normal, large, } class CEBtn extends StatelessWidget { final String title; final Type? type; final BtnSize? btnSize; final VoidCallback onPressed; const CEBtn({ super.key, required this.title, required this.onPressed, this.type, this.btnSize, }); @override Widget build(BuildContext context) { Color? backColor = Colors.blue; var textColor = Colors.white; var size = WidgetStateProperty.all(Size(40, 20)); double fontSize = 12; switch (type) { case Type.primary: backColor = Colors.blue; break; case Type.second: backColor = Colors.lightBlue; break; case Type.cancel: backColor = Colors.grey[100]; textColor = Colors.black87; break; case Type.disable: backColor = Colors.grey; break; case null: backColor = Colors.blue; break; } switch (btnSize) { case BtnSize.small: size = WidgetStateProperty.all(Size(40, 20)); fontSize = 12; break; case BtnSize.large: size = WidgetStateProperty.all(Size(80, 40)); fontSize = 16; break; case null: size = WidgetStateProperty.all(Size(0, 0)); fontSize = 14; break; case BtnSize.normal: size = WidgetStateProperty.all(Size(60, 30)); fontSize = 14; break; } var backgroundColor = WidgetStateProperty.all(backColor); // 按扭背景颜色 var foregroundColor = WidgetStateProperty.all(textColor); // 按钮文本颜色 return ElevatedButton( onPressed: onPressed, child: Text(title,style: TextStyle(fontSize: fontSize,fontWeight: FontWeight.normal),), style: ButtonStyle( backgroundColor: backgroundColor, foregroundColor: foregroundColor, padding: WidgetStateProperty.all(EdgeInsets.symmetric(vertical: 4, horizontal: 8)), minimumSize: size, // 设置最小宽度和高度// 设置内边距 shape: WidgetStateProperty.all(RoundedRectangleBorder( borderRadius: BorderRadius.circular(5))), // 圆角 ), ); } }