convert method

  1. @override
Map<String, dynamic> convert(
  1. String input
)
override

Converts the input query string into a Map<String, dynamic>.

  • If the input is empty, returns an empty map.
  • Removes the leading '?' character if present.
  • Splits the query string by '&' to get individual key-value pairs.
  • Decodes each key and value using Uri.decodeComponent.
  • Parses the value into its appropriate type (int, double, bool, list, or string).

Implementation

@override
Map<String, dynamic> convert(String input) {
  if (input.isEmpty) return {};

  // Remove leading '?' if present
  final cleanQuery = input.startsWith('?') ? input.substring(1) : input;
  if (cleanQuery.isEmpty) return {};

  final result = <String, dynamic>{};

  for (final segment in cleanQuery.split('&')) {
    if (segment.isEmpty) continue;
    final parts = segment.split('=');
    if (parts.length != 2) continue; // malformed

    final key = Uri.decodeComponent(parts[0]);
    final value = Uri.decodeComponent(parts[1]);

    result[key] = _parseValue(value);
  }

  return result;
}