toStringQs method

String toStringQs([
  1. EncodeOptions? options = const EncodeOptions(listFormat: ListFormat.repeat, skipNulls: false, strictNullHandling: false)
])

Returns a normalized string for this Uri with the query encoded by QS.encode.

Uses queryParametersAll (not queryParameters) so duplicate keys and ordered lists are preserved. When there are no query parameters, the resulting URI has no ? section.

The default options mirror common web conventions:

  • listFormat: ListFormat.repeata=1&a=2
  • skipNulls: false → keep null keys as empty
  • strictNullHandling: falsenull serializes as empty value, not omitted

Example:

final uri = Uri.https('example.com', '/p', {'a': ['1','2']});
uri.toStringQs(); // => 'https://example.com/p?a=1&a=2'

Implementation

String toStringQs([
  EncodeOptions? options = const EncodeOptions(
    listFormat: ListFormat.repeat,
    skipNulls: false,
    strictNullHandling: false,
  ),
]) =>
    replace(
      query: queryParameters.isNotEmpty
          ? QS.encode(queryParametersAll, options)
          : null,
      queryParameters: null,
    ).toString();