getFromMap method

String getFromMap({
  1. required String columnName,
  2. required String type,
  3. required bool isRequired,
})

Implementation

String getFromMap({
  required String columnName,
  required String type,
  required bool isRequired,
}) {
  String value =
      "map['${columnName.snakeCase}']${isRequired ? ' ?? ${getDefaultType(type)}' : ''}";
  if (type == 'int') {
    value =
        "int.tryParse(map['${columnName.snakeCase}']?.toString() ?? '') ${isRequired ? ' ?? ${getDefaultType(type)}' : ''}";
  } else if (type == 'double') {
    value =
        "double.tryParse(map['${columnName.snakeCase}']?.toString() ?? '') ${isRequired ? ' ?? ${getDefaultType(type)}' : ''}";
  } else if (type == 'bool') {
    value = "map['${columnName.snakeCase}'] == 1";
  }
  return "${columnName.camelCase}:  $value,";
}