我需要在BackdropFilter.blur中创建一个100x100的未模糊孔

推荐答案

你可以用CustomClipper美元.

class MyClipper extends CustomClipper<Path> {
  @override
  Path getClip(Size size) {
    Path path = Path();
    path.fillType = PathFillType.evenOdd;
    path.addRect(Rect.fromLTWH(0, 0, size.width, size.height));

    path.addOval(Rect.fromCenter(
        center: Offset(size.width / 2, size.height / 2),
        width: 100,
        height: 100));

    return path;
  }

  @override
  bool shouldReclip(covariant CustomClipper<Path> oldClipper) => true;
}

并使用

ClipPath(
  clipper: MyClipper(),
  child: BackdropFilter(
    filter: ImageFilter.blur(
      //import dart:ui
      sigmaX: 5.0,
      sigmaY: 5.0,
    ),
    child: const SizedBox(
      width: 200.0,
      height: 200.0,
    ),
  ),
),

结果

enter image description here

Flutter相关问答推荐

滚动时应用栏 colored颜色 更改Flutter

flutter:如何将字体大小设置得更大(更大)

类型int不是可迭代动态tmdbapi类型的子类型<>

Dexing时出错.将Flutter 升级到3.19.0后

TextFormfield无法与自动路由一起正常工作

Flutter 隔离.使用多个参数运行

Android Studio将不会构建iOS模拟器应用程序,因为plist.info有问题

如何将assets资源 实体类型转换为文件类型?

来自FirebaseAuth的错误DisplayName和邮箱在Flutter应用程序中给出错误

导航回上一页会将我带回Ffltter应用程序中的登录页面

当 Dart SDK 版本范围不匹配时,为什么依赖解析器不会抛出错误?

在 Dart 中按土耳其语字母顺序对字符串进行排序

Flutter Dismissible 不会在 startToEnd 滑动时被关闭

Dart:未捕获错误:RangeError(索引):索引超出范围:索引应小于 7:7

点击后,将按钮的 colored颜色 禁用/更改一段时间

Flutter开发中,如何通过'nfc_manager'插件在Android设备上避免默认的New Tag Scanned弹出窗口?

获取通过列表呈现的相同 TextEditingController 的值

是否可以在 flutter 应用程序中使用 jetpack compose?

更改下拉按钮的背景 colored颜色 - flutter

我的主屏幕上的 FutureBuilder 不断重新加载(但仅在其他屏幕上时)?