Skip to content
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

Feature request: Use controller with CardSettingsPhone #11

Closed
arthurgustin opened this issue Aug 15, 2018 · 7 comments
Closed

Feature request: Use controller with CardSettingsPhone #11

arthurgustin opened this issue Aug 15, 2018 · 7 comments
Assignees
Labels
enhancement New feature or request question Further information is requested wontfix This will not be worked on

Comments

@arthurgustin
Copy link
Contributor

My function creating a phone field is the following:

static Widget nullablePhoneFormField(TextEditingController controller, String label) {
     return CardSettingsPhone(
       label: label,
       controller: controller,
       validator: (val) {},
     );
   }

Here is the console output:

I/flutter (  618): ══╡ EXCEPTION CAUGHT BY WIDGETS LIBRARY ╞═══════════════════════════════════════════════════════════
I/flutter (  618): The following assertion was thrown building CardSettingsPhone(dirty):
I/flutter (  618): 'package:card_settings/widgets/text_fields/card_settings_text.dart': Failed assertion: line 55 pos
I/flutter (  618): 16: 'controller == null || inputMask == null': is not true.

A workaround is to instanciate my CardSettingsPhone like this:

static Widget nullablePhoneFormField(TextEditingController controller, String label) {
     return CardSettingsPhone(
       label: label,
       initialValue: controller.text == "" ? null : int.parse(controller.text),
       onChanged: (int intVal) {
         controller.text = intVal.toString();
       },
       onSaved: (int intVal) {
         controller.text = intVal.toString();
       },
       validator: (val) {},
     );
   }

But I don't really like it and sometimes the last characters are not updated and I don't understand why...

@codegrue
Copy link
Owner

codegrue commented Aug 15, 2018

This is because the CardSettingsPhone widget hard codes the phone mask string and sends that over to a CardSettingsText widget. That in turn uses a third part controller, MaskedTextController, to govern the formatting. Passing in your own controller would thus eliminate the ability for the phone widget to format the contexts as a phone number. The assert error is there to block this usage.

Off the top of my head I'm not sure what an elegant fix would be. Maybe it could be made to allow passing in your own MaskedTextController... Another fix would be to use the CardTextController instead and pass in your own MaskedTextController and an input string and you should be good to go. CardSettingPhone is just a shortcut to avoid this customization.

@codegrue codegrue added the enhancement New feature or request label Aug 15, 2018
@arthurgustin
Copy link
Contributor Author

Anyway, I have to store my phone number in String, not int because we can have +XX in Europe, I don't know about united states. For now I use a text field with a custom validator

@codegrue
Copy link
Owner

An optional country code is a nice idea to improve this. It would require a complete overhaul in how formatting works. What is the issue of it becoming an integer?

+1 (800) 555-1212 -> 18005551212
(800) 555-1212 -> 8005551212

@arthurgustin
Copy link
Contributor Author

arthurgustin commented Aug 16, 2018 via email

@codegrue codegrue changed the title Can not use controller with CardSettingsPhone Feature request: Use controller with CardSettingsPhone Oct 2, 2018
@rodydavis rodydavis added the question Further information is requested label Feb 15, 2019
@rodydavis rodydavis self-assigned this Feb 15, 2019
@rodydavis
Copy link
Collaborator

Is the workaround still working?

@arthurgustin
Copy link
Contributor Author

arthurgustin commented Feb 17, 2019 via email

@rodydavis rodydavis added wontfix This will not be worked on and removed waiting on customer labels Feb 19, 2019
@rodydavis
Copy link
Collaborator

Closing for now

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested wontfix This will not be worked on
Projects
None yet
Development

No branches or pull requests

3 participants