I'm trying to call the showDatePicker widget once an icon button is clicked, however when i call the onTap method get the following error:
The argument type 'Future' can't be assigned to the parameter type '() → void'.
Please find my code below:
showDatePicker code
DateTime selectedDate = DateTime.now();
Future<Null> _selectDate(BuildContext context) async {
final DateTime picked = await showDatePicker(
context: context,
initialDate: selectedDate,
firstDate: DateTime(2018, 1),
lastDate: DateTime(2101));
if (picked != null && picked != selectedDate)
setState(() {
selectedDate = picked;
});
}
IconButton code
IconButton(
icon: Icon(Icons.date_range),
onPressed: _selectDate(context)),
I'm using the StatefulWidget, please do let me know how to solve this issue. Thanks :)