I've managed to get the date from 18 years ago today:
var formatter = DateFormat('dd/MM/yyyy');
DateTime today = DateTime.now();
final eighteenY = DateTime(today.year - 18, today.month, today.day);
But now I need to check if the date a user enters is between that date and today's date, and if it is then they are not over the age of 18. How would I go about this? Here is my code:
MaskedTextController _maskDOBController =
MaskedTextController(mask: '00/00/0000');
@override
Widget build(BuildContext context) {
return Scaffold(
body:
return Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
Container(
height: 48,
width: 500,
child: TextFormField(
controller: _maskDOBController,
onChanged: (string){
setState(() {
provider.dobString = string;
dobError = false;
});
},
),
),
],
),
),
Container(height: 80),
Container(
GestureDetector(
onTap: (){
// if the date a user enters in textfield is between that date and today's date
// print('user is underage');
}
child: Text(
'Continue'
),
),
);