philip-soft / cupertino_calendar_picker

MIT License
1 stars 0 forks source link

[Enhancement] Allow build components with builders #4

Open JCKodel opened 3 weeks ago

JCKodel commented 3 weeks ago

There is a (lot) of bugs in Flutter Cupertino widgets, but one affects this picker:

image

The code on CupertinoDatePicker is naïve at best (it gets the month column width by string length - problem is: Fevereiro has more chars than Novembro, but that m is way wider, so, pixel-wise, the word November is a lot large then Fevereiro.

Since the Flutter team would not fix it (or it will take ages to fix, as always), it would be awesome to provide some alternatives through a builder. For instance:

final newDate = await showCupertinoCalendarPicker(
  context,
  widgetRenderBox: renderBox,
  minimumDate: now.addYears(-5),
  maximumDate: now.addYears(5),
  currentDate: now,
  initialDate: _currentDate,
  dismissBehaviour: CalendarDismissBehavior.onOusideTapOrDateSelect,
  monthPickerBuilder: (context, minimumDate, maximumDate, onDateTimeChanged, initialDateTime) =>
    SomeComponent()
);

If monthPickerBuilder is null, you can use the current CupertinoDatePicker (line 218 of calendar_picker.dart), otherwise, this function is called and the SomeComponent() is returned.

The same could be applied for all components, such as the calendar and the calendar/month picker button.

philip-soft commented 3 weeks ago

I wouldn’t say that it is a good idea. The main purpose of the cupertino_calendar_picker package is to bring the SwiftUI calendar picker to Flutter (since Flutter has a wheel picker as an iOS-style version only). Therefore, there are no plans to make this component a constructor or builder for creating your own calendar from separate parts. That’s why the calendar allows full customization of the text styles and colors but doesn’t have parameters for paddings, icon widgets or animations, because in that case it might lose the original appearance of the SwiftUI version.

Here is how the SwiftUI version looks like:

swift_ui

If the Flutter month-year picker has some UI issues, I think the only thing I can do is bring this component from the cupertino library to my package, try to fix it and make it look the same as in SwiftUI.