2025-07-03 09:45:15 +08:00
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
|
|
/// 自定义默认按钮
|
|
|
|
|
class CustomButton extends StatelessWidget {
|
|
|
|
|
final String text; // 按钮文字
|
|
|
|
|
final Color backgroundColor; // 按钮背景色
|
|
|
|
|
final double borderRadius; // 圆角半径(默认5)
|
|
|
|
|
final VoidCallback? onPressed; // 点击事件回调
|
|
|
|
|
final EdgeInsetsGeometry? padding; // 内边距
|
|
|
|
|
final EdgeInsetsGeometry? margin; // 外边距
|
|
|
|
|
final double? height; // 按钮高度
|
|
|
|
|
final TextStyle? textStyle; // 文字样式
|
|
|
|
|
|
|
|
|
|
const CustomButton({
|
|
|
|
|
super.key,
|
|
|
|
|
required this.text,
|
|
|
|
|
required this.backgroundColor,
|
|
|
|
|
this.borderRadius = 5.0,
|
|
|
|
|
this.onPressed,
|
|
|
|
|
this.padding,
|
|
|
|
|
this.margin,
|
|
|
|
|
this.height,
|
|
|
|
|
this.textStyle,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return GestureDetector(
|
|
|
|
|
onTap: onPressed,
|
|
|
|
|
child: Container(
|
2025-08-20 09:56:31 +08:00
|
|
|
|
height: height ?? 45, // 默认高度45
|
2025-07-03 09:45:15 +08:00
|
|
|
|
padding: padding ?? const EdgeInsets.all(8), // 默认内边距
|
2025-08-20 09:56:31 +08:00
|
|
|
|
margin: margin ?? const EdgeInsets.symmetric(horizontal: 5), // 默认外边距
|
2025-07-03 09:45:15 +08:00
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
borderRadius: BorderRadius.circular(borderRadius),
|
|
|
|
|
color: backgroundColor,
|
|
|
|
|
),
|
|
|
|
|
child: Center(
|
|
|
|
|
child: Text(
|
|
|
|
|
text,
|
|
|
|
|
style: textStyle ?? const TextStyle(
|
|
|
|
|
color: Colors.white,
|
2025-08-20 09:56:31 +08:00
|
|
|
|
fontSize: 15,
|
2025-07-03 09:45:15 +08:00
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|