ImageFiltered 与 BackdropFilter;有什么不同? [英] ImageFiltered vs BackdropFilter; what's the difference?

查看:14
本文介绍了ImageFiltered 与 BackdropFilter;有什么不同?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

ImageFilteredBackdropFilter 有什么区别,它们似乎都做同样的工作.我应该选择哪一个?

What's the difference between ImageFiltered and BackdropFilter, they both seem to do the same job. Which one should I choose?

推荐答案

ImageFilteredBackdropFilter 更易于使用,如果您只是打算将过滤器应用于您的子小部件.

ImageFiltered is more simpler to use than the BackdropFilter and is also recommended if you are only going to apply filters to your child widget.

BackdropFilter 在底层小部件之上应用过滤器(使用其 child 属性)不同,ImageFiltered 仅在 ImageFiltered 上应用过滤器代码>子小部件.为了更好地理解,请考虑以下示例.

Unlike BackdropFilter which applies filter (using its child property) on top of the underlying widget, ImageFiltered only applies the filter on the child widget. To better understand, please consider following example.

您会发现在 ImageFiltered 的情况下,过滤器应用于图像本身.但是,如果是 BackdropFilter(这通常与 Stack 一起使用,但我在 Column 中使用它)child(此处为 BackdropFilter 文本)被绘制在背景(Flutter 图像)上.

You'll find that in case of ImageFiltered, the filter is applied on the image itself. However, in case of BackdropFilter (this is generally used with a Stack but I used it in the Column) the child (here BackdropFilter text) is drawn over the background (Flutter image).

还值得注意的是,我将两个过滤器都包装在 ClipRRect 中,以防止模糊从容器框中出来.

It is also worth noting that I'm wrapping both the filters in ClipRRect to prevent the blur from coming out of the container box.

class FooPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.black,
      body: Column(
        children: [
          Text('ImageFiltered'),
          ClipRRect(
            child: ImageFiltered(
              imageFilter: _imageFilter,
              child: _image, // Above image filter is applied on the child itself.  
            ),
          ),
          SizedBox(height: 20),
          ClipRRect(
            child: Container(
              width: double.maxFinite,
              height: 200,
              decoration: BoxDecoration(image: DecorationImage(image: _image.image)), // Background
              child: BackdropFilter(
                filter: _imageFilter,
                child: Center(child: Text('BackdropFilter')), // Foreground
              ),
            ),
          ),
        ],
      ),
    );
  }

  Image get _image => Image.asset(flutterImage);

  ImageFilter get _imageFilter => ImageFilter.blur(sigmaX: 10, sigmaY: 10);
}

这篇关于ImageFiltered 与 BackdropFilter;有什么不同?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆