Skip to content

Commit

Permalink
[framework] document backdropfilter antipattern (#109340)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonahwilliams committed Aug 11, 2022
1 parent 3f5a253 commit 6e92f87
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions packages/flutter/lib/src/widgets/basic.dart
Original file line number Diff line number Diff line change
Expand Up @@ -493,6 +493,45 @@ class ShaderMask extends SingleChildRenderObjectWidget {
/// [ImageFiltered] instead. For that scenario, [ImageFiltered] is both
/// easier to use and less expensive than [BackdropFilter].
///
/// {@tool snippet}
///
/// This example shows how the common case of applying a [BackdropFilter] blur
/// to a single sibling can be replaced with an [ImageFiltered] widget. This code
/// is generally simpler and the performance will be improved dramatically for
/// complex filters like blurs.
///
/// The implementation below is unnecessarily expensive.
///
/// ```dart
/// Widget buildBackdrop() {
/// return Stack(
/// children: <Widget>[
/// Positioned.fill(child: Image.asset('image.png')),
/// Positioned.fill(
/// child: BackdropFilter(
/// filter: ui.ImageFilter.blur(sigmaX: 6, sigmaY: 6),
/// ),
/// ),
/// ],
/// );
/// }
/// ```
/// {@end-tool}
/// {@tool snippet}
/// Instead consider the following approach which directly applies a blur
/// to the child widget.
///
/// ```dart
/// Widget buildFilter() {
/// return ImageFiltered(
/// imageFilter: ui.ImageFilter.blur(sigmaX: 6, sigmaY: 6),
/// child: Image.asset('image.png'),
/// );
/// }
/// ```
///
/// {@end-tool}
///
/// See also:
///
/// * [ImageFiltered], which applies an [ImageFilter] to its child.
Expand Down

0 comments on commit 6e92f87

Please sign in to comment.