buttonGradient method

Widget buttonGradient(
  1. Gradient gradient,
  2. VoidCallback? onPressed, {
  3. double? width,
  4. double? height,
  5. double? textSize,
  6. double? radius,
  7. Color textColor = Colors.white,
  8. VoidCallback? onLongPress,
  9. 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),
            ),
      ),
    ),
  );
}