paramsWithInfo method

List<({ParamInfo info, String key, dynamic value})> paramsWithInfo(
  1. String uri
)

Extracts parameters with their type information from a URI.

Implementation

List<({String key, dynamic value, ParamInfo info})> paramsWithInfo(
  String uri,
) {
  final match =
      _uriPattern.firstMatch(uri) ?? _uriPattern.firstMatch("$uri/");
  if (match == null) return [];

  return _parameterPatterns.entries.map((entry) {
    final key = entry.key;
    final info = entry.value;
    final rawValue = match.namedGroup(key);
    // Handle null values based on parameter info
    if (rawValue == null && !info.isOptional) {
      return (key: key, value: null, info: ParamInfo(type: 'string'));
    }

    String? decodedValue;
    if (rawValue != null) {
      try {
        decodedValue = Uri.decodeComponent(rawValue);
      } catch (e) {
        // If decoding fails, use the raw value instead
        decodedValue = rawValue;
      }
    }

    return (
      key: key,
      value: _castParameter(decodedValue, info.type),
      info: info,
    );
  }).toList();
}