safe_controller 0.0.3
safe_controller: ^0.0.3 copied to clipboard
A clean architecture utility for Flutter that provides result-based API execution and centralized error handling, designed to keep UI and business logic clean.
safe_controller #
A lightweight Flutter utility package that provides result-based API execution to support clean architecture and eliminate UI-level exception handling.
This package is framework-agnostic and works with any state management solution.
✨ Features #
- Result-based API flow (
ApiSuccess/ApiFailure) - Centralized API execution with
ApiExecutor - No
try-catchrequired in UI layers - Prevents exception leakage to controllers
- Clean architecture friendly
📦 Installation #
dependencies:
safe_controller: ^0.2.0
Usage #
final result = await ApiExecutor.execute(
apiCall: () => repository.fetchData(),
);
switch (result) {
case ApiSuccess(:final data):
// handle success
break;
case ApiFailure(:final message):
// handle failure
break;
}
final result = await ApiExecutor.execute(
apiCall: () => apiClient.callApi(),
isTokenExpired: (response) => response.statusCode == 401,
);