Skip to content

Conversation

@shihaohong
Copy link
Contributor

Description

Introduces two new parameters that allow the BoxConstraints of the InputDecoration's prefixIcon and suffixIcon to be modifiable. This is particularly useful when isDense is set to true, which allows the icon sizes to be smaller than 48x48px.

Example:

Sample Code:

class TestWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    const double customMinIconSize = 32;
    const BoxConstraints iconConstraints = BoxConstraints(
      minWidth: customMinIconSize,
      minHeight: customMinIconSize,
    );

    return TextField(
      decoration: InputDecoration(
        hintText: 'Test icon size',
        prefixIcon: Icon(Icons.search, size: 26),
        prefixIconConstraints: iconConstraints,
        suffixIcon: Icon(Icons.arrow_right, size: 26),
        suffixIconConstraints: iconConstraints,
        contentPadding: EdgeInsets.symmetric(vertical: 10.0),
        isDense: true,
      ),
    );
  }
}

Alternative considered

This seems to be a tad verbose to define the box constraints separately for prefix and suffix icons. It could simply be controlled by one parameter (ie. iconConstraints). That makes the constraints less flexible since both icons will share the same set of constraints, but if that seems like a more favorable API, please comment on the PR, but I decided to choose flexibility for now. Thanks!

Related Issues

Fixes #21908

Tests

I added the following tests:

  • A test to ensure that custom BoxConstraint values are respected

Checklist

Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes ([x]). This will ensure a smooth and quick review process.

  • I read the Contributor Guide and followed the process outlined there for submitting PRs.
  • I signed the CLA.
  • I read and followed the Flutter Style Guide, including Features we expect every widget to implement.
  • I read the Tree Hygiene wiki page, which explains my responsibilities.
  • I updated/added relevant documentation (doc comments with ///).
  • All existing and new tests are passing.
  • The analyzer (flutter analyze --flutter-repo) does not report any problems on my PR.
  • I am willing to follow-up on review comments in a timely manner.

Breaking Change

Did any tests fail when you ran them? Please read Handling breaking changes.

  • No, no existing tests failed, so this is not a breaking change.
  • Yes, this is a breaking change. If not, delete the remainder of this section.
    • I wrote a design doc: https://flutter.dev/go/template Replace this with a link to your design doc's short link
    • I got input from the developer relations team, specifically from: Replace with the names of who gave advice
    • I wrote a migration guide: Replace with a link to your migration guide

@shihaohong shihaohong added framework flutter/packages/flutter repository. See also f: labels. f: material design flutter/packages/flutter/material repository. labels Feb 3, 2020
@shihaohong shihaohong requested a review from HansMuller February 3, 2020 23:45
@shihaohong shihaohong added the c: new feature Nothing broken; request for a new capability label Feb 11, 2020
Copy link
Contributor

@gspencergoog gspencergoog left a comment

Choose a reason for hiding this comment

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

About the splitting into prefix and suffix: since everything else is split that way, I think it makes sense to also split it that way.

/// setting the constraints' minimum height and width to a value lower than
/// 48px.
///
/// ```dart
Copy link
Contributor

Choose a reason for hiding this comment

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

Ideally, this would be an actual {@tool dartpad ...} sample so that people could see it in action and play with it in the web page.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I decided to give it a whirl since I've never tried it :)

Copy link
Contributor Author

@shihaohong shihaohong Feb 14, 2020

Choose a reason for hiding this comment

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

Although I noticed that testing the new feature in a new DartPad instance didn't work because the parameters did not exist on whatever version of Flutter that DartPad uses (I'm guessing stable), so we'll have no guarantee that it'll work via the instructions in snippets/README.md

Copy link
Contributor

Choose a reason for hiding this comment

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

It will work once DartPad picks up the changes, which should happen in a couple of weeks or so.

@fluttergithubbot fluttergithubbot merged commit 89ff794 into flutter:master Feb 18, 2020
@shihaohong shihaohong deleted the input-decorator-icon-size branch April 3, 2020 19:06
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 31, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

c: new feature Nothing broken; request for a new capability 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.

48px by 48px padding around TextField's prefixIcon is restrictive

4 participants