smartEncodeURIComponent static method
Smart URL encoder that ensures a string is encoded exactly once
Implementation
static String smartEncodeURIComponent(String string) {
if (string.isEmpty) return string;
// If it's already encoded, return as is
if (isEncoded(string)) {
debugPrint('URL already encoded, skipping encoding: $string');
return string;
}
// Otherwise, encode it with error handling
try {
final encoded = Uri.encodeComponent(string);
debugPrint('URL encoded from: $string to: $encoded');
return encoded;
} catch (error) {
debugPrint('URL encoding failed for: $string, returning original');
return string; // Fallback like iOS does
}
}