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