50 lines
1.4 KiB
Dart
50 lines
1.4 KiB
Dart
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(
|
||
height: height ?? 50, // 默认高度50
|
||
padding: padding ?? const EdgeInsets.symmetric(horizontal: 20), // 默认内边距
|
||
margin: margin ?? const EdgeInsets.symmetric(horizontal: 8), // 默认外边距
|
||
decoration: BoxDecoration(
|
||
borderRadius: BorderRadius.circular(borderRadius),
|
||
color: backgroundColor,
|
||
),
|
||
child: Center(
|
||
child: Text(
|
||
text,
|
||
style: textStyle ?? const TextStyle(
|
||
color: Colors.white,
|
||
fontWeight: FontWeight.bold,
|
||
),
|
||
),
|
||
),
|
||
),
|
||
);
|
||
}
|
||
} |