Flutte 圆角实现

一、使用CircleAvatar

const CircleAvatar({
    Key key,
    this.child,
    this.backgroundColor,
    this.backgroundImage,
    this.foregroundColor,
    this.radius,
    this.minRadius,
    this.maxRadius,
  }) : assert(radius == null || (minRadius == null && maxRadius == null)),
       super(key: key);

代码:

CircleAvatar(
	radius: 50,
	backgroundImage: NetworkImage(user.avatar_url ?? FZICons.DEFAULT_REMOTE_PIC),
),

效果:
CircleAvatar实现
二、使用BoxDecoration修饰器

const BoxDecoration({
    this.color,
    this.image,
    this.border,
    this.borderRadius,
    this.boxShadow,
    this.gradient,
    this.backgroundBlendMode,
    this.shape = BoxShape.rectangle,
  }) : assert(shape != null),
       assert(
         backgroundBlendMode == null || color != null || gradient != null,
         'backgroundBlendMode applies to BoxDecoration\'s background color or '
         'gradient, but no color or gradient was provided.'
       );

代码:

Container(
	width: 100,
	height: 100,
	decoration: BoxDecoration(
		image: DecorationImage(
			image: NetworkImage(user.avatar_url ?? FZICons.DEFAULT_REMOTE_PIC),
			fit: BoxFit.cover
		),
		borderRadius: BorderRadius.all(Radius.circular(50)),
	),
)

效果:
BoxDecoration修饰器实现

三、使用ClipOval

const ClipOval({ 
	Key key, 
	this.clipper,
 	this.clipBehavior = Clip.antiAlias, 
 	Widget child 
}) : super(key: key, child: child);

代码:

ClipOval(
	child: CachedNetworkImage(
		width: 100,
		height: 100,
		imageUrl: ImageUtil.imageUrlStr(user.avatar_url),
		fit: BoxFit.cover,
		placeholder: (context, url) => Icon(Icons.add),
		errorWidget: (context, url, error) => new Icon(Icons.error),
	),
),

效果:
ClipOval实现

四、使用ClipRRect

const ClipRRect({
    Key key,
    this.borderRadius,
    this.clipper,
    this.clipBehavior = Clip.antiAlias,
    Widget child,
  }) : assert(borderRadius != null || clipper != null),
       assert(clipBehavior != null),
       super(key: key, child: child);

代码:

ClipRRect(
	child: CachedNetworkImage(
		width: 100,
		height: 100,
 		imageUrl: ImageUtil.imageUrlStr(user.avatar_url),
		fit: BoxFit.cover,
		placeholder: (context, url) => Icon(Icons.add),
		errorWidget: (context, url, error) => new Icon(Icons.error),
	),
	borderRadius: BorderRadius.only(
		topLeft: Radius.circular(50),
		topRight: Radius.circular(50),
	),
),

效果:
ClipRRect实现

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值