encode function

String encode(
  1. Object? object, [
  2. EncodeOptions? options
])

Encode a Dart object into a query string (convenience for QS.encode).

  • object can be a Map, list/iterable, or scalar—anything the core encoder supports. Nested maps/lists are serialized using bracket syntax, matching the JavaScript qs format.
  • options controls percent-encoding, list formatting, sorting, etc. If omitted, defaults match the JavaScript qs behavior.

Returns a query string. Passing null yields an empty string.

Examples

final s1 = encode({'a': 'b'});                       // 'a=b'
final s2 = encode({'a': ['x', 'y']});                // 'a[0]=x&a[1]=y'
final s3 = encode({'user': {'id': 1, 'name': 'A'}}); // 'user[id]=1&user[name]=A'

Implementation

String encode(Object? object, [EncodeOptions? options]) =>
    QS.encode(object, options);