Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Make the barrier panel on the Material Drawer non-dismissible #164810

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

Open
wants to merge 20 commits into
base: master
Choose a base branch
from

Conversation

romanejaquez
Copy link

@romanejaquez romanejaquez commented Mar 7, 2025

This PR entails making the modal barrier behind the Material Drawer dismissible / non-dismissible via a Scaffold flag named "drawerBarrierDismissible", as in:

Scaffold(
   drawerBarrierDismissible: false, // defaults to true so it behaves as normal
   ....
)

This is so as to force the Drawer to be opened / closed programmatically using either:

Scaffold.of(context).openEndDrawer() / openDrawer()

or

Scaffold.of(Utils.adminNav.currentContext!).closeDrawer() / closeEndDrawer()

and the user not closing the Drawer upon tapping on the modal barrier.

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].
  • I followed the [breaking change policy] and added [Data Driven Fixes] where supported.
  • All existing and new tests are passing.

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

@romanejaquez romanejaquez requested a review from matanlurey as a code owner March 7, 2025 19:56
@github-actions github-actions bot added framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. labels Mar 7, 2025
@dkwingsmt dkwingsmt self-requested a review March 19, 2025 18:21
// If set to false, prevents the barrier behind the [Drawer] from being dismissed.
// Defaults to true. The value of this flag also gets inherited by the parent Scaffold,
// or can be overridden if a [DrawerController] is extended and this value set accordingly.
final bool drawerDismissible;
Copy link
Contributor

Choose a reason for hiding this comment

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

I wonder why we call it drawerDismissible here instead of simply dismissible, since this is already known as a DrawerController. (I know some other properties are also prefixed with "drawer", which also appears weird to me.)

Copy link
Author

Choose a reason for hiding this comment

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

I'd totally be open to call it dismissible - I was just trying to keep the existing convention which I also thought it was a bit redundant but didn't want to have to change the rest if there was a purpose for it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it. Can you rename it to dismissible?

Copy link
Author

Choose a reason for hiding this comment

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

will do!

Comment on lines 1740 to 1742
/// If false, and a [drawer] is specified, then the barrier behind the drawer should not
/// respond to a tap event and thus remain open. The default behavior is to close upon the
/// user tapping on the barrier.
Copy link
Contributor

Choose a reason for hiding this comment

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

Same doc style guide problem as above.

Copy link
Contributor

Choose a reason for hiding this comment

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

+1, this should be split into 2 paragraphs so that the first paragraph is a single sentence, per the styleguide.

@@ -27,4 +27,109 @@ void main() {
await tester.pumpAndSettle();
expect(findHeadingLevelOnes, findsOne);
});

testWidgets('drawer is dismissible', (WidgetTester tester) async {
Copy link
Contributor

Choose a reason for hiding this comment

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

Unless it's intentional, test cases should reside in packages/flutter/test/material/drawer_test.dart, not a11y_assessments.

Copy link
Author

Choose a reason for hiding this comment

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

no, not intentional. I actually saw some of the other drawer tests there so I wanted to put them along with the rest, but these can easily be moved wherever is more appropriate.

romanejaquez and others added 2 commits April 4, 2025 14:31
…missible"; moved tests topackages/flutter/test/material/drawer_test.dart
@matanlurey matanlurey removed their request for review April 9, 2025 18:56
@dkwingsmt
Copy link
Contributor

Can you move the test to the unit test file? (packages/flutter/test/material/drawer_test.dart) Also there are some analyser issues.



   info • Missing a newline at the end of the file • dev/a11y_assessments/lib/use_cases/drawer.dart:80:2 • eol_at_end_of_file
   info • The value of the argument is redundant because it matches the default value • packages/flutter/test/material/drawer_test.dart:772:30 • avoid_redundant_argument_values
   info • Use 'const' with the constructor to improve performance • packages/flutter/test/material/drawer_test.dart:774:54 • prefer_const_constructors
   info • Use 'const' with the constructor to improve performance • packages/flutter/test/material/drawer_test.dart:776:22 • prefer_const_constructors
   info • Use 'const' with the constructor to improve performance • packages/flutter/test/material/drawer_test.dart:779:20 • prefer_const_constructors
   info • Use 'const' with the constructor to improve performance • packages/flutter/test/material/drawer_test.dart:785:20 • prefer_const_constructors
   info • Use 'const' with the constructor to improve performance • packages/flutter/test/material/drawer_test.dart:786:22 • prefer_const_constructors
   info • Missing type annotation • packages/flutter/test/material/drawer_test.dart:794:5 • always_specify_types
   info • Missing type annotation • packages/flutter/test/material/drawer_test.dart:823:5 • always_specify_types
   info • Missing type annotation • packages/flutter/test/material/drawer_test.dart:826:5 • always_specify_types
   info • Missing type annotation • packages/flutter/test/material/drawer_test.dart:830:5 • always_specify_types
   info • Use 'const' with the constructor to improve performance • packages/flutter/test/material/drawer_test.dart:830:32 • prefer_const_constructors
   info • Missing type annotation • packages/flutter/test/material/drawer_test.dart:831:5 • always_specify_types
   info • Use 'const' with the constructor to improve performance • packages/flutter/test/material/drawer_test.dart:850:54 • prefer_const_constructors
   info • Use 'const' with the constructor to improve performance • packages/flutter/test/material/drawer_test.dart:852:22 • prefer_const_constructors
   info • Use 'const' with the constructor to improve performance • packages/flutter/test/material/drawer_test.dart:855:20 • prefer_const_constructors
   info • Use 'const' with the constructor to improve performance • packages/flutter/test/material/drawer_test.dart:861:20 • prefer_const_constructors
   info • Use 'const' with the constructor to improve performance • packages/flutter/test/material/drawer_test.dart:862:22 • prefer_const_constructors
   info • Missing type annotation • packages/flutter/test/material/drawer_test.dart:870:5 • always_specify_types
   info • Missing type annotation • packages/flutter/test/material/drawer_test.dart:899:5 • always_specify_types
   info • Missing type annotation • packages/flutter/test/material/drawer_test.dart:902:5 • always_specify_types
   info • Missing type annotation • packages/flutter/test/material/drawer_test.dart:906:5 • always_specify_types
   info • Use 'const' with the constructor to improve performance • packages/flutter/test/material/drawer_test.dart:906:32 • prefer_const_constructors
   info • Missing type annotation • packages/flutter/test/material/drawer_test.dart:907:5 • always_specify_types

@dkwingsmt
Copy link
Contributor

One analyzer issue missing

   info � Missing a newline at the end of the file � packages/flutter/test/material/drawer_test.dart:1005:2 � eol_at_end_of_file

Copy link
Contributor

@dkwingsmt dkwingsmt left a comment

Choose a reason for hiding this comment

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

LGTM

Copy link
Contributor

@justinmc justinmc left a comment

Choose a reason for hiding this comment

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

Just a few small things here, and it looks like the analyzer is failing. Thank you for the PR!

Is there an issue for this by the way?

Comment on lines 1740 to 1742
/// If false, and a [drawer] is specified, then the barrier behind the drawer should not
/// respond to a tap event and thus remain open. The default behavior is to close upon the
/// user tapping on the barrier.
Copy link
Contributor

Choose a reason for hiding this comment

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

+1, this should be split into 2 paragraphs so that the first paragraph is a single sentence, per the styleguide.

),
);

// check the flag is set at the Scaffold level
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Capital letter at the start and period at the end, here and elsewhere.

Copy link
Author

Choose a reason for hiding this comment

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

Took care of the comments above. However for the comment on the scaffold.dart, for the first sentence I had to split it into 2 because it would exceed the max length on a comment line.
Fixed the punctuation and capitalization on the other comments - thank you for catching that.

@@ -851,3 +1003,5 @@ void main() {
});
});
}

Copy link
Contributor

Choose a reason for hiding this comment

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

Remove these newlines.

Copy link
Author

Choose a reason for hiding this comment

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

gotcha - addressed the newline issue on the drawer_test.dart, but for some reason the Linux analyzer keeps barking on the newline not being added.

@romanejaquez
Copy link
Author

Just a few small things here, and it looks like the analyzer is failing. Thank you for the PR!

Is there an issue for this by the way?

@dkwingsmt
Copy link
Contributor

The analyzer errors seem to be only format errors, which can be resolved by running dart format . under the packages/flutter directory.

@romanejaquez
Copy link
Author

The analyzer errors seem to be only format errors, which can be resolved by running dart format . under the packages/flutter directory.

will do 👍

@dkwingsmt dkwingsmt requested a review from justinmc April 23, 2025 22:24
@dkwingsmt
Copy link
Contributor

dkwingsmt commented May 1, 2025

Hi, the tree-status red check is not related to your PR, but actually that Flutter's CI being flaky. It will resolve with time.

I've requested @/justinmc for a secondary review. After a 2nd approval we can land this PR. You're not needed to do anything now (unless you want to tweak something, of course). :)

@romanejaquez
Copy link
Author

Hi, the tree-status red check is not related to your PR, but actually that Flutter's CI being flaky. It will resolve with time.

I've requested @/justinmc for a secondary review. After a 2nd approval we can land this PR.

Sweet! Yeah I noticed that it succeeds one time, then it fails the other - so i thought of kicking it off once again and try my luck. It'd be great for this to make it in. Thanks @dkwingsmt for your help!

Copy link
Contributor

@justinmc justinmc left a comment

Choose a reason for hiding this comment

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

LGTM with nits 👍

Comment on lines 1740 to 1741
/// If false, and a [drawer] is specified, then the barrier behind the drawer should not respond to a tap event and thus remain open.
/// The default behavior is to close upon the user tapping on the barrier.
Copy link
Contributor

Choose a reason for hiding this comment

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

There should be an empty line of /// in between these two.

Also, check the 80 character line limit.

@@ -339,6 +339,7 @@ class DrawerController extends StatefulWidget {
this.scrimColor,
this.edgeDragWidth,
this.enableOpenDragGesture = true,
this.dismissible = true,
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Maybe this should be called barrierDismissible or something like that to avoid people thinking that it means the drawer can not be closed at all? A bunch of routes like ModalRoute have barrierDismissible properties.

I'm happy to defer to you though @romanejaquez, if you think the current name is better then let's stick with it.

Copy link
Contributor

Choose a reason for hiding this comment

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

Similar naming in an in-flight PR: #166896

Copy link
Author

@romanejaquez romanejaquez May 1, 2025

Choose a reason for hiding this comment

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

so you suggest naming it "barrierDismissible"? I kinda like it more than "drawerDismissible" now. I think we can change it to "barrierDismissible" across the board. how about "drawerBarrierDismissible"? too long?

@@ -1708,6 +1708,7 @@ class Scaffold extends StatefulWidget {
this.primary = true,
this.drawerDragStartBehavior = DragStartBehavior.start,
this.extendBody = false,
this.drawerDismissible = true,
Copy link
Contributor

Choose a reason for hiding this comment

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

I guess this would become drawerBarrierDismissible if we went with that name from my other comment.

Copy link
Author

@romanejaquez romanejaquez May 1, 2025

Choose a reason for hiding this comment

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

I thought drawerDismissible was more descriptive when it is set via the Scaffold, to go along with the other related drawer-related properties. I don't mind making it dismissible on both sides if y'all are ok with it. However, after @justinmc comment, i feel like we should rename it to drawerBarrierDismissible. Would it be too long of a name?

final ScaffoldState state = tester.firstState(find.byType(Scaffold));
state.openEndDrawer();

await tester.pump();
Copy link
Contributor

Choose a reason for hiding this comment

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

Do you need this initial pump if you also pump a duration?

Copy link
Author

Choose a reason for hiding this comment

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

nah, removed it - must've been left over from my tests.

state.openEndDrawer();

await tester.pump();
await tester.pump(const Duration(seconds: 1));
Copy link
Contributor

Choose a reason for hiding this comment

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

Would this be more accurate as 246ms?

const Duration _kBaseSettleDuration = Duration(milliseconds: 246);

Copy link
Contributor

Choose a reason for hiding this comment

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

I might be dumb but why isn't this a pumpAndSettle?

Copy link
Author

Choose a reason for hiding this comment

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

replaced it with the pumpAndSettle and it worked as well, which I think is cleaner. I believe I was testing for the duration of the animation of the drawer, which was another PR that I had related to it. Will replace with the pumpAndSettle instead.


expect(find.byType(Drawer), findsExactly(1));

// Tap on the modal barrier.
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you mean to delete this comment?

Copy link
Author

Choose a reason for hiding this comment

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

yeah meant to remove that one. Will remove it.

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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants