基本上,我有一个CupertinoDatePicker小部件,最大日期设置为第二天,即now.day+1
显示日,月和日,即Web, Feb 17
如何自定义要显示的文本Tomorrow
。
这就是我要重现的
这就是我目前所拥有的
以下是Cupertino日期选择器小部件的代码
final now = DateTime.now();
CupertinoDatePicker(
initialDateTime: now,
onDateTimeChanged: (DateTime newdate) {
print(newdate);
},
use24hFormat: true,
maximumDate: DateTime(now.year, now.month, now.day + 2),
minimumDate: now,
// minuteInterval: 1,
mode: CupertinoDatePickerMode.dateAndTime,
)
是的,您必须复制并修改库代码才能执行此操作。
看起来这是在_buildMediumDatePicker
库代码的方法中设置的。您可以通过IDE中的快捷方式来查看源代码来找到它。
final String dateText = rangeStart == DateTime(now.year, now.month, now.day)
? localizations.todayLabel
: localizations.datePickerMediumDate(rangeStart);
return itemPositioningBuilder(
context,
Text(dateText, style: _themeTextStyle(context)),
);
},
因此,您可以将代码从date_picker.dart
库文件复制到项目中,将其重命名(通过重构)为本地代码中的CupertinoDatePicker
类似名称MyCupertinoDatePicker
。您必须在该文件中重命名几个其他对象以清除错误。
然后修改该部分
final String dateText =
rangeStart == DateTime(now.year, now.month, now.day)
? localizations.todayLabel
: rangeStart == DateTime(now.year, now.month, now.day + 1)
? 'Tomorrow'
: localizations.datePickerMediumDate(rangeStart);
我只是尝试过,它有效。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句