代码如下:
String get birthdayWeekday {
if (birthday == null) return '';
final weekdaysCN = ['周一', '周二', '周三', '周四', '周五', '周六', '周日'];
final weekdaysEN = ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'];
final locale = Get.locale?.languageCode ?? 'en';
if (locale.startsWith('zh')) {
return weekdaysCN[birthday!.weekday - 1];
} else {
return weekdaysEN[birthday!.weekday - 1];
}
}
这样,当你调用birthdayWeekday的时候就可以根据当前自定义语言环境的星期