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

173 lines
4.2 KiB

4 years ago
import 'package:flutter/material.dart';
4 years ago
import 'package:flutter_screenutil/flutter_screenutil.dart';
4 years ago
///安速按钮
class ASButton extends StatefulWidget {
4 years ago
///按钮颜色
final Color bgcolor;
4 years ago
///按钮文字
///动态类型可以是string或者widget
final dynamic title;
///按钮圆角
final double radius;
///按钮边框
final bool outline;
///按钮边框颜色
final Color outlineColor;
///按钮文字颜色
///若已定义文字风格则此属性不生效
4 years ago
final Color textColor;
///按钮文字格式
final TextStyle textStyle;
///内边距
final EdgeInsets padding;
///点击事件
final VoidCallback onPressed;
4 years ago
4 years ago
///宽度
final double width;
4 years ago
///不可点击颜色
final Color disableColor;
///不可点击时文字颜色
final Color disableTextColor;
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,
4 years ago
}) : super(key: key);
4 years ago
ASButton.warn(
{Key key,
this.textStyle,
this.padding,
this.radius,
this.bgcolor,
this.onPressed,
4 years ago
@required this.title,
4 years ago
this.width,
this.disableColor,
this.disableTextColor})
4 years ago
: outline = true,
outlineColor = Color(0xFFE50112),
textColor = Color(0xFFE50112),
super(key: key);
4 years ago
ASButton.info(
{Key key,
this.bgcolor,
this.radius,
this.textStyle,
this.padding,
@required this.title,
this.onPressed,
4 years ago
this.width,
this.disableColor,
this.disableTextColor})
4 years ago
: outline = true,
outlineColor = Color(0x73000000),
textColor = Color(0xD9000000),
super(key: key);
4 years ago
ASButton.delete(
{Key key,
this.radius,
this.outlineColor,
this.textStyle,
this.padding,
@required this.title,
this.onPressed,
4 years ago
this.width,
this.disableColor,
this.disableTextColor})
: bgcolor = Color(0xFFFFB600),
4 years ago
textColor = Color(0xD9FFFFFF),
outline = false,
super(key: key);
4 years ago
ASButton.opration(
{Key key,
this.radius,
this.outlineColor,
this.textStyle,
this.padding,
@required this.title,
this.onPressed,
4 years ago
this.width,
this.disableColor,
this.disableTextColor})
: bgcolor = Color(0xFFF2F2F2),
textColor = Color(0xD9000000),
outline = false,
super(key: key);
4 years ago
ASButton.order({
Key key,
@required this.title,
this.onPressed,
this.outlineColor,
this.width,
}) : bgcolor = Color(0xFFFFBD32),
textColor=Color(0xFF0000000),
textStyle = TextStyle(
fontSize: 14.sp,
fontWeight: FontWeight.bold),
radius = 5.w,
outline = false,
disableColor = Color(0xFFFFDF9B),
disableTextColor = Color(0x73000000),
padding=EdgeInsets.symmetric(vertical: 8.w),
super(key: key);
4 years ago
@override
_ASButtonState createState() => _ASButtonState();
}
class _ASButtonState extends State<ASButton> {
@override
Widget build(BuildContext context) {
4 years ago
return MaterialButton(
4 years ago
disabledColor: widget.disableColor ?? widget.bgcolor,
disabledTextColor: widget.disableTextColor ?? Color(0x73000000),
textColor: widget.textColor ?? Color(0xFFFFB600),
4 years ago
minWidth: widget.width ?? 75.w,
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
onPressed: widget.onPressed,
4 years ago
child: widget.title is String
? Text(widget.title,
style: widget.textStyle ??
TextStyle(
fontSize: 13.sp))
4 years ago
: widget.title,
4 years ago
padding: widget.padding ?? EdgeInsets.symmetric(vertical: 6.w),
4 years ago
shape: RoundedRectangleBorder(
side: widget.outline
? BorderSide(color: widget.outlineColor, width: 0.5.w)
4 years ago
: BorderSide.none,
borderRadius: BorderRadius.circular(widget.radius ?? 15.5.w)),
color: widget.bgcolor ?? Color(0xFFFFFFFF),
4 years ago
elevation: 0,
4 years ago
focusElevation: 0,
highlightElevation: 0,
hoverElevation: 0,
4 years ago
);
4 years ago
}
}