You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
ansu_ui/lib/buttons/as_button.dart

180 lines
4.4 KiB

4 years ago
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:ansu_ui/styles/as_colors.dart';
4 years ago
///安速按钮
class ASButton extends StatelessWidget {
4 years ago
///按钮颜色
final Color? bgcolor;
4 years ago
///按钮文字
///动态类型可以是string或者widget
final dynamic title;
///按钮圆角
final double? radius;
4 years ago
///按钮边框
final bool outline;
///按钮边框颜色
final Color? outlineColor;
4 years ago
///按钮文字颜色
///若已定义文字风格则此属性不生效
final Color? textColor;
4 years ago
///按钮文字格式
final TextStyle? textStyle;
4 years ago
///内边距
final EdgeInsets? padding;
4 years ago
///点击事件
final VoidCallback? onPressed;
4 years ago
4 years ago
///宽度
final double? width;
4 years ago
///不可点击颜色
final Color? disableColor;
4 years ago
///不可点击时文字颜色
final Color? disableTextColor;
final Color? splashColor;
4 years ago
ASButton({
Key? key,
this.bgcolor,
4 years ago
this.radius,
this.outline = false,
this.outlineColor,
this.textColor,
this.textStyle,
this.padding,
required this.title,
this.onPressed,
4 years ago
this.width,
4 years ago
this.disableColor,
this.disableTextColor,
this.splashColor,
4 years ago
}) : super(key: key);
ASButton.danger({
Key? key,
this.textStyle,
this.padding,
this.radius,
this.bgcolor,
this.onPressed,
required this.title,
this.width,
this.disableColor,
this.disableTextColor,
}) : outline = true,
outlineColor = kDangerColor,
textColor = kDangerColor,
splashColor = kDangerColor.withOpacity(0.2),
4 years ago
super(key: key);
4 years ago
ASButton.info(
{Key? key,
4 years ago
this.bgcolor,
this.radius,
this.textStyle,
this.padding,
required this.title,
this.onPressed,
4 years ago
this.width,
this.disableColor,
this.disableTextColor,
this.splashColor})
4 years ago
: outline = true,
4 years ago
outlineColor = kDarkColor,
textColor = kTextColor,
4 years ago
super(key: key);
4 years ago
ASButton.warn({
Key? key,
4 years ago
this.radius,
this.outlineColor,
this.textStyle,
this.padding,
required this.title,
4 years ago
this.onPressed,
this.width,
this.disableColor,
this.disableTextColor,
}) : bgcolor = kLightPrimaryColor,
4 years ago
textColor = kLightTextColor,
4 years ago
outline = false,
4 years ago
this.splashColor = ColorTool.getSplashColor(kPrimaryColor),
4 years ago
super(key: key);
ASButton.operation(
{Key? key,
4 years ago
this.radius,
this.outlineColor,
this.textStyle,
this.padding,
required this.title,
this.onPressed,
4 years ago
this.width,
this.disableColor,
this.disableTextColor,
this.splashColor})
: bgcolor = Color(0xFFF2F2F2),
4 years ago
textColor = kTextColor,
outline = false,
super(key: key);
4 years ago
ASButton.order({
Key? key,
required this.title,
4 years ago
this.onPressed,
this.outlineColor,
this.width,
this.splashColor,
4 years ago
}) : bgcolor = kLightPrimaryColor,
textColor = kTextColor,
textStyle = TextStyle(fontSize: 14.sp, fontWeight: FontWeight.bold),
4 years ago
radius = 5.w,
outline = false,
disableColor = Color(0xFFFFDF9B),
4 years ago
disableTextColor = kTextSubColor,
padding = EdgeInsets.symmetric(vertical: 8.w),
4 years ago
super(key: key);
4 years ago
@override
Widget build(BuildContext context) {
4 years ago
return MaterialButton(
disabledColor: disableColor,
disabledTextColor: disableTextColor,
textColor: textColor ?? kLightPrimaryColor,
minWidth: width,
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
onPressed: onPressed,
child: title is String
? Text(title, style: textStyle ?? TextStyle(fontSize: 13.sp))
: title,
padding: padding ?? EdgeInsets.symmetric(vertical: 6.w, horizontal: 12.w),
shape: radius == null
? StadiumBorder(
side: outline
? BorderSide(color: outlineColor!, width: 0.5.w)
: BorderSide.none,
)
: RoundedRectangleBorder(
side: outline
? BorderSide(color: outlineColor!, width: 0.5.w)
: BorderSide.none,
borderRadius: BorderRadius.circular(radius ?? 15.5.w)),
color: bgcolor ?? kForegroundColor,
splashColor: splashColor,
highlightColor: splashColor?.withOpacity(0.3),
4 years ago
elevation: 0,
4 years ago
focusElevation: 0,
highlightElevation: 0,
hoverElevation: 0,
4 years ago
);
4 years ago
}
}