DateQuestion.fromJson constructor

DateQuestion.fromJson(
  1. Map<String, dynamic> json
)

Implementation

factory DateQuestion.fromJson(Map<String, dynamic> json) {
  // Handle migration from old format presets
  final dateFormatPresetValue = json['dateFormatPreset'] as String?;
  if (dateFormatPresetValue != null) {
    // Check if this is an old format with time included
    final timeVariants = [
      'isoDateTime',
      'europeanDateTime',
      'usDateTimeAmPm',
    ];

    if (timeVariants.contains(dateFormatPresetValue)) {
      // Migrate old time-inclusive format to new structure
      json['inputType'] = 'dateTime';

      // Set time format based on old preset
      if (dateFormatPresetValue == 'usDateTimeAmPm') {
        json['timeFormatPreset'] = 'h12';
      } else {
        json['timeFormatPreset'] = 'h24';
      }
    } else if (!json.containsKey('inputType')) {
      // Old date-only format without inputType field
      json['inputType'] = 'date';
    }
  }

  return _$DateQuestionFromJson(json);
}