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

prevent manual text input #7

Closed
andytwoods opened this issue Oct 16, 2018 · 7 comments
Closed

prevent manual text input #7

andytwoods opened this issue Oct 16, 2018 · 7 comments

Comments

@andytwoods
Copy link

Hi,
just wondering if it would be best to prevent people typing in dates by hand? Or having a little logic to disable this if wanted. The former is achievable by removing parent.controller.text.isEmpty && previousValue.isEmpty. Want a pull request?

cheers,
Andy.

void inputChanged() {
    if (//parent.controller.text.isEmpty &&
        //_previousValue.isEmpty &&
       parent.focusNode.hasFocus) {
      getDateTimeInput(context).then((date) {
        parent.focusNode.unfocus();
        setState(() {
          parent.controller.text = _toString(date, parent.format);
          setValue(date);
        });
      });
    } else if (parent.resetIcon != null &&
        parent.controller.text.isEmpty == showResetIcon) {
      setState(() => showResetIcon = !showResetIcon);
      // parent.focusNode.unfocus();
    }
    _previousValue = parent.controller.text;
    if (!parent.focusNode.hasFocus) {
      setValue(_toDate(parent.controller.text, parent.format));
    }
  }
@jifalops
Copy link
Owner

I'm on mobile so I can't check right now, but I have a strong suspicion removing those lines will have side effects. I'll look into adding an editable option.

@jifalops
Copy link
Owner

So I started implementing this but having a text field that is focusable but not editable isn't supported in the platform. The best option I could see was to override any changes to the text that were made manually, but then I realized instead of putting in an ugly hack, your use case shouldn't actually use this widget.

You should just use a Text or similar non-editable widget and use the platform's showDatePicker() and/or showTimePicker() when a user clicks on it.

@andytwoods
Copy link
Author

I guess this could be used: https://stackoverflow.com/questions/44490622/disable-a-text-edit-field-in-flutter. Would be a shame to create a new package just with this feature!

@jifalops
Copy link
Owner

Focus is currently how the input knows to show the picker dialog. I may be able to wrap it in a gesture detector. It may actually make some of the logic cleaner.

@andytwoods
Copy link
Author

I think you can just do node.unfocus() immediately before launching the date input function.

@noordawod
Copy link
Contributor

Added support for this in #8.

@jifalops
Copy link
Owner

jifalops commented Nov 2, 2018

Fixed in v0.1.5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants