'how to change the way DatePicker shows Date
I want to change the way DatePicker shows the Date, so that it shows
day/month/year. As of right now it shows in the format of year/month/day and I'm not sure on how to change this. I've been searching a lot but couldn't find the right way to do this.
I will show my code below, hopefully someone can help me :D
Thank you in Advance guys.
class WFDatePickerField extends DateTimeField {
final bool? hasError;
final bool hasErrorDecoration;
final double? errorHeight;
final dynamic error;
final DateTimeValue value;
final TextStyle? errorStyle;
WFDatePickerField(
{Key? key,
required this.value,
required String labelText,
String hintText = '',
TextEditingController? controller,
FormFieldValidator<DateTime>? validator,
FloatingLabelBehavior? floatingLabelBehavior =
FloatingLabelBehavior.never,
String format = 'dd.MM.yyyy',
final InputDecoration? decoration,
this.errorStyle,
this.hasError,
this.hasErrorDecoration=false,
this.error,
this.errorHeight})
: super(
key: key,
decoration: ErrorDecorationSelector(hasError, hasErrorDecoration, errorHeight, error, value, errorStyle).getDecoration(),
readOnly: true,
style: AppTheme()
.textStyles
.bodyText1!
.copyWith(color: Colors.white.withOpacity(0.5)),
initialValue: value.value,
format: DateFormat('dd/MM/yyyy'),
controller: controller,
validator: validator,
onShowPicker: (context, currentValue) async {
DateTime? newDate;
String? deviceLocale = await (Devicelocale.currentLocale);
LocaleType locale =
deviceLocale != null && deviceLocale.contains('de')
? LocaleType.de
: LocaleType.en;
await DatePicker.showDatePicker(context,
minTime: DateTime(1900, 1, 1),
maxTime: DateTime(DateTime.now().year - 18,
DateTime.now().month, DateTime.now().day),
locale: locale,
onConfirm: (date) => newDate = date);
return newDate;
},
onChanged: (newValue) {
value.value = newValue;
},
);
}
Solution 1:[1]
if I'M not mistaken your trying to format the date if that is what you're asking [enter link description here][1]
// Use this link it is flutter intl dateFormater it has different style [1]: https://pub.dev/packages/intl
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Suretion |

