setValue method

void setValue(
  1. DateTime? result,
  2. TimeOfDay? timeResult,
  3. String? format, {
  4. DateTime? secondResult,
})

Implementation

void setValue(DateTime? result, TimeOfDay? timeResult, String? format,
    {DateTime? secondResult}) {
  DateTime now = DateTime.now();

  //return result based on type and format

  if (type == "date" || type == "year" || type == "range") {
    try {
      if (secondResult != null) {
        value = "${DateFormat(format).format(result!)} - ${DateFormat(format).format(secondResult)}";
      } else {
        value = DateFormat(format, 'en_US').format(result!);
      }
    } on FormatException catch(e) {
      Log().debug('${e}FORMATTING ERROR!!!!!');
    }
  } else if (type == "time") {
    if (format == 'yMd') format= 'H:m';
    try {
      value = DateFormat(format).format(DateTime(now.year, now.month,
              now.day, timeResult!.hour, timeResult.minute));
    } on FormatException catch(e) {
      Log().debug('${e}FORMATTING ERROR!!!!!');
      value = '';
    }
  } else {
    if (format == 'yMd') {format= 'y/M/d H:mm'; this.format = "y/M/d H:mm";}
    try {
      value = DateFormat(format).format(DateTime(result!.year, result.month,
              result.day, timeResult!.hour, timeResult.minute));
    } on FormatException catch(e) {
      Log().debug('${e}FORMATTING ERROR!!!!!');
      value = '';
    }
  }
  onChange(context);
}