验证码: 看不清楚,换一张 查询 注册会员,免验证
  • {{ basic.site_slogan }}
  • 打开微信扫一扫,
    您还可以在这里找到我们哟

    关注我们

flutter常见圆角如何处理

阅读:453 来源:乙速云 作者:代码code

flutter常见圆角如何处理

      步骤

      ClipRRect 方式:

      这种方式是包裹在图片上,然后通过裁切的方式进行圆角处理,很常见。

      如果你要裁切成圆形,Radius = 边长 / 2

          ClipRRect(
            borderRadius: BorderRadius.circular(10),
            child: Image.asset(
              'assets/desktop.jpg',
              width: 100,
              height: 100,
              fit: BoxFit.cover,
            ),
          );

      ClipOval 方式:

      直接对一张图片进行圆形裁切,一般用在用户头像处理。

          ClipOval(
            child: Image.asset(
              'assets/desktop.jpg',
              width: 100,
              height: 100,
              fit: BoxFit.cover,
            ),
          );

      ClipPath 方式:

      这种方式用在自定义裁切一张图片,比如机票左右两侧的三角凹陷。

      你需要自定义一个 Clip Path。

      class MyCustomClipper1 extends CustomClipper<Path> {
        @override
        Path getClip(Size size) {
          var path = Path();
          // 四个圆角,圆角半径为20
          path.addRRect(RRect.fromLTRBR(
              0, 0, size.width, size.height, const Radius.circular(20)));
          return path;
        }
      
        @override
        bool shouldReclip(CustomClipper<Path> oldClipper) {
          return false;
        }
      }
      		ClipPath(
            clipper: MyCustomClipper1(),
            child: Image.asset(
              'assets/desktop.jpg',
              width: 100,
              height: 100,
              fit: BoxFit.cover,
            ),
          );

      BoxDecoration 方式:

      这种方式用在背景图片的圆角处理,比如用户首页封面图,广告轮播图。

      		Container(
            decoration: const BoxDecoration(
              borderRadius: BorderRadius.all(Radius.circular(10)),
              image: DecorationImage(
                image: AssetImage('assets/desktop.jpg'),
                fit: BoxFit.cover,
              ),
            ),
            width: 100,
            height: 100,
          );
    分享到:
    *特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: hlamps#outlook.com (#换成@)。
    相关文章
    {{ v.title }}
    {{ v.description||(cleanHtml(v.content)).substr(0,100)+'···' }}
    你可能感兴趣
    推荐阅读 更多>