[英]blur edeges of horizontal listview flutter
It can be done in few ways:可以通过以下几种方式完成:
Stack
with 3 Positioned
widgets(left blur with defined width with z=1, your full-width list with z = 0, right blur with defined width and z=1)将Stack
与 3 个Positioned
小部件一起使用(左模糊,定义宽度,z=1,全宽度列表,z = 0,右模糊,定义宽度和 z=1)ShaderMask
使用ShaderMask
I will propose an example code for the second approach.我将为第二种方法提出一个示例代码。 This is how your BlurredHorizontalListView
build method might look like:这就是您的BlurredHorizontalListView
构建方法的样子:
@override
Widget build(BuildContext context) {
return Container(
height: 400,
child: ShaderMask(
shaderCallback: (Rect bounds) {
return LinearGradient(
begin: Alignment.centerLeft,
end: Alignment.centerRight,
colors: <Color>[
Colors.transparent,
Colors.white,
Colors.transparent
],
).createShader(bounds);
},
blendMode: BlendMode.dstIn,
child: ListView.builder(
itemBuilder: (BuildContext context, int index) {
return Card(
child: Container(
width: 220,
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Image.network(
YOUR_URL,
height: 190,
fit: BoxFit.cover,
),
],
),
),
);
},
scrollDirection: Axis.horizontal,
itemCount: 3,
),
),
);
}
Parts of the example are hardcoded, so feel free to adjust it by your needs.该示例的部分内容是硬编码的,因此请随意根据您的需要进行调整。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.