我如何在Cupertino日期选择器中隐藏日期 [英] How can i hide day from cupertino date picker

查看:107
本文介绍了我如何在Cupertino日期选择器中隐藏日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只需要从日期选择器中显示年份和月份,所以我该如何从日期选择器中隐藏日期。

  CupertinoDatePicker(
initialDateTime:DateTime.now(),
onDateTimeChanged:(DateTime newdate){
print(newdate);
widget.card.expDateTime = newdate.toString();
dateCnt.text = newdate.toString()。split()[0];
},
最小年份:DateTime.now()。year,
最小日期:DateTime .now(),
模式:CupertinoDatePickerMode.date,


解决方案

我遇到了这个问题,尝试了软件包



希望它对某人有所帮助,并节省了我一直在寻找简单快速的解决方案的时间。


i need to pic only year and month from the date picker, so how can i hide day from date picker.

CupertinoDatePicker(
    initialDateTime: DateTime.now(),
    onDateTimeChanged: (DateTime newdate) {
        print(newdate);
        widget.card.expDateTime = newdate.toString();
         dateCnt.text = newdate.toString().split(" ")[0];
    },
    minimumYear: DateTime.now().year,
    minimumDate: DateTime.now(),
    mode: CupertinoDatePickerMode.date,
)

解决方案

I had this problem, tried the package flutter_cupertino_date_picker but it looks like it don't have the hability to format only month and year excluding day, so you need to program on it to extend the capabilities. To me seemed more logical to change the build in CupertinoDatePicker that comes with Flutter, what I did was copy all the content of '/Users/your_user_name/developer/flutter/packages/flutter/lib/src/cupertino/date_picker.dart' in another file in my local envirronment, I called cupertino_picker_extended.dart, then (because I wanted a quick way) on line 1182 I changed: Text(localizations.datePickerDayOfMonth(day),... for Text('',...

Then where you need to use the customed Picker call it like:

import 'package:local_app/ui/widgets/cupertino_picker_extended.dart' as CupertinoExtended;

and use it:

  CupertinoExtended.CupertinoDatePicker(
    onDateTimeChanged: (DateTime value) {
      setDate('${value.month}/${value.year}', setDateFunction,
          section, arrayPos);
    },
    initialDateTime: DateTime.now(),
    mode: CupertinoExtended.CupertinoDatePickerMode.date,
  ),

This is the result:

Hope it help someone and save the time I been looking for a easy and quick solution for my problem.

这篇关于我如何在Cupertino日期选择器中隐藏日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆