如何修改CupertinoDatePicker使其仅显示年份和月份?
如何让CupertinoDatePicker仅显示年份和月份?

当前CupertinoDatePicker的日期格式为年、月、日,但我希望仅显示年份和月份,请问该如何实现?
我的现有代码:
SizedBox( width: 500, height: 250, child: CupertinoDatePicker( mode: CupertinoDatePickerMode.date, backgroundColor: Colors.black54, dateOrder: DatePickerDateOrder.ymd, onDateTimeChanged: (date) { print(date); }, ), ),
直接修改CupertinoDatePicker的mode参数为CupertinoDatePickerMode.monthYear即可实现仅显示年份和月份的效果,同时可以把dateOrder调整为DatePickerDateOrder.ym更贴合需求:
SizedBox( width: 500, height: 250, child: CupertinoDatePicker( mode: CupertinoDatePickerMode.monthYear, backgroundColor: Colors.black54, dateOrder: DatePickerDateOrder.ym, onDateTimeChanged: (date) { print(date); }, ), ),
这个模式下,选择器只会展示年份和月份的滚轮,完全符合需求。
内容的提问来源于stack exchange,提问作者无夜之星辰
相关产品推荐
相关产品推荐

