Decode URL/URI from string in Flutter Dart via extending String
Author:
Omar Shamali
Last Modification:
Writing Date:
you can decode a url from string by using this method:
String str="https%3A%2F%2Fomarshamali.com%2Fpost%2Fdecode-url-uri-from-string-in-flutter-dart-via-extending-string%2Fen";
print(Uri.decodeFull(str));
Or better to have it like a method from String type class, you can place it in any file in the project:
extension StringExtensions on String {
String decode() {
return Uri.decodeFull(this);
}
}
then the usage will be for decoding as follows:
String str="https%3A%2F%2Fomarshamali.com%2Fpost%2Fdecode-url-uri-from-string-in-flutter-dart-via-extending-string%2Fen";
print(str.decode());
result of decoded string (originally encoded URI as string):
https://omarshamali.com/post/decode-url-uri-from-string-in-flutter-dart-via-extending-string/en