flutter datetime picker
a flutter date time picker inspired by flutter-cupertino-date-picker
you can choose date / time / date&time in multiple languages:
- albanian(sq)
- arabic(ar)
- armenian(hy)
- azerbaijan(az)
- basque(eu)
- bengali(bn)
- bulgarian(bg)
- catalan(cat)
- chinese(zh)
- danish(da)
- dutch(nl)
- english(en)
- french(fr)
- german(de)
- indonesian(id)
- italian(it)
- japanese(jp)
- kazakh(kk)
- korean(ko)
- persian(fa)
- polish (pl)
- portuguese(pt)
- russian(ru)
- spanish(es)
- swedish(sv)
- thai(th)
- turkish(tr)
- vietnamese(vi)
- khmer(kh)
and you can also custom your own picker content
date picker | time picker | date time picker |
---|---|---|
international:
date time picker (chinese) | date time picker (america) | date time picker (dutch) | date time picker (russian) |
---|---|---|---|
demo app
usage
textbutton(
onpressed: () {
datepicker.showdatepicker(context,
showtitleactions: true,
mintime: datetime(2018, 3, 5),
maxtime: datetime(2019, 6, 7), onchanged: (date) {
print('change $date');
}, onconfirm: (date) {
print('confirm $date');
}, currenttime: datetime.now(), locale: localetype.zh);
},
child: text(
'show date time picker (chinese)',
style: textstyle(color: colors.blue),
));
customize
if you want to customize your own style of date time picker, there is a class called commonpickermodel, every type of date time picker is extended from this class, you can refer to other picker model (eg. datepickermodel), and write your custom one, then pass this model to showpicker method, so that your own date time picker will appear, it’s easy, and will perfectly meet your demand
how to customize your own picker model:
class custompicker extends commonpickermodel {
string digits(int value, int length) {
return '$value'.padleft(length, "0");
}
custompicker({datetime currenttime, localetype locale}) : super(locale: locale) {
this.currenttime = currenttime ?? datetime.now();
this.setleftindex(this.currenttime.hour);
this.setmiddleindex(this.currenttime.minute);
this.setrightindex(this.currenttime.second);
}
@override
string leftstringatindex(int index) {
if (index >= 0 && index < 24) {
return this.digits(index, 2);
} else {
return null;
}
}
@override
string middlestringatindex(int index) {
if (index >= 0 && index < 60) {
return this.digits(index, 2);
} else {
return null;
}
}
@override
string rightstringatindex(int index) {
if (index >= 0 && index < 60) {
return this.digits(index, 2);
} else {
return null;
}
}
@override
string leftdivider() {
return "|";
}
@override
string rightdivider() {
return "|";
}
@override
list<int> layoutproportions() {
return [1, 2, 1];
}
@override
datetime finaltime() {
return currenttime.isutc
? datetime.utc(currenttime.year, currenttime.month, currenttime.day,
this.currentleftindex(), this.currentmiddleindex(), this.currentrightindex())
: datetime(currenttime.year, currenttime.month, currenttime.day, this.currentleftindex(),
this.currentmiddleindex(), this.currentrightindex());
}
}
getting started
for help getting started with flutter, view our online documentation.
for help on editing package code, view the documentation.
Comments are closed.