chlorine 0.1.0

  • README.md
  • CHANGELOG.md
  • Installing
  • Versions
  • 55

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 packages get

Alternatively, your editor might support flutter packages 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';
  
Version Uploaded Documentation Archive
0.1.0 Dec 9, 2018 Go to the documentation of chlorine 0.1.0 Download chlorine 0.1.0 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
22
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]
55
Learn more about scoring.

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

  • Dart: 2.1.0
  • pana: 0.12.10
  • Flutter: 1.1.7

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 (library, class, field or method) have no adequate dartdoc content. Good documentation improves code readability and discoverability through search.

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 description is too short. (-20 points)

Add more detail about the package, what it does and what is its target use case. Try to write at least 60 characters.

Maintain an example. (-10 points)

Create a short demo in the example/ directory to show how to use this package. Common file name patterns include: main.dart, example.dart or you could also use chlorine.dart.

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+1
Transitive dependencies
async 2.0.8
charcode 1.1.2
collection 1.14.11
http_parser 3.1.3
meta 1.1.6 1.1.7
path 1.6.2
sky_engine 0.0.99
source_span 1.5.1
string_scanner 1.0.4
term_glyph 1.1.0
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test