Skip to content

Instantly share code, notes, and snippets.

@bharathraj-e
Created February 1, 2020 04:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bharathraj-e/6578b23162686726b045dff8ee8c00c5 to your computer and use it in GitHub Desktop.
Save bharathraj-e/6578b23162686726b045dff8ee8c00c5 to your computer and use it in GitHub Desktop.
date picker and date to user readable string
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