getVariableToMap method

String getVariableToMap(
  1. String key,
  2. dynamic value
)

Implementation

String getVariableToMap(String key, dynamic value) {
  final variable = key.camelCase;
  if (value is Map) {
    return '$variable?.toMap()';
  }
  if (value is List) {
    if (value.isNotEmpty) {
      if (value.first is Map) {
        return '$variable?.map((e) => e.toMap(),).toList()';
      }
    }
  }
  if (value is String) {
    if (RegExp(r'^\d{4}-\d{2}-\d{2}(\s|T)?(\d{2}:\d{2}(:\d{2})?)?(\.\d+)?Z?$')
        .hasMatch(value)) {
      return '$variable?$responseDateFormat';
    }
  }
  return variable;
}