flutter - How to create a blur with a linear gradient in Flutter
问题描述
I am trying to create a widget inside of Flutter that will act like the BackdropFilter widget and blur anything behind it. Although unlike the BackdropFilter, this blurrness should not be distributed evenly but instead progressively increase in blur linearly.
Does anyone have any ideas. Thanks
解决方案
现在似乎可以使用新的ImageFiltered
Widget。
我通过这个GitHub 评论找到了一个代码示例:
Stack(
alignment: Alignment.bottomCenter,
fit: StackFit.expand,
children: <Widget>[
Image.network(
image,
fit: BoxFit.cover,
alignment: Alignment.bottomCenter),
ImageFiltered(
imageFilter: ImageFilter.blur(sigmaX: 10, sigmaY: 10),
child: ShaderMask(
shaderCallback: (rect) {
return LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [Colors.black, Colors.black.withOpacity(0)],
stops: [0.4, 0.75]).createShader(rect);
},
blendMode: BlendMode.dstOut,
child: Image.network(
image,
fit: BoxFit.cover,
alignment: Alignment.bottomCenter),
)
),
])
推荐阅读
- r - 计算组均值和总体均值
- cmd - 如何将 cmd 输出中的每一行通过管道传输到从 Microsoft SQL 创建的表中的列?
- mongodb - MongoDB 模式:喜欢评论或帖子
- python - 仅替换字符串中完全匹配的单词
- javascript - 在 2 点之间向下滚动将不起作用
- ruby-on-rails - 无法在 Rails 应用程序中刷新 Google API 令牌
- python - 从 cython 调用 c++ 模板函数
- c - 为什么添加 char(来自 argv)会导致 C 中没有结果
- angular - 量角器 - 在 pdf 查看器 iframe 中找不到下载按钮
- php - 如何对一组关联数组进行分组并声明自定义键?