Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flutter DatePicker without day

Is it possible have a YEAR-MONTH picker with only the month and the year with the current showDatePicker without using third-party PLUGINS!!

Note: As a result the day selection layout should not be visible.

like image 941
Jorge Vieira Avatar asked Dec 12 '18 18:12

Jorge Vieira


People also ask

How do you date pickers in flutter?

DatePicker is a material widget in a flutter that lets the user select a date. Since there is no widget available for creating a date picker we will use showDatePicker() function. It will display a Material Design date picker in a dialog by calling flutter's inbuilt function.


2 Answers

Use flutter_datetime_picker with custom model which disables the last column

class CustomMonthPicker extends DatePickerModel {
  CustomMonthPicker({DateTime currentTime, DateTime minTime, DateTime maxTime,
    LocaleType locale}) : super(locale: locale, minTime: minTime, maxTime:
  maxTime, currentTime: currentTime);

  @override
  List<int> layoutProportions() {
    return [1, 1, 0];
  }
}

and show the picker with custom model

DatePicker.showPicker(context,
  ...
  pickerModel: CustomMonthPicker(
    minTime: DateTime(2020, 1, 1),
    maxTime: DateTime.now(),
    currentTime: DateTime.now()
  )
  ...
)

enter image description here

like image 85
Abdutahir Avatar answered Oct 20 '22 05:10

Abdutahir


The stock pickers do not allow to have month and year only.

You could use the month_picker_dialog package available in the pub page by Dimitri Krivoj.

enter image description here

like image 15
chemamolins Avatar answered Oct 20 '22 03:10

chemamolins