Skip to content

Conversation

@rkishan516
Copy link
Contributor

Gap between prefixIcon and input field was not compliant with M3 spec i.e. 16.0 rather it was 12.0
and similar situation was also happening with suffixIcon and input field.

Now with these changes, its compliant with M3 spec of input decoration.

Fixes #149408
Fixes #149409

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.

@github-actions github-actions bot added framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. labels Jul 20, 2024
@Piinks Piinks requested a review from justinmc July 24, 2024 18:21
@rkishan516 rkishan516 force-pushed the input-decorator-prefix-gap branch from 4af5c6b to a1db915 Compare July 25, 2024 02:33
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.

Thanks for attempting to fix this! Can you take a look at the test failures? Changes to InputDecorator's layout can be pretty finicky.

@rkishan516 rkishan516 force-pushed the input-decorator-prefix-gap branch from a1db915 to 4607e48 Compare July 26, 2024 02:23
@bleroux bleroux self-requested a review July 26, 2024 21:27
Copy link
Contributor

@bleroux bleroux 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 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):

image

@rkishan516
Copy link
Contributor Author

Sure @bleroux, Let me do the respective changes and notify once done.

@rkishan516 rkishan516 force-pushed the input-decorator-prefix-gap branch 4 times, most recently from a5c4864 to 01cb668 Compare August 2, 2024 02:13
@rkishan516
Copy link
Contributor Author

@bleroux I have made changes for TextDirection.rtl. Please have a look.

@rkishan516 rkishan516 force-pushed the input-decorator-prefix-gap branch from b003e2a to 171d27c Compare August 5, 2024 23:24
Copy link
Contributor

@bleroux bleroux 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 the last changes.
There were some missing tests related to RTL, can you add them? (see my review comments).

@rkishan516 rkishan516 force-pushed the input-decorator-prefix-gap branch from d2c2a3b to 2eb1559 Compare August 7, 2024 14:53
@rkishan516
Copy link
Contributor Author

Hey @bleroux, I have added both test you mentioned. But as you said, there are many more test related to TextDirection.rtl as pending, I feel I can cover few of them. Do you want me to continue on this PR or should I create a new one for those tests ?

@bleroux
Copy link
Contributor

bleroux commented Aug 7, 2024

Hey @bleroux, I have added both test you mentioned. But as you said, there are many more test related to TextDirection.rtl as pending, I feel I can cover few of them. Do you want me to continue on this PR or should I create a new one for those tests ?

@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).
Adding tests on a separate PR will make it possible to land them without waiting for this PR.

@rkishan516
Copy link
Contributor Author

@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). Adding tests on a separate PR will make it possible to land them without waiting for this PR.

Sure, I will create a new PR.

@bleroux
Copy link
Contributor

bleroux commented Aug 8, 2024

@rkishan516
Can you have a look at the test failures in step 'Linux framework_tests_libraries '?
You can get details on those failures in two different ways:

  • Follow the 'Details' link near that CI check, then tap the link 'View more details on flutter-dashboard' and then the link 'stdout[raw]'.
  • Running the whole framework test suite locally (go to flutter/packages/flutter directory and run 'flutter test').

@rkishan516
Copy link
Contributor Author

Sure @bleroux, I can fix them.

@rkishan516 rkishan516 force-pushed the input-decorator-prefix-gap branch 5 times, most recently from 97c4dab to 5def1a7 Compare August 12, 2024 02:42
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);
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 know why this line is not impacted?

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

Great 👍

@rkishan516 rkishan516 force-pushed the input-decorator-prefix-gap branch from 5def1a7 to 7998743 Compare August 12, 2024 14:25
Copy link
Contributor

@bleroux bleroux left a 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.

@rayliverified
Copy link

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.

@rkishan516
Copy link
Contributor Author

I think @bleroux or @justinmc can take a call on that because I think both are not possible together (either we can follow m3 spec or avoid clipping).

@bleroux
Copy link
Contributor

bleroux commented Oct 10, 2024

@rayliverified @rkishan516
This is an interesting point. It will more actionnable to discuss that on a separate issue.
Getting this PR merged as-is is already far from easy so let's keep this PR discussion focused on the main goal.

@rkishan516
Copy link
Contributor Author

Sure @bleroux, Then I will wait until google test are fixed. Once it's merged, we can create another issue.

@justinmc
Copy link
Contributor

@rayliverified Would you be able to create a separate issue with the information in #152069 (comment) and tag me?

@rayliverified
Copy link

Sure, the icon is also bugged where it doesn't respect any size configurations. You can't customize the size of the trailing icon.

@justinmc
Copy link
Contributor

@rkishan516 Can you fix the merge conflict here? I'm still working on figuring out how to land this.

@rkishan516 rkishan516 force-pushed the input-decorator-prefix-gap branch from dd13319 to d935cb8 Compare October 23, 2024 04:42
@justinmc justinmc merged commit c1b7740 into flutter:master Nov 5, 2024
73 checks passed
@justinmc
Copy link
Contributor

justinmc commented Nov 5, 2024

Thanks @rkishan516 for all your work here. Hopefully this will roll in smoothly but I'll be keeping an eye on it.

@rayliverified
Copy link

rayliverified commented Nov 5, 2024

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.

@justinmc
Copy link
Contributor

justinmc commented Nov 5, 2024

Thank you @rayliverified, no rush!

@rkishan516
Copy link
Contributor Author

No no, Thanks to all of you @justinmc and @bleroux and @rayliverified, Without guidance I couldn't have fetched this far.

engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Nov 6, 2024
auto-submit bot pushed a commit to flutter/packages that referenced this pull request Nov 6, 2024
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
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 12, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 13, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Feb 13, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 6, 2025
engine-flutter-autoroll added a commit to engine-flutter-autoroll/packages that referenced this pull request Mar 7, 2025
@rkishan516 rkishan516 deleted the input-decorator-prefix-gap branch July 26, 2025 05:46
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.

InputDecorator gap between suffixIcon and input field is not compliant InputDecorator gap between prefixIcon and input field is not compliant

5 participants