【发布时间】:2020-03-11 15:57:44
【问题描述】:
我想在 Flutter 中的图像上应用 BackdropFilter。所以,我使用下面的方式来应用Flutter docs中给出的过滤器。
import 'dart:ui';
import 'package:flutter/material.dart';
void main() {
runApp(
MaterialApp(
debugShowCheckedModeBanner: false,
home: Scaffold(
body: MyApp(),
),
),
);
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: Stack(
alignment: Alignment.bottomCenter,
children: <Widget>[
Container(
height: 500,
child: Image.network('https://encrypted-tbn0.gstatic.com/images?q=tbn%3AANd9GcQlXYdeEKhFq34sh8-0ZKC1uqCcVGgOzdW_ZRAqCBkWxG-oeCB1'),
),
Positioned(
top: 300,
bottom: 0,
left: 0,
right: 0,
child: ClipRect(
child: BackdropFilter(
filter: ImageFilter.blur(sigmaX: 2, sigmaY: 10),
child: Container(
color: Colors.black.withOpacity(0),
),
),
),
),
]
),
),
);
}
}
它产生了以下输出: Output of my code
我在 BackDropFilter 和 Image 之间遇到了困难。不过,我希望它们之间有一个平滑的边缘。
我怎样才能实现类似 this?
【问题讨论】:
-
我做了一些实验,但即使是来自 Flutter 团队的 YouTube 视频中的原始代码也不能像视频中显示的那样工作。 Positioned Widget 无法正常工作,而 Clipping 它的结果与您得到的结果相同。