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_gradientbutton.dart

97 lines
2.4 KiB

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
class ASGradientButton extends StatefulWidget {
///按钮文字
///动态类型可以是string或者widget
final dynamic title;
///按钮文字颜色
///若已定义文字风格则此属性不生效
final Color textColor;
///圆角
final double radius;
///按钮文字风格
final TextStyle textStyle;
///内边距
final Padding padding;
///点击事件
final VoidCallback onPressed;
///渐变颜色
final List<Color> colors;
///开始位置
final AlignmentGeometry begin;
///结束位置
final AlignmentGeometry end;
///宽度
final double width;
ASGradientButton(
{Key key,
this.title,
this.textColor,
this.radius,
this.textStyle,
this.padding,
this.onPressed,
this.colors,
this.width,
this.begin,
this.end})
: super(key: key);
ASGradientButton.pay({
Key key,
this.title,
this.textStyle,
this.padding,
this.onPressed,
}) : textColor = Color(0xD9FFFFFF),
radius = 19.w,
colors = [Color(0xFFF89B14), Color(0xFFF86B140)],
width = 100.w,
begin = Alignment.centerLeft,
end = Alignment.centerRight,
super(key: key);
@override
_ASGradientButtonState createState() => _ASGradientButtonState();
}
class _ASGradientButtonState extends State<ASGradientButton> {
@override
Widget build(BuildContext context) {
return Container(
width: widget.width ?? 100.w,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: widget.begin ?? Alignment.centerLeft,
end: widget.end ?? Alignment.centerRight,
colors: widget.colors ?? [Color(0xFFF89B14), Color(0xFFF86B140)],
),
borderRadius: BorderRadius.circular(widget.radius ?? 19.w),
),
child: MaterialButton(
minWidth: widget.width ?? 100.w,
materialTapTargetSize: MaterialTapTargetSize.shrinkWrap,
onPressed: widget.onPressed,
child: widget.title is String
? Text(widget.title,
style: widget.textStyle ??
TextStyle(
color: widget.textColor ?? Color(0xD9FFFFFF),
fontSize: 18.sp))
: widget.title,
padding: widget.padding ?? EdgeInsets.symmetric(vertical: 8.w),
elevation: 0,
),
);
}
}