applyTextTransform function

dynamic applyTextTransform(
  1. dynamic value,
  2. String transform
)

Apply text transformation to a value

Applies text manipulation, encoding, or hashing operations to values. Handles both single values and lists uniformly.

Parameters

  • value - The value to transform (can be any type, will be converted to string)
  • transform - The transform type (see supported transforms below)

Returns

  • For single values: transformed string or null
  • For lists: list of transformed strings
  • For null input: null

Supported Transforms

  • 'upper' - Convert to uppercase
  • 'lower' - Convert to lowercase
  • 'base64' - Encode to Base64
  • 'base64decode' - Decode from Base64
  • 'reverse' - Reverse the string
  • 'md5' - Generate MD5 hash

Examples

applyTextTransform('hello', 'upper');  // 'HELLO'
applyTextTransform('Hello', 'base64');  // 'SGVsbG8='
applyTextTransform('SGVsbG8=', 'base64decode');  // 'Hello'
applyTextTransform('hello', 'reverse');  // 'olleh'
applyTextTransform('test', 'md5');  // '098f6bcd4621d373cade4e832627b4f6'
applyTextTransform(['a', 'b'], 'upper');  // ['A', 'B']
applyTextTransform(null, 'upper');  // null

Implementation

dynamic applyTextTransform(dynamic value, String transform) {
  if (value == null) return null;

  if (value is List) {
    return value.map((v) => _applyTextTransformSingle(v, transform)).toList();
  }

  return _applyTextTransformSingle(value, transform);
}