I have created two text fields named starrt date and end date which should accept dates in the format yyyy/mm/dd only.Right now user can input it in any format.How can set validations for the user to input the date in yyyy/mm/dd.
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Flexible(
child: Padding(
padding: const EdgeInsets.all(3.0),
child: TxtField(
fillColor: Cultured,
labelText: 'Start Date',
hintText: '2022-01-10',
onChanged: (value) => context
.read<CareRequirementsScreenBloc>()
.add(StartDateChanged(value)),
),
),
),
Flexible(
child: Padding(
padding: const EdgeInsets.all(3.0),
child: TxtField(
fillColor: Cultured,
labelText: 'End Date',
hintText: '2022-01-10',
onChanged: (value) => context
.read<CareRequirementsScreenBloc>()
.add(EndDateChanged(value)),
),
),
),
],
),
Here TxtField is a custom text field I have created using TextFormField
Make
DatePicker
instead of keyboard to ensure a proper format.