ncc 0.0.6
ncc: ^0.0.6 copied to clipboard
A robust Dart package for efficient network request handling, session management, real-time network state tracking, and seamless error handling for modern applications.
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.
β¨ 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 formatanddart testbefore submitting
π§ͺ Testing #
To run tests and see code coverage:
dart test
π License #
MIT Β© 2025 Coolosos