app-starlock/lib/tools/submitBtn.dart

206 lines
4.8 KiB
Dart
Raw Normal View History

2023-07-10 17:50:31 +08:00
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import '../app_settings/app_colors.dart';
/*
*
* */
class SubmitBtn extends StatelessWidget {
SubmitBtn({
required this.btnName,
Key? key,
this.borderRadius,
this.color,
this.padding,
this.onClick,
this.margin,
this.width,
this.backgroundColorList,
this.isDelete,
this.fontSize,
this.isDisabled,
}) : super(key: key);
2023-07-15 15:11:28 +08:00
String? btnName;
2023-07-10 17:50:31 +08:00
2023-07-15 15:11:28 +08:00
Function()? onClick;
2023-07-10 17:50:31 +08:00
2023-07-15 15:11:28 +08:00
EdgeInsetsGeometry? margin;
2023-07-10 17:50:31 +08:00
2023-07-15 15:11:28 +08:00
EdgeInsetsGeometry? padding;
2023-07-10 17:50:31 +08:00
2023-07-15 15:11:28 +08:00
double? width;
2023-07-10 17:50:31 +08:00
2023-07-15 15:11:28 +08:00
double? fontSize;
2023-07-10 17:50:31 +08:00
2023-07-15 15:11:28 +08:00
Color? color;
2023-07-10 17:50:31 +08:00
2023-07-15 15:11:28 +08:00
List<Color>? backgroundColorList;
2023-07-10 17:50:31 +08:00
2023-07-15 15:11:28 +08:00
double? borderRadius;
2023-07-10 17:50:31 +08:00
bool? isDelete;
2023-07-29 09:25:21 +08:00
bool? isDisabled;
2024-04-30 09:51:12 +08:00
2023-07-10 17:50:31 +08:00
@override
Widget build(BuildContext context) {
2024-04-30 09:51:12 +08:00
return Container(
width: ScreenUtil().screenWidth - 40.w,
constraints: BoxConstraints(
minHeight: 60.h, // 设置最小高度
),
child: ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: isDisabled == false
? AppColors.btnDisableColor
: (isDelete == true ? Colors.red : AppColors.mainColor),
),
onPressed: () {
if (onClick != null) {
onClick!();
}
},
child: Text(
btnName!,
textAlign: TextAlign.center, // 文本居中对齐
softWrap: true, // 允许换行
overflow: TextOverflow.visible, // 文本溢出时显示
style: TextStyle(
color: Colors.white,
fontSize: 24.sp,
height: 1.2, // 行高
),
)),
);
/*
2023-07-10 17:50:31 +08:00
return GestureDetector(
child: Container(
width: width??690.w,
padding: padding??EdgeInsets.only(
top: 20.w,
bottom: 20.w
),
margin: margin??EdgeInsets.only(top: 30.w),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(borderRadius ?? 10.w),
gradient: LinearGradient(
2023-07-10 17:50:31 +08:00
begin: Alignment.centerLeft,
end: Alignment.centerRight,
colors: backgroundColorList ??
[
AppColors.mainColor,
AppColors.mainColor,
],
)),
2023-07-10 17:50:31 +08:00
child: Center(
child: Text(btnName!,
style: TextStyle(
fontSize: fontSize ?? 30.sp,
height: 1.3,
decoration: TextDecoration.none,
fontWeight: FontWeight.w500,
color: color ?? Colors.white)),
2023-07-10 17:50:31 +08:00
),
),
onTap: () {
if (onClick != null) {
2023-07-15 15:11:28 +08:00
onClick!();
2023-07-10 17:50:31 +08:00
}
},
);
*/
2023-07-10 17:50:31 +08:00
}
}
/*
*
* */
class AddBottomWhiteBtn extends StatelessWidget {
AddBottomWhiteBtn({
required this.btnName,
Key? key,
this.onClick,
}) : super(key: key);
String? btnName;
Function()? onClick;
@override
Widget build(BuildContext context) {
return GestureDetector(
child: Container(
height: 90.h,
margin: EdgeInsets.only(left: 20.w, right: 20.w),
decoration: BoxDecoration(
color: Colors.white, borderRadius: BorderRadius.circular(8.w)),
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: [
Image.asset(
'images/icon_btn_add.png',
width: 28.w,
height: 28.w,
),
SizedBox(
width: 6.w,
),
Text(
btnName!,
style: TextStyle(
color: AppColors.mainColor,
fontSize: 24.sp,
fontWeight: FontWeight.bold),
)
],
),
),
onTap: () {
if (onClick != null) {
onClick!();
}
},
);
}
}
/*
*
* */
class OutLineBtn extends StatelessWidget {
OutLineBtn({
required this.btnName,
Key? key,
this.onClick,
}) : super(key: key);
String? btnName;
Function()? onClick;
@override
Widget build(BuildContext context) {
return SizedBox(
width: ScreenUtil().screenWidth - 40.w,
height: 60.h,
child: OutlinedButton(
style: OutlinedButton.styleFrom(
backgroundColor: Colors.white,
side: BorderSide(width: 1, color: AppColors.mainColor)),
onPressed: () {
if (onClick != null) {
onClick!();
}
},
child: Text(
btnName!,
style: TextStyle(
color: AppColors.mainColor, fontSize: ScreenUtil().setSp(24)),
)),
);
}
}