-
Notifications
You must be signed in to change notification settings - Fork 29.7k
Fix: Gap between prefix and suffix icon and input field in input deco… #152069
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
Fix: Gap between prefix and suffix icon and input field in input deco… #152069
Conversation
4af5c6b to
a1db915
Compare
justinmc
left a comment
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.
Thanks for attempting to fix this! Can you take a look at the test failures? Changes to InputDecorator's layout can be pretty finicky.
a1db915 to
4607e48
Compare
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.
Thanks for working on this.
I’m ok with the approach (adding prefix/suffix gaps).
As Justin mentioned, be aware that it might be difficult to get this change landed because it will probably break some internal Google tests and maybe some customer tests.
Another difficulty is that InputDecoration test coverage is not perfect because the migration of the tests from Material 2 to Material 3 is still in progress (for instance there are missing tests for the RTL text direction).
See my comments on specific lines of the PR but I noticed that the rendering is wrong for RTL.
Here is a code sample that we can use to make this more visual
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
home: SafeArea(
child: Material(
child: Container(
color: const Color.fromARGB(255, 200, 206, 182),
padding: const EdgeInsets.all(8.0),
child: const Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(height: 10),
IconsMetrics(),
SizedBox(height: 4),
InputDecoratorWithIcons(
textDirection: TextDirection.ltr,
),
SizedBox(height: 16),
FloatingLabelMetrics(),
SizedBox(height: 4),
InputDecoratorWithIcons(
textDirection: TextDirection.ltr,
labelText: 'Label text',
),
SizedBox(height: 30),
IconsMetrics(),
SizedBox(height: 4),
InputDecoratorWithIcons(
textDirection: TextDirection.rtl,
),
SizedBox(height: 16),
FloatingLabelMetrics(),
SizedBox(height: 4),
InputDecoratorWithIcons(
textDirection: TextDirection.rtl,
labelText: 'Label text',
),
],
),
),
),
),
);
}
}
class InputDecoratorWithIcons extends StatelessWidget {
const InputDecoratorWithIcons({super.key, required this.textDirection, this.labelText});
final TextDirection textDirection;
final String? labelText;
@override
Widget build(BuildContext context) {
return Directionality(
textDirection: textDirection,
child: SizedBox(
width: 200,
child: InputDecorator(
isEmpty: false,
isFocused: false,
decoration: InputDecoration(
labelText: labelText,
prefixIcon: const Icon(Icons.search),
suffixIcon: const Icon(Icons.cancel),
filled: true,
border: const OutlineInputBorder(),
),
child: Container(
width: 200, // Too long but will be cut.
height: 24, // Simulate default font height.
color: Colors.blueGrey,
child: Center(
child: Text(
textDirection == TextDirection.rtl ? 'RTL' : 'LTR',
style: const TextStyle(color: Colors.white, fontWeight: FontWeight.bold),
),
),
),
),
),
);
}
}
class IconsMetrics extends StatelessWidget {
const IconsMetrics({super.key});
@override
Widget build(BuildContext context) {
return SizedBox(
height: 12,
child: Row(
children: [
// Based on https://m3.material.io/components/text-fields/specs#1ad2798c-ab41-4f0c-9a97-295ab9b37f33.
Container(color: Colors.purple, width: 12),
Container(color: Colors.white, width: 24),
Container(color: Colors.purple, width: 16),
Container(color: Colors.blueGrey, width: 96), // 200 - 52 - 52
Container(color: Colors.purple, width: 16),
Container(color: Colors.white, width: 24),
Container(color: Colors.purple, width: 12),
],
),
);
}
}
class FloatingLabelMetrics extends StatelessWidget {
const FloatingLabelMetrics({super.key});
@override
Widget build(BuildContext context) {
return SizedBox(
height: 12,
child: Row(
children: [
// Based on https://m3.material.io/components/text-fields/specs#1ad2798c-ab41-4f0c-9a97-295ab9b37f33.
Container(color: Colors.red, width: 12 + 4), // 16
Container(color: Colors.white, width: 168), // 200 - 16 - 16
Container(color: Colors.red, width: 12 + 4), // 16
],
),
);
}
}
See the following screenshot where I added red arrows to point out to two problems with the rendering in RTL direction
(the colored lines above the decorations are based on the expected padding from the M3 spec):
|
Sure @bleroux, Let me do the respective changes and notify once done. |
a5c4864 to
01cb668
Compare
|
@bleroux I have made changes for |
b003e2a to
171d27c
Compare
bleroux
left a comment
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.
Thanks for the last changes.
There were some missing tests related to RTL, can you add them? (see my review comments).
d2c2a3b to
2eb1559
Compare
|
Hey @bleroux, I have added both test you mentioned. But as you said, there are many more test related to |
@rkishan516 It would be better to add other tests on a new PR because we don't know if this one will be merged (it could be blocked on Google internal testing or being reverted after being merged due to an internal customer having an issue with it). |
Sure, I will create a new PR. |
|
@rkishan516
|
|
Sure @bleroux, I can fix them. |
97c4dab to
5def1a7
Compare
| expect(tester.getTopLeft(find.text('Hint')).dx, 52.0); | ||
|
|
||
| // By default, the text of item 0 should be aligned with the text of the text field. | ||
| expect(tester.getTopLeft(find.text('Item 0').last).dx, 48.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.
Do you know why this line is not impacted?
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.
Oh, weird. I don't know. But let me check.
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 happening because I forgot to add padding when leading icon is not there. I have fixed and pushed the change.
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.
Great 👍
5def1a7 to
7998743
Compare
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! Thanks for keeping up on this PR.
Let me approve the PR and see how it goes with the 'Google testing' CI check.
|
Amazing, thank you! What would the decision be because the clipping is what happens if you follow the material specs exactly (default 0 padding). Adding 4 padding would fix the clipping, but not follow the materials specs. |
|
@rayliverified @rkishan516 |
|
Sure @bleroux, Then I will wait until google test are fixed. Once it's merged, we can create another issue. |
|
@rayliverified Would you be able to create a separate issue with the information in #152069 (comment) and tag me? |
|
Sure, the icon is also bugged where it doesn't respect any size configurations. You can't customize the size of the trailing icon. |
|
@rkishan516 Can you fix the merge conflict here? I'm still working on figuring out how to land this. |
dd13319 to
d935cb8
Compare
|
Thanks @rkishan516 for all your work here. Hopefully this will roll in smoothly but I'll be keeping an eye on it. |
|
Amazing work @rkishan516 👏 👏 Thanks for letting me jump in and distract you. I appreciate your professionalism in humoring me. I do have a TODO to open a separate issue with what I raised. |
|
Thank you @rayliverified, no rush! |
|
No no, Thanks to all of you @justinmc and @bleroux and @rayliverified, Without guidance I couldn't have fetched this far. |
flutter/flutter@29d40f7...73546b3 2024-11-06 [email protected] Add test for `image.loading_builder.0.dart` (flutter/flutter#158248) 2024-11-06 [email protected] Make flutter_tools use newest package:{native_assets_builder,native_assets_cli,native_toolchain_c} (flutter/flutter#158214) 2024-11-06 [email protected] Fix RawScrollbar examples and desktop test (flutter/flutter#158237) 2024-11-06 [email protected] Cleanup MenuAnchor and Improve DropdownMenu tests readability (flutter/flutter#158175) 2024-11-06 [email protected] Roll Flutter Engine from a3741d6248b7 to f03f11300a9d (2 revisions) (flutter/flutter#158222) 2024-11-06 [email protected] Update error message for Cocoapods support for synchronized groups/folders (flutter/flutter#158206) 2024-11-06 [email protected] Restore skipped iOS test by looping over `FakeAsync` elapse. (flutter/flutter#158204) 2024-11-06 [email protected] fix: ensure draggable_scrollable_sheet respects shouldCloseOnMinExten� (flutter/flutter#156338) 2024-11-06 [email protected] Roll Flutter Engine from e5e06c97c33c to a3741d6248b7 (14 revisions) (flutter/flutter#158218) 2024-11-06 [email protected] Forward fix `CupertinoDynamicColor` by adding `toARGB32()`. (flutter/flutter#158145) 2024-11-05 [email protected] Remove unused `enableObservatory` flag. (flutter/flutter#158202) 2024-11-05 [email protected] Remove observatory related TODO that is already fixed. (flutter/flutter#158205) 2024-11-05 [email protected] Factor out "shaker" class (flutter/flutter#157748) 2024-11-05 [email protected] Marks Mac_benchmark animated_complex_opacity_perf_macos__e2e_summary to be flaky (flutter/flutter#157424) 2024-11-05 [email protected] Increase subsharding for `Linux tool_integration_tests` (flutter/flutter#158196) 2024-11-05 [email protected] Add test for `raw_scrollbar.2.dart` (flutter/flutter#158161) 2024-11-05 [email protected] use root directory as the default for rootOverride in Cache.test constructor (flutter/flutter#158201) 2024-11-05 [email protected] Kill interactive script job `xcdevice observe` processes on tool/daemon shutdown (flutter/flutter#157646) 2024-11-05 [email protected] Fix: Gap between prefix and suffix icon and input field in input deco� (flutter/flutter#152069) 2024-11-05 [email protected] Roll Flutter Engine from f56401062e42 to e5e06c97c33c (1 revision) (flutter/flutter#158194) If this roll has caused a breakage, revert this CL and stop the roller using the controls here: https://autoroll.skia.org/r/flutter-packages Please CC [email protected],[email protected] on the revert to ensure that a human is aware of the problem. To file a bug in Packages: https://github.com/flutter/flutter/issues/new/choose To report a problem with the AutoRoller itself, please file a bug: https://issues.skia.org/issues/new?component=1389291&template=1850622 Documentation for the AutoRoller is here: https://skia.googlesource.com/buildbot/+doc/main/autoroll/README.md

Gap between
prefixIconandinputfield was not compliant with M3 spec i.e. 16.0 rather it was 12.0and similar situation was also happening with
suffixIconandinputfield.Now with these changes, its compliant with M3 spec of input decoration.
Fixes #149408
Fixes #149409
Pre-launch Checklist
///).