添加渐变按钮

null_safety
张萌 4 years ago
parent bd07e09b4a
commit 81e39621bc

@ -0,0 +1,96 @@
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
class ASGradientButton extends StatefulWidget {
///
///stringwidget
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,
),
);
}
}
Loading…
Cancel
Save