jsonplaceholder_offline 1.0.1 copy "jsonplaceholder_offline: ^1.0.1" to clipboard
jsonplaceholder_offline: ^1.0.1 copied to clipboard

outdated

A simple JsonPlaceholder offline package that allows you to get data for your flutter project on the go without relying on the network

jsonplaceholder_offline #

A simple package that allows you to get data for your project on the go without relying on the network

Installation #

Add this to your package's pubspec.yaml file

dependencies:
    jsonplaceholder_offline: 1.0.1

and run

flutter packages get

How it work #

The package is offline version ofJsonPlaceholder Jsonplaceholder has 6 different data categories:

  • User
  • Post
  • Comment
  • Album
  • Photo
  • Todo

you can get data in two format either object or json.

  • to get object data you will need to call getData<T>(length:1) method with length as a parameter
  • to get json data you will need to call getJsonData<T>(length:1) method with length as a parameter

NB:

  • length is number of data you wish to return. from (min 1 - max 100)

  • T is the generic reference of your category.

    Usage #

    Getting Object data #

list of Users #

      JsonPlaceholder jsonPlaceholder = JsonPlaceholder();
      List<User> users = jsonPlaceholder.getData<User>(length: 20);

a single User object #

      JsonPlaceholder jsonPlaceholder = JsonPlaceholder();
      User user = jsonPlaceholder.getData<User>(length:1);

Getting Json data #

list of users data #

      JsonPlaceholder jsonPlaceholder = JsonPlaceholder();
      List<Map<String, dynamic>> users = jsonPlaceholder.getJsonData<User>(length: 20);

a single User json #

      JsonPlaceholder jsonPlaceholder = JsonPlaceholder();
      Map<String, dynamic> user = jsonPlaceholder.getJsonData<User>(length:1);

Get UserPost by userId #

 JsonPlaceholder jsonPlaceholder = JsonPlaceholder();
      List<dynamic> comments =
          jsonPlaceholder.getUserPosts(userId: 1, toJson: false);

NB: toJson property can be set to true if you want the return data to be in JSON format

Get PostComment by postId #

 JsonPlaceholder jsonPlaceholder = JsonPlaceholder();
      List<dynamic> comments =
          jsonPlaceholder.getUserPosts(postId: 1, toJson: false);

NB: toJson property can be set to true if you want the return data to be in JSON format

Data credit: https://jsonplaceholder.typicode.com/

5
likes
0
pub points
0%
popularity

Publisher

verified publisherdammak.dev

A simple JsonPlaceholder offline package that allows you to get data for your flutter project on the go without relying on the network

Repository (GitHub)
View/report issues

License

unknown (LICENSE)

Dependencies

flutter

More

Packages that depend on jsonplaceholder_offline