Line data Source code
1 : /// Helper class to construct uri for the ImageTransformation class 2 : class URLQueryParams { 3 : final Map<String, String> _values = {}; 4 : 5 : // Appends a parameter to the query with received key. 6 2 : void append(String key, dynamic value) { 7 4 : if (value != null && value.toString().isNotEmpty) { 8 8 : _values[key] = Uri.encodeQueryComponent(value.toString()); 9 : } 10 : } 11 : 12 : // Removes a parameter from query by key. 13 1 : void remove(String key) { 14 2 : _values.remove(key); 15 : } 16 : 17 : // Convert to query string like the next example: 18 : // * param1=value1¶m2=value2 19 2 : @override 20 : String toString() { 21 : String response = ''; 22 6 : _values.forEach((key, value) { 23 4 : response += '$key=$value&'; 24 : }); 25 8 : return response.substring(0, response.isEmpty ? 0 : response.length - 1); 26 : } 27 : 28 2 : String toUrl(String urls) { 29 : String updatedUrl; 30 4 : if (urls != null && urls.isNotEmpty && urls.endsWith('/')) { 31 3 : updatedUrl = urls.substring(0, urls.length - 1); 32 : } else { 33 : updatedUrl = urls; 34 : } 35 4 : return '$updatedUrl?${toString()}'; 36 : } 37 : }