toDateTime function

DateTime? toDateTime(
  1. dynamic date
)

Implementation

DateTime? toDateTime(dynamic date){
  if(date == null) return null;
  if (date is String){
    List _type = date.split(' ');
    List _date = _type[0].split('/');
    List _time = _type[1].split(':');
    if(_time.length == 2) _time.add('0');
    return DateTime(int.parse(_date[0]),int.parse(_date[1]),int.parse(_date[2]),int.parse(_time[0]),int.parse(_time[1]), int.parse(_time[2]));
  }
  if(date is Timestamp) return date.toDate();
  if(date is int) return DateTime.fromMillisecondsSinceEpoch(date);
  return null;
}