Skip to content

Conversation

@TahaTesser
Copy link
Member

@TahaTesser TahaTesser commented Feb 11, 2022

regression: #94811
context: #94811 (review)
fixes: #98205

We didn't know why ClipRect was present as it wasn't failing any test but looks like it does affect BackdropFilter when applied to Snackbar's content

For regular widgets, BackdropFilter could use some clipping thus ClipRect is usually applied, see this #16614 (comment)
For Snackbar, it is not possible since you can only provide Snackbar to showSnackbar function and this issue shows when trying to apply BackdropFilter Snackbar's Content to achieve the desired results, blur area is not clipped.

So this PR introduces clip behavior, which when not set to Clip.none, applies ClipRect to the Snackbar itself. This is same as CupertinoFormSection clipBehavior code.

This way clipping is achievable when needed without breaking previous issue or new issue.

minimal code sample
import 'dart:ui';

import 'package:flutter/material.dart';

void main() => runApp(const MyApp());

class MyApp extends StatelessWidget {
  const MyApp({Key? key, this.dark = false}) : super(key: key);

  final bool dark;

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'Material App',
      theme: dark ? ThemeData.dark() : ThemeData.light(),
      home: const SnackarSample(),
    );
  }
}

class SnackarSample extends StatelessWidget {
  const SnackarSample({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('Snackar Sample'),
      ),
      body: Center(
        child: OutlinedButton(
          onPressed: () {
            ScaffoldMessenger.of(context).showSnackBar(SnackBar(
              clipBehavior: Clip.hardEdge,
              backgroundColor: Colors.transparent,
              content: BackdropFilter(
                filter: ImageFilter.blur(
                  sigmaX: 20.0,
                  sigmaY: 20.0,
                ),
                child: const Text('I am a snack bar.'),
              ),
              duration: const Duration(seconds: 2),
              action: SnackBarAction(label: 'ACTION', onPressed: () {}),
              behavior: SnackBarBehavior.fixed,
            ));
          },
          child: const Text('Show Snackbar'),
        ),
      ),
      floatingActionButton: FloatingActionButton(onPressed: () {}),
    );
  }
}
Preview

Screenshot 2022-02-11 at 14 10 00

Golden test

snack_bar goldenTest backdropFilter

Pre-launch Checklist

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I signed the CLA.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///).
  • I added new tests to check the change I am making, or this PR is test-exempt.
  • All existing and new tests are passing.

If you need help, consider asking for advice on the #hackers-new channel on Discord.

@flutter-dashboard flutter-dashboard bot added f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. labels Feb 11, 2022
@TahaTesser TahaTesser force-pushed the fix-snackbar-cliprect branch from bd36fd5 to 2a2a5eb Compare February 11, 2022 12:47
@TahaTesser TahaTesser changed the title Add clipBehaviour for Snackbar Add clipBehavior for Snackbar Feb 11, 2022
@TahaTesser TahaTesser requested a review from Piinks February 11, 2022 12:51
@skia-gold

This comment was marked as resolved.

@skia-gold

This comment was marked as resolved.

@HansMuller HansMuller requested a review from flar February 11, 2022 17:57
@TahaTesser TahaTesser changed the title Add clipBehavior for Snackbar Add clipBehavior to Snackbar Feb 11, 2022
@TahaTesser TahaTesser force-pushed the fix-snackbar-cliprect branch from 9c3aa7c to 14c4507 Compare February 15, 2022 08:05
@skia-gold

This comment was marked as resolved.

@skia-gold

This comment was marked as resolved.

@skia-gold

This comment was marked as resolved.

@skia-gold

This comment was marked as resolved.

@flutter-dashboard
Copy link

Golden file changes have been found for this pull request. Click here to view and triage (e.g. because this is an intentional change).

If you are still iterating on this change and are not ready to resolve the images on the Flutter Gold dashboard, consider marking this PR as a draft pull request above. You will still be able to view image results on the dashboard, commenting will be silenced, and the check will not try to resolve itself until marked ready for review.

For more guidance, visit Writing a golden file test for package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

Changes reported for pull request #98252 at sha cd629487561f4da4de6775d277f8a585ac3b806e

@flutter-dashboard flutter-dashboard bot added the will affect goldens Changes to golden files label Feb 15, 2022
@flar
Copy link
Contributor

flar commented Feb 15, 2022

So are we adding a clip to all snackbars in case a particular child needs it? Could the responsibility be pushed to the child that actually adds the BackdropFilter? Isn't that a widget that we control?

@TahaTesser
Copy link
Member Author

Hey @flar
ClipRect was present before but for another issue, we had to remove it #94811
Looks like it is needed so this PR adds it back but with clipBehavior.

showSnackbar only takes Snackbar, not Widget such as Snackbar wrapped with ClipRect.
and if you apply clipping to content of Snackbar you get something like this

Screenshot 2022-02-16 at 06 19 14

While the desired effect is

Screenshot 2022-02-11 at 14 10 00

Copy link
Contributor

Choose a reason for hiding this comment

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

Since this was a regression, should we restore the original behavior that clipped, and let those that do not want it to set Clip.none?
I can see folks not wanting a subtle shadow clip, but I can also understand folks that were broken by removing the clip, and in the case of the backdrop filter experiencing a very disruptive change.

Copy link
Member Author

Choose a reason for hiding this comment

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

I like this idea, I think restoring original clipping would help most folks. Removing it when needed is easy with PR now :)

@TahaTesser TahaTesser force-pushed the fix-snackbar-cliprect branch from 29e8f67 to 95cbb65 Compare February 18, 2022 13:15
@flutter-dashboard
Copy link

Golden file changes are available for triage from new commit, Click here to view.

For more guidance, visit Writing a golden file test for package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

Changes reported for pull request #98252 at sha 95cbb654559d580de9b7eb9433f6363948832b24

@TahaTesser TahaTesser requested a review from Piinks February 18, 2022 15:35
Copy link
Contributor

@Piinks Piinks left a comment

Choose a reason for hiding this comment

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

Approved golden files, LGTM

@fluttergithubbot
Copy link
Contributor

This pull request is not suitable for automatic merging in its current state.

  • The status or check suite Google testing has failed. Please fix the issues identified (or deflake) before re-applying this label.

engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Feb 27, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Feb 28, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Feb 28, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Feb 28, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Feb 28, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Feb 28, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Feb 28, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Feb 28, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Feb 28, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Feb 28, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Feb 28, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Feb 28, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 28, 2022
engine-flutter-autoroll added a commit to engine-flutter-autoroll/plugins that referenced this pull request Feb 28, 2022
clocksmith pushed a commit to clocksmith/flutter that referenced this pull request Mar 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. will affect goldens Changes to golden files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[stable 2.10+] Snackbar with a BackdropFilter blurs entire screen.

8 participants