network_cool_client

A robust Dart package for efficient network request handling, session management, real-time network state tracking, and seamless error handling for modern applications.

Pub Version Pub Likes Pub Points Pub Downloads Dart SDK Version License codecov


✨ Features

  • πŸ” Session-based client with auto token renewal and error handling
  • 🌐 Observes and notifies about network states (offline, maintenance, etc.)
  • 🧩 Extensible and easy to integrate with existing architectures
  • πŸ§ͺ Built-in testing and override-friendly design

πŸš€ Installation

Add the package to your pubspec.yaml:

dependencies:
  network_cool_client: ^1.0.0

Then run:

dart pub get

πŸ“† Usage

Basic usage

final client = NccClient(
  id: 'ncc-client',
  client: http.Client(),
);

final response = await client.get(Uri.parse('https://api.example.com/data'));

Session-based usage

final client = SessionClient(
  id: 'session-client',
  client: http.Client(),
);

final response = await client.get(
  Uri.parse('https://api.example.com/secure-data'),
);

You can customize token renewal, header logic, and handle session expiration seamlessly.


πŸ“š API Reference

Check the full API reference on pub.flutter-io.cn β†’ network_cool_client.


πŸ’‘ Examples

Creation of Custom Session Client

final class MySessionClient extends SessionClient {
  MySessionClient({required this.sessionTokenStorage, required this.renewSessionRepository})
      : super(
          id: 'my-session-client',
          client: Client(),
        );

    final LocalStorageOfSessionToken sessionTokenStorage;
    final RenewSessionRepository renewSessionRepository;

  @override
  Future<String?> getBearerToken() async {
    //Obtain the token from the datasource where you store on the login request
    final token = await sessionTokenStorage.call();
    return token;
  }

  @override
  Future<bool> renewSession() async {
    //Renew session as your application need
    final renew = await renewSessionRepository.call();
    return renew.isValid;
  }
}

You can find usage examples in the example/ folder.


🀝 Contributing

Contributions are welcome!

  • Open issues for bugs or feature requests
  • Fork the repo and submit a PR
  • Run dart format and dart test before submitting

πŸ§ͺ Testing

To run tests and see code coverage:

dart test

πŸ“„ License

MIT Β© 2025 Coolosos

Libraries

ncc