Created
February 1, 2020 04:51
-
-
Save bharathraj-e/6578b23162686726b045dff8ee8c00c5 to your computer and use it in GitHub Desktop.
date picker and date to user readable string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
import 'package:intl/intl.dart'; | |
Future<DateTime> fetchDate(BuildContext context, | |
{DateTime initialDate, DateTime last}) async { | |
DateTime t = await showDatePicker( | |
context: context, | |
firstDate: DateTime(DateTime.now().year - 1), | |
initialDate: initialDate ?? DateTime.now(), | |
lastDate: last ?? DateTime(DateTime.now().year + 2), | |
); | |
return t; | |
} | |
String dateAsReadable(DateTime d, String f) { | |
//f ~ 'dd-MMM-yyyy' 'd-M-yyyy h:mm a' 'EEEE'//day | |
DateFormat formatter = new DateFormat(f); | |
return formatter.format(d); | |
} | |
DateTime optimizeDate(DateTime d) { | |
return DateTime(d.year, d.month, d.day); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment