networking_layer 1.0.0
networking_layer: ^1.0.0 copied to clipboard
A robust, solid-compliant networking layer using Dio.
Networking Layer #
A robust, SOLID-compliant networking package for Flutter using Dio.
Features #
- Decoupled Architecture: Independent of app-specific logic using
DioConfig. - SOLID Principles: Clean separation of concerns.
- Interceptors: Built-in support for Logging, Auth, Caching, and Retries.
- GraphQL & REST: Unified
ApiClientmixin for both. - Error Handling: Standardized
HelperResponsewith functional error handling (Either).
Installation #
Add this to your package's pubspec.yaml file:
dependencies:
networking_layer:
path: ./packages/networking_layer # If local
# OR
# git:
# url: https://github.com/your_username/networking_layer.git
Usage #
- Initialize
DioServicesin yourmain.dart:
void main() {
DioServices.instance.init(
DioConfig(
baseUrl: 'https://api.example.com',
getToken: () => 'your_token',
translate: (key) => key, // Your cleanup logic
),
);
runApp(MyApp());
}
- Create a Repository using
ApiClient:
class UserRepository with ApiClient {
Future<Either<HelperResponse, User>> getUser(String id) async {
return await get<User>(
'/users/$id',
fromJson: (json) => User.fromJson(json),
);
}
}
Example #
See example/lib/main.dart for a complete runnable example.