第二次提交
This commit is contained in:
@@ -2,16 +2,52 @@ import 'package:flutter/material.dart';
|
||||
|
||||
class CCPrimaryButton extends StatelessWidget {
|
||||
final String text;
|
||||
final VoidCallback onPressed;
|
||||
final VoidCallback? onPressed;
|
||||
final double? width;
|
||||
final double height;
|
||||
final double fontSize;
|
||||
final Color backgroundColor; // 新增:背景颜色
|
||||
final Color textColor; // 新增:字体颜色
|
||||
|
||||
const CCPrimaryButton({
|
||||
super.key,
|
||||
required this.text,
|
||||
required this.onPressed,
|
||||
this.onPressed,
|
||||
this.width = double.infinity,
|
||||
this.height = 54.0,
|
||||
this.fontSize = 16.0,
|
||||
this.backgroundColor = Colors.black, // 默认黑色背景
|
||||
this.textColor = Colors.white, // 默认白色文字
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ElevatedButton(onPressed: onPressed, child: Text(text));
|
||||
// 💡 核心改动:如果父组件是 Row 且没有指定 width,
|
||||
// 直接用 double.infinity 会崩溃。
|
||||
// 使用这种方式可以更加安全。
|
||||
return SizedBox(
|
||||
width: width,
|
||||
height: height,
|
||||
child: ElevatedButton(
|
||||
onPressed: onPressed,
|
||||
style: ElevatedButton.styleFrom(
|
||||
backgroundColor: backgroundColor, // 使用参数
|
||||
foregroundColor: textColor, // 使用参数
|
||||
disabledBackgroundColor: Colors.grey.shade300,
|
||||
disabledForegroundColor: Colors.white,
|
||||
elevation: 0,
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16),
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
textStyle: TextStyle(
|
||||
fontSize: fontSize,
|
||||
fontWeight: FontWeight.w600,
|
||||
letterSpacing: 1.2,
|
||||
),
|
||||
),
|
||||
child: Text(text),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user