genSpecifyTime method Null safety

String genSpecifyTime(
  1. {String? prefix = '',
  2. String? ext = '',
  3. String? seperator = '-',
  4. required DateTime? time}
)

generate now file name

Implementation

static String genSpecifyTime({
  String? prefix: '',
  String? ext: '',
  String? seperator: '-',
  required DateTime? time,
}) {
  // final now = DateTime.now();
  final now = time == null ? DateTime.now() : time;

  final y = now.year.toString().padLeft(4, '0');
  final m = now.month.toString().padLeft(2, '0');
  final d = now.day.toString().padLeft(2, '0');
  final h = now.hour.toString().padLeft(2, '0');
  final mi = now.minute.toString().padLeft(2, '0');
  final s = now.second.toString().padLeft(2, '0');
  final ml = now.millisecond.toString().padLeft(3, '0');
  final mc = now.microsecond.toString().padLeft(3, '0');

  final p = prefix ?? '';
  final e = ext ?? '';
  final sp = seperator ?? '';
  return p + y + m + d + sp + h + mi + s + sp + ml + sp + mc + e;
}