vanshg395 / intl_phone_field

A customised Flutter TextFormField to input international phone number along with country code.
https://pub.dev/packages/intl_phone_field
MIT License
177 stars 506 forks source link

Added validates bool parameter to onChanged callback #286

Closed jimmyff closed 11 months ago

jimmyff commented 1 year ago

There is currently no easy way to update a client app state based on if a number validates. In this PR I've exposed the validation result to the app by adding a validates parameter to the onChanged callback:

 onChanged: (PhoneNumber phone, bool validates) {
   print('${phone.completeNumber} (validates: $validates)');
 }
jimmyff commented 1 year ago

Hey @marcaureln - whenever is convenient could you take a look at this and let me know what you think? It's a breaking change but I think the functionality it provides is worth it.

jimmyff commented 1 year ago

hey @vanshg395 @marcaureln - Are you interested in this PR, if so I will resolve the conflicts. Thanks

jimmyff commented 1 year ago

Hey, any chance of looking at this PR @vanshg395 or @marcaureln

I'm using this in a popular production app and fixing issues as I find them.

marcaureln commented 1 year ago

Hey @jimmyff, I'll do my best to find an hour or two in the coming days to merge/triage PRs. Hold tight and thank you for using the package!

marcaureln commented 1 year ago

Hey @jimmyff, I review your PR, I have no doubt that this feature would be interesting, but it doesn't have to be a breaking change. Can you make the validates optional?

jimmyff commented 1 year ago

Hey @marcaureln sorry for the late reply on this. Somehow this notification slipped through the net. The validates is a bool parameter that is included when the library invokes the users onChanged function. As a result people would need to update their onChanged declarations to account for this additional parameter -even if they just did something like:

onChanged: (phone, _) {

I can't think of a way of making it optional unless i'm missing something obvious -which is very possible as it's been a long day!

The reason I added this feature was I had no way to update the UI in real-time as the user entered their number to indicate if it is valid or not. If there is an alternative way to achieve this I'm happy to adopt that method and move all my other countries.dart fixes in to a different PR?

marcaureln commented 1 year ago

Hey @jimmyff, thanks a lot for the work you are pushing in here, and sorry for the late answer. I come across a solution for your PR. I made a new branch next for all breaking changes. Your PR with the validates boolean should target the latter. And don't forget to update the changelog too. It'll make breaking changes easier to merge now.

And, I saw you add a whole new dependency. Kinda like the idea, but it should be another PR on its own. Where we can discuss the pros and cons. Also, the new PR should target the next branch (I think :thinking:)

marcaureln commented 1 year ago

@all-contributors please add @jimmyff for code

allcontributors[bot] commented 1 year ago

@marcaureln

I've put up a pull request to add @jimmyff! :tada:

github-actions[bot] commented 1 year ago

This PR has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs within the next 30 days. If you believe this PR is still relevant, please comment to keep it open. Thank you for your contributions.