chlorine 0.1.0

Chlorine #

A lightweight json api network abstraction for flutter.

Chlorine uses async functions and give a easy way to access by binding responses and errors to two different closures.

Usage #

Import this package adding it in your pubspec.yaml.

...
dependencies:
  flutter:
    sdk: flutter
  chlorine: ">=0.1.0"
  ...

Create a Target:

import 'package:chlorine/chlorine_target.dart';

class UserTarget {

  String baseUrl = 'https://jsonplaceholder.typicode.com/';

  getUsers() {
    return ChlorineTarget()
        ..baseUrl = this.baseUrl
        ..path = 'users'
        ..method = ChlorineMethod.GET
        ..headers = Map.from({'Content-Type' : 'application/json'})

        //optional closures which will compute te results just before returning the response
        ..successClosure = (users) {
          print(users);
          return users;
        }
        ..errorClosure = (error) {
          print(error);
          return error;
        };
  }

  getUser(int id) {
    return ChlorineTarget()
      ..baseUrl = this.baseUrl
      ..path = 'users/$id'
      ..method = ChlorineMethod.GET
      ..headers = Map.from({'Content-Type' : 'application/json'})
  }
}

As you can see a builder methods like getUser() and getUsers() should return a ChlorineTarget. Dart's cascade notation make it very easy to build different instances of the same object.

Create a Chlorine instance and pass to it a builder method from your target class and relative success and error closure:


void main() {
    Chlorine chlorine = Chlorine();
    chlorine.jsonRequest(UserTarget().getUsers(),
        (response) {
            print(response.jsonBody);
        },
        (error) {
            print(error.jsonBody);
        }
    );
    chlorine.jsonRequest(UserTarget().getUser(2),
            (response) {
                print(response.jsonBody);
            },
            (error) {
                print(error.jsonBody);
            }
        );
}

Testing #

void main() {
  test('getUsers()', () {
    Chlorine chlorine = Chlorine();
    chlorine.jsonRequest(UserTarget().getUsers(), (response) {
      expect(response.statusCode, 200);
    }, (error) {
      return null;
    });
  });
 }

Contributing #

  • Fork it!
  • Create your feature branch: git checkout -b my-new-feature
  • Commit your changes: git commit -am 'Add some feature'
  • Push to the branch: git push origin my-new-feature
  • Submit a pull request.

[0.1.0] - 9/12/2018

  • Initial Open Source release.

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  chlorine: ^0.1.0

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:chlorine/chlorine.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
0
Health:
Code health derived from static analysis. [more]
99
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
70
Overall:
Weighted score of the above. [more]
44
Learn more about scoring.

We analyzed this package on Jul 22, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.4.0
  • pana: 0.12.19
  • Flutter: 1.7.8+hotfix.3

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health issues and suggestions

Document public APIs. (-1 points)

67 out of 67 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Format lib/chlorine.dart.

Run flutter format to format lib/chlorine.dart.

Format lib/chlorine_target.dart.

Run flutter format to format lib/chlorine_target.dart.

Maintenance suggestions

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package.

Common filename patterns include main.dart, example.dart, and chlorine.dart. Packages with multiple examples should provide example/README.md.

For more information see the pub package layout conventions.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
flutter 0.0.0
http >=0.12.0 <0.13.0 0.12.0+2
Transitive dependencies
async 2.3.0
charcode 1.1.2
collection 1.14.11
http_parser 3.1.3
meta 1.1.6 1.1.7
path 1.6.2
pedantic 1.8.0+1
sky_engine 0.0.99
source_span 1.5.5
string_scanner 1.0.4
term_glyph 1.1.0
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test

Admin