customConvert method

  1. @override
String? customConvert(
  1. PropertyInfo propertyInfo
)

Implementation

@override
String? customConvert(PropertyInfo propertyInfo) {
  var name = propertyInfo.propertyName;
  var type = propertyInfo.propertyType;
  if (type.isDartCoreList && type is ParameterizedType) {
    var propertyType = type.typeArguments.first;
    if (propertyType is InterfaceType) {
      var code = _convertType('e', propertyType);
      if (code != null) {
        return '$name.map((e) => $code).toList()';
      }
    }
  } else if (type.isDartCoreMap && type is ParameterizedType) {
    var keyType = type.typeArguments.first;
    var valueType = type.typeArguments.last;
    var keyCode = null;
    if (keyType is InterfaceType) {
      keyCode = _convertType('key', keyType);
    }
    var valueCode = null;
    if (valueType is InterfaceType) {
      valueCode = _convertType('value', valueType);
    }
    if (keyCode != null || valueCode != null) {
      return '$name.map((key, value) => MapEntry(${keyCode ?? 'key'}, ${valueCode ?? 'value'}))';
    }
  } else if (type is InterfaceType) {
    return _convertType(name, type);
  }

  return null;
}