Calender Picker

final TextEditingController dateController = TextEditingController();

write this code inside onclick function

DateTime? pickedDate = await showDatePicker(

context: context,

initialDate: DateTime.now(), //get today's date

firstDate:DateTime(1800), //DateTime.now() - not to allow to choose before today.

lastDate: DateTime(2101)

);

if(pickedDate != null ){

print(pickedDate); //get the picked date in the format => 2022-07-04 00:00:00.000

String formattedDate = DateFormat('yyyy-MM-dd').format(pickedDate); // format date in required form here we use yyyy-MM-dd that means time is removed

print(formattedDate); //formatted date output using intl package => 2022-07-04

//You can format date as per your need


setState(() {

dateController.text = formattedDate.toString(); //set foratted date to TextField value.

});

}else{

print("Date is not selected");

}

Sign In or Register to comment.