bdlukaa / fluent_ui

Implements Microsoft's WinUI3 in Flutter.
https://bdlukaa.github.io/fluent_ui/
BSD 3-Clause "New" or "Revised" License
2.97k stars 464 forks source link

feat: [Picker] add `autoOpen` allow open panel auto when the widget is built #1112

Closed CorvusYe closed 2 months ago

CorvusYe commented 2 months ago

In some scenarios, we hope that time related forms will automatically pop up a panel when loaded to save the need for clicking again.

This PR affects DatePicker, TimePicker, and Picker

Pre-launch Checklist

bdlukaa commented 2 months ago

I'm not sure if I like the design of this. Instead, we should provide the developer an option to open the picker programmatically - using keys, maybe? What do you think?

CorvusYe commented 2 months ago

Thank you for your reply.

I have some questions that I would like to discuss with you. Does 'using keys' mean the following:

GlobalKey key = GlobalKey();
DatePicker(
  key: key,
  selected: v,
);
(key.currentState as dynamic).open();

If so, this calling method can indeed achieve the desired effect, but it seems more cumbersome. More encapsulation is needed to achieve parameter level logic control.

Moreover, _DatePickerState is private and can only be cast through "as dynamic" when we call the open method externally, it seems a bit strange.

I am not sure if my understanding is in line with popular thinking.

bdlukaa commented 2 months ago

autoOpen can lead to unexpected behavior by the user. If the widget is ever entirely rebuilt, the panel would open as well. I prefer to leave this kind of control to the developer.

Moreover, _DatePickerState is private and can only be cast through "as dynamic" when we call the open method externally, it seems a bit strange.

Ideally, we'd make the necessary changes to make the picker states public.

CorvusYe commented 2 months ago

autoOpen can lead to unexpected behavior by the user. If the widget is ever entirely rebuilt, the panel would open as well. I prefer to leave this kind of control to the developer.

You' re right. I overlooked this point.

From this point of view, it would indeed be better for users to decide for themselves.