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

Remove date or set back to empty #15

Closed
JandalZaheer opened this issue May 24, 2021 · 5 comments
Closed

Remove date or set back to empty #15

JandalZaheer opened this issue May 24, 2021 · 5 comments

Comments

@JandalZaheer
Copy link

JandalZaheer commented May 24, 2021

Hi
You got very good plugin for date time, I am facing an issue after adding date to field there is no way to remove or set it back to empty field. please help me on this

@JandalZaheer JandalZaheer changed the title Remove date Remove date or set back to empty May 24, 2021
@GaspardMerten
Copy link
Owner

Hello @JandalZaheer, I am currently very busy. I will be able to fix that during the week of June 12. If you are in a rush you can create a pull request. I will make sure to review it as soon as you push it!

@GaspardMerten
Copy link
Owner

You can just set the date to null and call the setState method. Since this is not an issue, I will now close it.

@dsyrstad
Copy link

@JandalZaheer @GaspardMerten I added a "clear" button to the input decoration of the form field. To actually clear the date, you need to get a hold of the FormFieldState and call didChange(newValue) on it. For example:

  final _formFieldStateKey = GlobalKey<FormFieldState>();
  DateTime? myValue;

  //...

    DateTimeFormField(
          key: _formFieldStateKey,
          decoration: InputDecoration(
            suffixIcon: myValue == null
                ? Icon(Icons.event_outlined)
                : IconButton(
                    icon: const Icon(Icons.clear_outlined),
                    onPressed: () {
                      _formFieldStateKey.currentState!.didChange(null);
                     setState(() => myValue = null);
                    }),
          ),
          mode: _dateTimeModes[uiValueType]!,
          initialValue: widget.comparison.uiValue,
          onDateSelected: (value) {
            setState(() => myValue = value);
          },
          // ...
        );

@JandalZaheer
Copy link
Author

JandalZaheer commented Mar 29, 2022 via email

@Mmisiek
Copy link

Mmisiek commented Oct 2, 2022

Thanks for this solution ! Great plugin !

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

4 participants