A simple Flutter / Dart Utility class for converting complex objects to uri and query string

Overview

A simple Flutter / Dart Utility class for converting complex or nested objects to uri and query strings

you can follow the the article on how this class was built and add suggestions

Example1

final params = {
  'name': 'John',
  'columns': ['firstName', 'lastName'],
  'ageRange': {
    'from': 12,
    'to': 60,
  },
  'someInnerArray': [1,2,3,5]
};
final Uri uri = SimplifiedUri.uri('http://api.mysite.com/users', params);
final headers = {HttpHeaders.contentTypeHeader: 'application/json'};
final response = await http.get(uri, headers: headers);

output

http://api.mysite.com/users?name=John&columns%5B%5D=firstName&columns%5B%5D=lastName&ageRange%5Bfrom%5D=12&ageRange%5Bto%5D=60&someInnerArray%5B%5D=1&someInnerArray%5B%5D=2&someInnerArray%5B%5D=3&someInnerArray%5B%5D=5

Example 2 using the objectToQueryString() method

final params = {
  'name': 'John',
  'columns': ['firstName', 'lastName'],
  'ageRange': {
    'from': 12,
    'to': 60,
  },
  'someInnerArray': [1,2,3,5]
};
final queryString = objectToQueryString(param);
final Uri uri = 'http://api.mysite.com/users?$queryString';
final headers = {HttpHeaders.contentTypeHeader: 'application/json'};
final response = await http.get(uri, headers: headers);

same output

http://api.mysite.com/users?name=John&columns%5B%5D=firstName&columns%5B%5D=lastName&ageRange%5Bfrom%5D=12&ageRange%5Bto%5D=60&someInnerArray%5B%5D=1&someInnerArray%5B%5D=2&someInnerArray%5B%5D=3&someInnerArray%5B%5D=5
You might also like...

Contains utility functions and classes in the style of dart:collection to make working with collections easier

The collection package for Dart contains a number of separate libraries with utility functions and classes that makes working with collections easier.

Dec 27, 2022

Parse cron string to schedule and generate previous or next schedule item

Parse cron string to schedule and generate previous or next schedule item

Apr 17, 2022

AsyncCallQueue is a Dart class which provides a queuing mechanism to prevent concurrent access to asynchronous code.

async_call_queue AsyncCallQueue is a Dart class which provides a queuing mechanism to prevent concurrent access to asynchronous code. Getting Started

Jan 18, 2022

A Dart testing utility for asserting that some code emits a compilation error.

A Dart testing utility for asserting that some code emits a compilation error.

Dec 11, 2022

A Pure Dart Utility library that checks for an Active Internet connection

This Code comes from https://github.com/komapeb/data_connection_checker * 🌍 Internet Connection Checker A Pure Dart Utility library that checks for a

Nov 25, 2022

The Flutter code generator for your assets, fonts, colors, … — Get rid of all String-based APIs.

The Flutter code generator for your assets, fonts, colors, … — Get rid of all String-based APIs.

The Flutter code generator for your assets, fonts, colors, … — Get rid of all String-based APIs. Inspired by SwiftGen. Motivation Using asset path str

Jan 6, 2023

Converts SVG icons to OTF font and generates Flutter-compatible class. Provides an API and a CLI tool.

Fontify The Fontify package provides an easy way to convert SVG icons to OpenType font and generate Flutter-compatible class that contains identifiers

Oct 28, 2022

A generator to create config class from json files that support many environments

A generator to create config class from json files that support many environments. Motivation If you use a json file to config your applications, perp

Oct 9, 2021

A builder that generates an ArgsParser from a class

Parse command line arguments directly into an annotation class using the Dart Build System. Example Annotate a class with @CliOptions() from package:b

Oct 30, 2022
Owner
Opata Joshua
Fullstack Dev: native desktop, native mobile, hybrid mobile, web frontend, web backend
Opata Joshua
Parse and compose Magnet URI extension (BEP53) ranges.

bep53-range Parse and compose Magnet URI extension (BEP53) ranges. Dart port of https://github.com/webtorrent/bep53-range Usage parse Parse Magnet URI

Chiziaruhoma Ogbonda 2 Feb 7, 2022
A collection of flutter and dart libraries allowing you to consume complex external forms at runtime.

flutter_dynamic_forms A collection of flutter and dart libraries providing a solution for Server Driven UI in your Flutter application. Package Pub ex

Ondřej Kunc 193 Dec 20, 2022
A flutter package provides controllers and editors for complex models and lists

This package provides controllers and editors for complex models and lists and is inspired by simplicity of TextEditingController. It encapsulates sta

null 2 Sep 1, 2022
An auto mapper for Dart. It allows mapping objects of different classes automatically and manually using JSON serialization.

AutoMapper for Dart An auto mapper for Dart. It allows mapping objects of different classes automatically and manually using JSON serialization. Examp

Leynier Gutiérrez González 7 Aug 24, 2022
This package allows programmers to annotate Dart objects in order to Serialize / Deserialize them to / from JSON

This package allows programmers to annotate Dart objects in order to Serialize / Deserialize them to / from JSON. Why? Compatible with all target plat

Alexander Mazuruk 356 Jan 6, 2023
Quiver is a set of utility libraries for Dart that makes using many Dart libraries easier and more convenient, or adds additional functionality.

Quiver is a set of utility libraries for Dart that makes using many Dart libraries easier and more convenient, or adds additional functionality.

Google 905 Jan 2, 2023
Generate random data(string, integer, IPs etc...) using Dart.

Generate random data using Features API provides generation of: Integers in any range of numbers Strings with various characters and length Colors rep

Dinko Pehar 14 Apr 17, 2022
This is a simple class to package up and send requests to the Kroki.io web service.

Kroki.dart This is a simple class to package up and send requests to the Kroki.io web service. A live editor to editing diagrams that Kroki supports c

Tim Maffett 1 Jun 8, 2022
Automatically generate usecase classes from your repository class definition in Dart and Flutter

Repo Case Automatically generate usecase classes from your repository class definition in Dart and Flutter. Check out the official guide on repo_case

Sandro Maglione 5 Jul 30, 2022
Uproot(uprt) is a multi-platform (Windows, MacOs, and Linux) command line utility written in Dart to convert a router's DHCP IP Reservations between routers

UPROOT Uproot(uprt) is a multi-platform (Windows, MacOs, and Linux) command line utility written in Dart to convert a router's DHCP IP Reservations be

GeekVisit 73 Jan 1, 2023