qhd-prevention-flutter/lib/customWidget/custom_button.dart

50 lines
1.4 KiB
Dart
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

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.all(8), // 默认内边距
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,
),
),
),
),
);
}
}