I faced with the problem of validating text fields.
Here you need to enter the date in the format dd.mm.yyyy. I also use flutter_multi_formatter package for this form.
import 'package:flutter/material.dart';
import 'package:flutter_multi_formatter/formatters/masked_input_formatter.dart';
void main() => runApp(const MyApp());
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return const MaterialApp(home: StartPage());
}
}
class StartPage extends StatelessWidget {
const StartPage({super.key});
@override
Widget build(BuildContext context) {
return Scaffold(
body: Padding(
padding: const EdgeInsets.symmetric(vertical: 300, horizontal: 50),
child: TextFormField(
onChanged: (val) {},
keyboardType: TextInputType.number,
decoration: const InputDecoration(hintText: 'dd.mm.yyyy'),
inputFormatters: [MaskedInputFormatter('##.##.####')],
),
),
);
}
}
For example, user will start entering an incorrect date format: 32.13.2009. And I want the text with the error notification to appear below this form. Is it possible to add validation for this form if an incorrect date is entered? Maybe it’s good to parse the entered text and use conditions to compare numbers. I will be glad any help.
2
Answers
I suggest you look at Flutter Form Validation doc provided by flutter itself.
Example:
Try below code I have try using extension:
Extension:
UI: