Skip to content

Conversation

@Michele-x98
Copy link

@Michele-x98 Michele-x98 commented May 19, 2022

Me, Daniele Cambi and Cosimo Tassone made this PR that allows to customize the errorText of an InputDecoration with an errorWidgetBuilder function that takes in input the errorText String that cames from InputDecoration, when it is not null, and allows to build a custom Widget for the error.
The default behavior doesn't change if the errorWidgetBuilder is not provided.

Without error widget builder:

Simulator-Screen-Shot-i-Phone-13-mini-2022-05-19-at-11-38-16

With custom errorWidgetBuilder:

Simulator-Screen-Shot-i-Phone-13-mini-2022-05-19-at-11-40-30

List which issues are fixed by this PR. You must list at least one issue.
Fixes #11068

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.
  • All existing and new tests are passing.

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

@flutter-dashboard flutter-dashboard bot added f: material design flutter/packages/flutter/material repository. framework flutter/packages/flutter repository. See also f: labels. labels May 19, 2022
@flutter-dashboard
Copy link

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 on the #hackers channel in Chat (don't just cc him here, he won't see it! He's on Discord!).

If you are not sure if you need tests, consider this rule of thumb: the purpose of a test is to make sure someone doesn't accidentally revert the fix. Ask yourself, is there anything in your PR that you feel it is important we not accidentally revert back to how it was before your fix?

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@google-cla
Copy link

google-cla bot commented May 19, 2022

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

For more information, open the CLA check for this pull request.

@Michele-x98 Michele-x98 changed the title fix11068 InputDecoration fix11068 InputDecoration 'errorText' custom builder May 19, 2022
@HansMuller HansMuller requested a review from justinmc May 20, 2022 21:56
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 the PR (+@dancamdev and @ctechdev)! I agree that people probably do want to be able to specify a widget for the error and not just text. Some points that I'm noticing:

  1. Did you run an autoformatter on the code? It looks like there are lots of unrelated changes. We don't use dart format on the Flutter framework code.
  2. We'll need at least one test for this.
  3. I wonder if a parameter of type Widget would be better than a builder function? Similar to label and labelText. Would that still work for you?
  4. Should helperText also have this kind of parameter?

@dancamdev
Copy link

Hi @justinmc, thanks for reviewing the code.

  1. Yes, we might have, is there a quick way to roll back?

  2. Sure, we'll figure what exactly should be tested, I'm not sure we can have widget tests within flutter itself, right?

  3. We'll have a look into it, I remember running into issues when trying to go that route, that's why we settled for a builder in the end.

  4. I think it does make sense to have it for helperText as well, we'll have a look into it.

@dancamdev
Copy link

@justinmc upon further analysis on the current error implementation on both TextField and TextFormField, which both use InputDecoration, we consider the builder approach the better one as it doesn't brake the form validation logic.

We're working on adding tests and helperWidgetBuilder

@HansMuller
Copy link
Contributor

HansMuller commented Jun 6, 2022

Specifying an errorWidget instead of errorText seems sufficient, since the developer needs to specify one or the other for InputDecoration and if we allow an errorWidget to be specified, some apps may choose to just show an icon (or whatever) rather than a text message.

This PR reformats InputDecorator.dart; it should not. Please only change as much of the existing code as is necessary to make your change.

Note also: tests for this new feature will be needed.

@justinmc
Copy link
Contributor

justinmc commented Jun 7, 2022

+1 to the above. I'm not sure if there's an easy way to rollback the formatter changes or not. For tests, take a look at input_decorator_test.dart or maybe text_field_test.dart.

@flutter-dashboard
Copy link

This pull request executed golden file tests, but it has not been updated in a while (20+ days). Test results from Gold expire after as many days, so this pull request will need to be updated with a fresh commit in order to get results from Gold.

For more guidance, visit Writing a golden file test for package:flutter.

Reviewers: Read the Tree Hygiene page and make sure this patch meets those guidelines before LGTMing.

@justinmc
Copy link
Contributor

@dancamdev @Michele-x98 Are you guys still available to finish this PR? Let me know if there's anything blocking you.

It looks like there is a merge conflict, but it's probably just due to the formatting changes in input_decorator.dart.

@justinmc justinmc added the waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds label Jun 27, 2022
@Michele-x98
Copy link
Author

@justinmc I removed the change due to autoformatting and added the errorWidget property as proposed, so it is not possible to define both errorText and errorWidget. The tests are missing for the moment, I have defined them but without implementing them at all.

@xvrh
Copy link
Contributor

xvrh commented Jul 1, 2022

I like the idea to customise the style of an error messages in TextFields.

But with a simple errorWidget, I don't understand how it work with the validator of TextField? Can we stylise those messages too?

Shouldn't the API be like: Widget Function(String errorMessage) errorBuilder as proposed initially?

@Michele-x98
Copy link
Author

@xvrh That's the point, you can't. Now with the simple errorWidget you can just add something under the field and it is permanently showed, without the builder you don't have access to the error message string if that is not null. In the previous version that i proposed, the builder method allow to take the message error in input and handle it as you want, but as @justinmc and @HansMuller said, that logic works only if the widget is "linked" to the errorText, and if the errorText is Null, the widget is never displayed.

@xvrh
Copy link
Contributor

xvrh commented Jul 1, 2022

@Michele-x98

that logic works only if the widget is "linked" to the errorText, and if the errorText is Null, the widget is never displayed.

Unless I'm missing something, this is the behaviour we want.

And if not, then we can also update the builder to be Widget? Function(String? errorMessage) errorBuilder. So the user of the API can really decide what to do with and without an error message.

@Michele-x98
Copy link
Author

@xvrh I follow this logic above:

Specifying an errorWidget instead of errorText seems sufficient, since the developer needs to specify one or the other for InputDecoration and if we allow an errorWidget to be specified, some apps may choose to just show an icon (or whatever) rather than a text message.

But i think that it also works as you propose as well, maybe the function could be Nullable and the return type Widget not?

Widget Function(String? errorMessage)? errorBuilder

This make more sense to me.
Let me know if it's ok

@cinder92
Copy link

any update on this?

@HansMuller
Copy link
Contributor

I'm closing this due to lack of activity. If you decide to resume working on it, please reopen the PR.

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. waiting for customer response The Flutter team cannot make further progress on this issue until the original reporter responds

Projects

None yet

Development

Successfully merging this pull request may close these issues.

InputDecorator 'errorText' should have 'textAlign' property

6 participants