encode function
- Object? object, [
- EncodeOptions? options
Encode a Dart object into a query string (convenience for QS.encode).
object
can be aMap
, list/iterable, or scalar—anything the core encoder supports. Nested maps/lists are serialized using bracket syntax, matching the JavaScriptqs
format.options
controls percent-encoding, list formatting, sorting, etc. If omitted, defaults match the JavaScriptqs
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);