buttonGradient method
Widget
buttonGradient(
- Gradient gradient,
- VoidCallback? onPressed, {
- double? width,
- double? height,
- double? textSize,
- double? radius,
- Color textColor = Colors.white,
- VoidCallback? onLongPress,
- Widget? child,
渐变色按钮
Implementation
Widget buttonGradient(
Gradient gradient,
VoidCallback? onPressed, {
double? width,
double? height,
double? textSize,
double? radius,
Color textColor = Colors.white,
VoidCallback? onLongPress,
Widget? child,
}) {
radius ??= 12;
textSize ??= 16;
return Container(
decoration: BoxDecoration(
gradient: onPressed == null ? null : gradient, // 渐变色
borderRadius: BorderRadius.circular(radius),
color: onPressed == null ? Colors.white.withOpacity(0.2) : null,
),
child: ElevatedButton(
onPressed: onPressed,
style: ButtonStyle(
shadowColor: MaterialStateProperty.all(Colors.transparent),
padding: MaterialStateProperty.all<EdgeInsetsGeometry>(EdgeInsets.zero),
backgroundColor: MaterialStateProperty.all(Colors.transparent),
shape: MaterialStateProperty.all(RoundedRectangleBorder(borderRadius: BorderRadius.circular(radius))),
),
child: Container(
alignment: Alignment.center,
height: height ?? 50,
child: child ??
Text(
this,
style: TextStyle(
color: onPressed == null ? Colors.white.withOpacity(0.2) : Colors.white, fontSize: textSize),
),
),
),
);
}