networkjson 0.1.1 copy "networkjson: ^0.1.1" to clipboard
networkjson: ^0.1.1 copied to clipboard

outdated

Network JSON Request package.

Network JSON Request package. #

the package consists of JsonObject and JsonArray and handlers to get JsonArray from objects and JsonObject from arrays the most important part of this package is the ability to get async json directly from network calls it implements async GET and POST request simply by calling its network handlers

#

#

Getting Started #

#

GET Request #

Plain Request

#

#

Future<JsonObject> futureJson = JsonObject.get("http://example.com/api/get/", parameters: {"id": "1234"}, headers: {"Authorization": "Bearer 123456"});

it has options to provide query parameters and headers

Using with FutureBuilder

#

#

FutureBuilder<JsonObject>(
  future: JsonObject.get("http://example.com/api/get/", parameters: {"id": "1234"}, headers: {"Authorization": "Bearer 123456"});
  builder: (context, snapshot) {
    if (snapshot.hasData) {
      JsonArray list = snapshot.data.array("list");
      ListView lv = ListView.builder(
          padding: new EdgeInsets.all(8.0),
          itemExtent: 100.0,
          itemCount: list.length,
          itemBuilder: (BuildContext context, int index) {
            JsonObject json = list.object(index);
            return Text(json["key"]);
          }
      );
      return lv;
    } else if (snapshot.hasError) {
      return Text("${snapshot.error}");
    }
    return CircularProgressIndicator();
  },
)

#

#

#

#

POST Request #

Plain Request

#

#

Future<JsonObject> futureJson = JsonObject.post("http://example.com/api/get/", parameters: {"id": "1234"}, headers: {"Authorization": "Bearer 123456"}, coding: PostCoding.JSON);

it has options to provide post parameters and headers the parameter encoding could be three types :

PostCoding.UrlEncoded //url ecoded parameter encoding with 'application/json' Content-Type
PostCoding.JSON // json encoded parameter encoding with 'application/x-www-form-urlencoded' Content-Type
PostCoding.Form //post form encoding
Using with FutureBuilder

#

#

FutureBuilder<JsonObject>(
  future: JsonObject.post("http://example.com/api/get/", parameters: {"id": "1234"}, headers: {"Authorization": "Bearer 123456"}, coding: PostCoding.JSON);
  builder: (context, snapshot) {
    if (snapshot.hasData) {
      JsonArray list = snapshot.data.array("list");
      ListView lv = ListView.builder(
          padding: new EdgeInsets.all(8.0),
          itemExtent: 100.0,
          itemCount: list.length,
          itemBuilder: (BuildContext context, int index) {
            JsonObject json = list.object(index);
            return Text(json["key"]);
          }
      );
      return lv;
    } else if (snapshot.hasError) {
      return Text("${snapshot.error}");
    }
    return CircularProgressIndicator();
  },
)
1
likes
0
pub points
0%
popularity

Publisher

unverified uploader

Network JSON Request package.

Repository
View/report issues

License

unknown (LICENSE)

Dependencies

flutter, http

More

Packages that depend on networkjson