Skip to content

feat: add StacBackdropFilter widget #274

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Jun 9, 2025

Conversation

manav-m
Copy link
Contributor

@manav-m manav-m commented Jun 3, 2025

Adds the StacBackdropFilter widget, which applies a filter to the background of its child widget. The backdrop filter is applied to everything behind the child widget that is within the same layer.

Examples
✅ Example: Basic blur filter

{
  "type": "clipRRect",
  "borderRadius": {
    "all": 16
  },
  "child": {
    "type": "sizedBox",
    "height": 200,
    "width": 300,
    "child": {
      "type": "stack",
      "fit": "expand",
      "children": [
        {
          "type": "container",
          "decoration": {
            "image": {
              "src": "https://images.pexels.com/photos/1323550/pexels-photo-1323550.jpeg",
              "fit": "cover"
            }
          }
        },
        {
          "type": "backdropFilter",
          "filter": {
            "type": "blur",
            "sigmaX": 15.0,
            "sigmaY": 15.0
          },
          "child": {
            "type": "container",
            "decoration": {
              "color": "#80FFFFFF"
            }
          }
        }
      ]
    }
  }
}

More examples can be found in the docs at docs/widgets/backdrop_filter.md

Related Issues
Closes #269

Type of Change

  • New feature (non-breaking change which adds functionality)
  • Bug fix (non-breaking change which fixes an issue)
  • Breaking change (fix or feature that would cause existing functionality to change)
  • Code refactor
  • Build configuration change
  • Documentation
  • Chore

@CLAassistant
Copy link

CLAassistant commented Jun 3, 2025

CLA assistant check
All committers have signed the CLA.

Copy link
Member

@divyanshub024 divyanshub024 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks a lot for this contribution @manav-m 🎉 I have few suggestions please check them out.

Comment on lines 27 to 36
final imageFilter = StacImageFilterParser.parse(model.filter);
if (imageFilter == null) {
return child;
}

return BackdropFilter(
filter: imageFilter,
child: child,
);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We should throw error when imageFilter is missing. So, ideally we should remove the null check for imageFilter.

Widget parse(BuildContext context, StacBackdropFilter model) {
final child = Stac.fromJson(model.child, context) ?? const SizedBox();

if (!model.enabled) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

model.enabled should be passed in BackdropFilter

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@manav-m I think this one is not resolved. Can you please check?

Comment on lines 11 to 14
@Default(StacDouble(10.0)) StacDouble sigmaX,
StacDouble? sigmaY,
@Default(StacDouble(1.0)) StacDouble radiusX,
StacDouble? radiusY,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Default value for sigma and radius should be 0.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A 0 sigma/radius value would basically make the filter do nothing by default. Shouldn't the filter do a basic blur by default?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We usually set the default value of the Flutter framework to keep Stac consistent with Flutter.

@freezed
abstract class StacImageFilter with _$StacImageFilter {
const factory StacImageFilter({
required String type,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we please turn type into an enum?

import 'package:stac/src/parsers/widgets/stac_image_filter/stac_image_filter.dart';

class StacImageFilterParser {
static ImageFilter? parse(StacImageFilter? filter) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we please turn this into an extension method?

https://dart.dev/language/extension-methods

divyanshub024 and others added 3 commits June 8, 2025 11:25
Removed null check for image filter
Passing model.enabled to backdrop filter
Added support for Blendmode Property
Set default value for sigma and radius to 0
Filter type is now an enum
Turn the stac_image_filter_parser into an extension method
Convert the parse function into a getter
|-----------|------------------------|--------------------------------------------------------------------------------------------|
| `filter` | `Map<String, dynamic>` | The image filter to apply to the existing painted content before painting the child. |
| `child` | `Map<String, dynamic>?`| The widget to paint after applying the filter to the existing painted content. |
| `enabled` | `bool` | Whether the filter should be applied. When false, the child is drawn without a filter. Defaults to `true`. |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we please add the blendMode in docs?

Copy link
Member

@divyanshub024 divyanshub024 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your contribution @manav-m 🎉 💯

@divyanshub024 divyanshub024 merged commit e8623dc into StacDev:dev Jun 9, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

feat: Add support for BackdropFilter widget
3 participants