parseValue method

dynamic parseValue(
  1. String rawValue
)

Parses a raw string value according to the parameter's type

Returns the parsed value as the appropriate Dart type:

  • boolean type: returns bool
  • int type: returns int (throws if invalid)
  • double type: returns double (throws if invalid)
  • string type: returns String (default)

Throws FormatException if parsing fails

Implementation

dynamic parseValue(String rawValue) {
  final effectiveType = type ?? 'string';

  switch (effectiveType) {
    case 'boolean':
      final lower = rawValue.toLowerCase();
      if (lower == 'true') return true;
      if (lower == 'false') return false;
      throw FormatException('Parameter "$name" expects a boolean value (true/false), got: "$rawValue"');

    case 'int':
      final value = int.tryParse(rawValue);
      if (value == null) {
        throw FormatException('Parameter "$name" expects an integer, got: "$rawValue"');
      }
      return value;

    case 'double':
      final value = double.tryParse(rawValue);
      if (value == null) {
        throw FormatException('Parameter "$name" expects a number, got: "$rawValue"');
      }
      return value;

    case 'string':
    default:
      return rawValue;
  }
}