flutter - Flutter 如何创建分割的圆形合并图像
问题描述
我想创建形状像这样的圆形合并图像。例如有teamA 和teamB,teamA 的logo 或图片出现在圆圈的左边,而teamB 出现在右边。
我试过这样,但两个图像的形状仍然是这样的矩形。
我怎样才能让它工作?
new Center(
child: new Container(
width: 120.0,
height: 120.0,
child: new Row(
children: <Widget>[
Image.network(
'https://images.unsplash.com/photo-1535593063927-5c40dee9cb83?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=3bfc6e7c6043924de9c4746bef6dc969&auto=format&fit=crop&w=500&q=60',
width: 60.0,
height: 120.0,
fit: BoxFit.cover,
),
Image.network(
'https://images.unsplash.com/photo-1535603863228-ded98173a95d?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=78dee486ac6c9bffda623b83a36ecb1f&auto=format&fit=crop&w=500&q=60',
width: 60.0,
height: 120.0,
fit: BoxFit.cover,
)
],
),
),
),
解决方案
有很多方法可以实现这一点,其中一种是这样的:
new Center(
child: new Container(
height: 300.0,
width: 300.0,
decoration: BoxDecoration(
shape: BoxShape.circle,
border: new Border.all(color: Colors.blue, width: 4.0),
),
child: new Stack(
children: <Widget>[
Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
image: DecorationImage(
fit: BoxFit.cover,
image: NetworkImage(
'https://images.unsplash.com/photo-1535593063927-5c40dee9cb83?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=3bfc6e7c6043924de9c4746bef6dc969&auto=format&fit=crop&w=500&q=60',
))),
),
ClipRect(
child: Align(
alignment: Alignment.centerLeft,
widthFactor: 0.5,
child: Container(
decoration: BoxDecoration(
shape: BoxShape.circle,
image: DecorationImage(
fit: BoxFit.cover,
image: NetworkImage(
'https://images.unsplash.com/photo-1535603863228-ded98173a95d?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=78dee486ac6c9bffda623b83a36ecb1f&auto=format&fit=crop&w=500&q=60'),
)),
),
),
),
],
),
),
)
结果
推荐阅读
- reactjs - Google-maps-react Polyline 根本没有显示
- java - libgdx Clicklistener 不起作用,缺少什么?
- django - 渲染慢速加载结果
- javascript - 我们如何使用这个命令 ./prog.js 来启动一个 JS 程序?
- python - pyspark - 尝试从 Vector Dense 对象获取最大值时出错
- java - 我的程序只能在 NetBeans 中运行,但是当我将它构建到 JAR 中时它不起作用
- c# - 来自 C# 中接口的异步 ObservableCollection (Xamarin)
- javascript - Highcharts - 2 个同步的活动量表
- c - 3 个不同的函数根据 C 中的变量类型给出相同的输出
- protractor - 我们如何在量角器中使用硒网格进行分布式测试执行