app-starlock/lib/tools/submitBtn.dart
2024-08-19 15:24:14 +08:00

198 lines
4.5 KiB
Dart
Executable File

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);
String? btnName;
Function()? onClick;
EdgeInsetsGeometry? margin;
EdgeInsetsGeometry? padding;
double? width;
double? fontSize;
Color? color;
List<Color>? backgroundColorList;
double? borderRadius;
bool? isDelete;
bool? isDisabled;
@override
Widget build(BuildContext context) {
return Container(
width: ScreenUtil().screenWidth - 40.w,
height: 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!,
style: TextStyle(color: Colors.white, fontSize: 24.sp),
)),
);
/*
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(
begin: Alignment.centerLeft,
end: Alignment.centerRight,
colors: backgroundColorList ??
[
AppColors.mainColor,
AppColors.mainColor,
],
)),
child: Center(
child: Text(btnName!,
style: TextStyle(
fontSize: fontSize ?? 30.sp,
height: 1.3,
decoration: TextDecoration.none,
fontWeight: FontWeight.w500,
color: color ?? Colors.white)),
),
),
onTap: () {
if (onClick != null) {
onClick!();
}
},
);
*/
}
}
/*
* 底部添加白色按钮 公用组件
* */
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)),
)),
);
}
}