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
Add enableFeedback param to MaterialButton, RawMaterialButton and IconButton #41972
Conversation
It looks like this pull request may not have tests. Please make sure to add tests before merging. If you need an exemption to this rule, contact Hixie. Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing. |
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here with What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
@googlebot I signed it! |
CLAs look good, thanks! ℹ️ Googlers: Go here for more info. |
Hi, this change looks good! Could you add a few tests to verify that the Thank you! |
How can i fix " Flutter build is currently broken" ? |
That isn't an issue with your PR, so there's nothing you need to do about it. That basically checks if Flutter's latest master is failing for whatever reason. This prevents new changes from being introduced if there is a potential existing issue in the codebase. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks pretty good! I have a request about adding an additional test case, and we should wait to see what Hans has to say about handling long presses with material buttons.
/// Whether detected gestures should provide acoustic and/or haptic feedback. | ||
/// | ||
/// For example, on Android a tap will produce a clicking sound and a | ||
/// long-press will produce a short vibration, when feedback is enabled. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems that RawMaterialButton
, MaterialButton
and IconButton
do not have an onLongPress
callback or option, which makes this inaccurate. We should either modify the docs to explain that long-press is not supported for these widgets, or implement them correctly.
@HansMuller What seems like the appropriate step here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Related to this issue somewhat, since it explains the default long press behavior for Material buttons and the intent to add an onLongPress
param: #40641
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed comment in doc about long-press
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think just removing it is the right approach -- I think if we take the route of not having it respond to long presses, we need to explain how this is different from what is expected. Let's wait for @HansMuller before we continue forward about this topic
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that #40641 will land pretty soon and so it's OK to explain that enableFeedback does what InkWell.enableFeedback does without qualification.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
/// Whether detected gestures should provide acoustic and/or haptic feedback. | ||
/// | ||
/// For example, on Android a tap will produce a clicking sound and a | ||
/// long-press will produce a short vibration, when feedback is enabled. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment regarding long-press
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed comment in doc about long-press
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commenting here that we've re-added the comment since long-press is now enabled on these buttons
@@ -1191,4 +1192,45 @@ void main() { | |||
final Material material = tester.widget<Material>(rawButtonMaterial); | |||
expect(material.color, const Color(0xff00ff00)); | |||
}); | |||
|
|||
group('feedback', () { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could you add a set of these tests for RawMaterialButton
as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
expect(feedback.hapticCount, 0); | ||
}); | ||
}); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: remove these two additional newlines
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
@@ -397,6 +398,56 @@ void main() { | |||
expect(focusNode1.hasPrimaryFocus, isTrue); | |||
expect(focusNode2.hasPrimaryFocus, isFalse); | |||
}); | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: remove one newline, since two were added
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
expect(feedback.hapticCount, 0); | ||
}); | ||
|
||
testWidgets('MaterialButton with enabled feedback', (WidgetTester tester) async { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This feels like it tests the default behavior (that enableFeedback
is set to true
by default). You should probably add a test where enableFeedback
is explicitly set to true
. ie.
await tester.pumpWidget(Directionality(
textDirection: TextDirection.ltr,
child: MaterialButton(
onPressed: () {},
enableFeedback: true, // add a test for this case
),
));
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
expect(feedback.hapticCount, 0); | ||
}); | ||
|
||
testWidgets('IconButton with enabled feedback', (WidgetTester tester) async { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment about testing for explicitly setting enableFeedback: true
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The rest of the changes look good, let's just wait to hear back about the long press detail :)
(iconSize + math.min(padding.horizontal, padding.vertical)) * 0.7, | ||
// x 0.5 for diameter -> radius and + 40% overflow derived from other Material apps. | ||
enableFeedback: enableFeedback, | ||
child: result, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One of the merges with master
cluttered up this section of code. It should be the original, adding the enableFeedback param.
/// Whether detected gestures should provide acoustic and/or haptic feedback. | ||
/// | ||
/// For example, on Android a tap will produce a clicking sound and a | ||
/// long-press will produce a short vibration, when feedback is enabled. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commenting here that we've re-added the comment since long-press is now enabled on these buttons
@NikitaZhelonkin do you have the bandwidth to finish up this PR? |
Yes, what I need to do? |
There are some failing pre-submit tests that need to be resolved. Also, there is a part of the code I commented on which was formatted incorrectly in one of the recent merges to master that needs to be fixed. |
}); | ||
|
||
group('feedback', () { | ||
FeedbackTester feedback; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@shihaohong Why did you remove those tests?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was causing a merge conflict since it's part of an ongoing effort to remove the buttons_test.dart
file. There are more specific files that some of these tests belong to (ie. flat_button_test.dart
), and it made more sense to have them there.
However, if I seem to have removed a test accidentally that wasn't intentional, please let me know (on looking at the files changed tab on GitHub, it seems like everything looks okay).
Hi, any updates on this PR? I just want to make sure we can get this one moving along since it's so close to the finish line! |
Fixed formatting; Seems some checks don't pass after merge master from origin repository |
It seems to be failing the following test:
|
@@ -10,6 +10,7 @@ import 'package:flutter_test/flutter_test.dart'; | |||
|
|||
import '../rendering/mock_canvas.dart'; | |||
import '../widgets/semantics_tester.dart'; | |||
import 'feedback_tester.dart'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove this line
Make sure to run
|
It shows '36816 issues found." if i run it locally |
Is there any more detail as to what the issues are? Make sure that you've run |
Co-Authored-By: Shi-Hao Hong <shihaohong@google.com>
Yes, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
…nButton (flutter#41972) * Wire enableFeedback parameter through MaterialButton, RawMaterialButton, and IconButton. Co-Authored-By: Shi-Hao Hong <shihaohong@google.com>
In some cases developers need to disable default tap feedback, e.g. if you want to implement custom feedback. This PR gives that opportunity