flutter_integrated_whb/lib/customWidget/custom_button.dart

51 lines
1.4 KiB
Dart
Raw Normal View History

2025-07-11 11:03:21 +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-07-28 14:22:07 +08:00
height: height ?? 45, // 默认高度45
2025-07-11 11:03:21 +08:00
padding: padding ?? const EdgeInsets.all(8), // 默认内边距
2025-07-22 13:34:34 +08:00
margin: margin ?? const EdgeInsets.symmetric(horizontal: 5), // 默认外边距
2025-07-11 11:03:21 +08:00
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(borderRadius),
color: backgroundColor,
),
child: Center(
child: Text(
text,
style: textStyle ?? const TextStyle(
color: Colors.white,
2025-07-28 14:22:07 +08:00
fontSize: 15,
2025-07-11 11:03:21 +08:00
fontWeight: FontWeight.bold,
),
),
),
),
);
}
}