GaspardMerten / date_field

Flutter DateField and DateFormField
Other
45 stars 32 forks source link

Remove date or set back to empty #15

Closed JandalZaheer closed 3 years ago

JandalZaheer commented 3 years ago

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

GaspardMerten commented 3 years ago

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 commented 3 years ago

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 commented 2 years ago

@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 commented 2 years ago

ok thanks for help, really appreciate.

On Wed, Sep 22, 2021 at 10:55 PM Gaspard Merten @.***> wrote:

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

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/GaspardMerten/date_field/issues/15#issuecomment-925152662, or unsubscribe https://github.com/notifications/unsubscribe-auth/AQEZL7CFYWXTIYTRAAHXBY3UDIKAZANCNFSM45M52KOA . Triage notifications on the go with GitHub Mobile for iOS https://apps.apple.com/app/apple-store/id1477376905?ct=notification-email&mt=8&pt=524675 or Android https://play.google.com/store/apps/details?id=com.github.android&referrer=utm_campaign%3Dnotification-email%26utm_medium%3Demail%26utm_source%3Dgithub.

Mmisiek commented 1 year ago

Thanks for this solution ! Great plugin !