GaspardMerten / date_field

Flutter DateField and DateFormField
Other
45 stars 32 forks source link

Support showing the picker via code #58

Closed galenwarren closed 3 months ago

galenwarren commented 7 months ago

It would be helpful to be able to show the picker via code instead of just via a tap. My particular use case is that I want to show a pop-up to get a date without requiring the user to see and tap on a field.

This could be done easily by changing _DateTimeFieldState to DateTimeFieldState and then exposing the _handleTap method, perhaps as showPicker. Then, one could pass in a GlobalKey<DateTimeFieldState> to an instance of DateTimeField and invoke it that way. For convenience, we could also make that method return the selected value.

I'd be happy to submit a PR for this if you're interested. Thanks.

torbenkeller commented 6 months ago

I don't think this is something the package should allow. It could cause bugs to open implementation details as _handleTap. Also I think it is not a good UX to open a dialog without tapping on the form field.

If you really need this, you can copy the widget code to your project and modify it to your needs. The License allows that

galenwarren commented 6 months ago

You don't think it would be viable UX where someone would click on a button and then be prompted to provide a date? Say, for example, a clocking in/out app for time management. Obviously, some sort of input event needs to occur to prompt the dialog to show but not sure why that only makes sense in terms of clicking on a form field as opposed to some other element.

I'm also not sure I'm following regarding exposing implementation details -- what would be exposed?

I'll use my fork if you're not interested in this enhancement, but I figured others might run into the same issue. Thanks.

torbenkeller commented 6 months ago

Sure, clicking a button and opening a dialog is a viable UX. But this package provides a widget that is supposed to be used as a form field. And opening the dialog that is filling the form field without tapping on the form field is not good UX in my opinion.

galenwarren commented 6 months ago

And opening the dialog that is filling the form field without tapping on the form field is not good UX in my opinion

Just to be clear, there would be no visible form field to tap on in this flow. Agreed that if there were a form field in view, it would be odd to bring the popup up through some other mechanism.

This library has a nice UI for date and time, better than others I tried -- it would be nice to use it in a broader range of circumstances. But, if that's not the way you want to go, that's fine.

GaspardMerten commented 5 months ago

@torbenkeller, it could be extract the "show date time picker" to a public method, it would lighten the field.dart file while offering a better separation of concerns...

Like this, the package could offer a showAdaptiveDateTimePicker method?

What do you think? (I will implement it myself, no worries ;)).

galenwarren commented 5 months ago

@GaspardMerten That would be perfect for my use case -- thanks!

GaspardMerten commented 3 months ago

@galenwarren, could you review the PR to see if it suits your needs?

galenwarren commented 3 months ago

@GaspardMerten Yes I will give it a look this week, thanks!

GaspardMerten commented 3 months ago

It has now been released in v5.2.0

galenwarren commented 3 months ago

@GaspardMerten Sorry it took me so long to take a look, I've been really busy. I just pulled down the latest and it works great! Thanks.

I was running Flutter 3.19 and it doesn't work in that environment, because of the renaming of MaterialState to WidgetState in the core flutter library (breaking change). Worked fine once I upgraded to 3.22. Just mentioning that in case anyone else runs into the same thing.

Again, thanks for adding this support! Really appreciate it.