美文网首页
Flutter | 封装一个背景渐变且具有波浪效果的button

Flutter | 封装一个背景渐变且具有波浪效果的button

作者: 贾震惊 | 来源:发表于2022-11-26 23:06 被阅读0次

如上图,这是一个比较常见的需求:

  1. 按钮背景色渐变;
  2. 点击按钮会产生波浪特效。

代码:

class GradientTextButton extends StatelessWidget {
  const GradientTextButton({
    Key? key,
    required this.gradient,
    required this.onTap,
    required this.textString,
    this.textStyle,
    this.width,
    this.height,
    this.radius,
  }) : super(key: key);

  // 标题
  final String textString;
  // 标题样式
  final TextStyle? textStyle;
  // 渐变
  final LinearGradient gradient;
  // 点击回调
  final VoidCallback onTap;
  // 宽
  final double? width;
  // 高
  final double? height;
  // 圆角
  final double? radius;

  @override
  Widget build(BuildContext context) {
    return Material(
      clipBehavior: Clip.hardEdge,
      borderRadius: radius == null ? null : BorderRadius.circular(radius!),
      child: Ink(
        width: width,
        height: height,
        decoration: BoxDecoration(
          gradient: gradient,
        ),
        child: InkWell(
          onTap: onTap,
          child: Center(
            child: Text(
              textString,
              style: textStyle ??
                  const TextStyle(
                    fontWeight: FontWeight.w500,
                    fontSize: 16,
                    color: Colors.white,
                  ),
            ),
          ),
        ),
      ),
    );
  }
}

相关文章

  • iOS 渐变色水波纹

    因项目需求封装了一个带有渐变色水波视图,水波视图相信大家可以在网上搜到很多,但是绘制一个波浪是渐变色的,且背景也可...

  • Swift.类微博弹出动画

    实现效果: view弹出时:背景渐变展示,有毛玻璃效果.view内部的button依次从上方弹到指定frame. ...

  • RN渐变按钮

    react-native渐变效果,渐变背景组件封装 组件文件 使用(自己修改一下导入路径)

  • 【iOS】渐变水波 YAWaveView

    一个渐变水波视图,水波视图相信大家已经司空见惯,但是最近视觉要求绘制一个波浪是渐变色的,且背景是径向渐变的水波,于...

  • [每天进步一点点~] uni-app css 制作雷达扫描、波浪

    雷达扫描效果(背景换成纯色渐变了): 波浪移动动画效果 第一种: 第二种(有待改进,后续再补)

  • 类似gradientLayer绘制成渐变图片

    今天有个需求,需要给了渐变颜色,然后制作出渐变图片。应用场景,比如给button设置背景图,然后按下效果是butt...

  • CSS渐变之背景、边框、字体渐变

    使用CSS实现背景色渐变、边框渐变,字体渐变的效果。 背景色渐变 效果如图: linear-gradient: (...

  • 5、条纹背景

    1、水平和垂直条纹 使用背景渐变效果可以实现各种各样的条纹背景。当渐变色中的多个色标具有相同的位置时,它们之间就不...

  • 实现背景渐变效果

    UIView *bgView = [[UIView alloc] initWithFrame:CGRectMake...

  • CSS制作逼真的波浪效果

    这是使用 SVG 和 CSS 动画制作的波浪效果,上半部分是蓝色(可修改成其他颜色)渐变的背景颜色,下半部分就是波...

网友评论

      本文标题:Flutter | 封装一个背景渐变且具有波浪效果的button

      本文链接:https://www.haomeiwen.com/subject/johhfdtx.html