smart_api_executor
Lightweight โข Reusable โข Architecture Independent โข Dart & Flutter
๐ Overview
smart_api_executor is a lightweight and reusable
API lifecycle execution utility for Dart and Flutter applications.
It standardizes:
- Loading state handling
- Success responses
- Failure handling
- No-internet detection
Without forcing any specific architecture or state management.
No more repeated try-catch boilerplate across projects.
โจ Features
- โ Standardized API execution flow
- ๐ Optional no-internet detection
- โก Minimal boilerplate
- ๐งฑ Works with BLoC, Riverpod, Provider, GetX
- ๐งช Fully testable
- ๐ฏ Pure Dart (no UI dependency)
- ๐ฆ Lightweight and production-ready
๐ฑ Platform Support
| Platform | Supported |
|---|---|
| Android | โ |
| iOS | โ |
| Web | โ |
| Windows | โ |
| macOS | โ |
| Linux | โ |
๐ฆ Installation
Add this to your pubspec.yaml:
dependencies:
smart_api_executor: ^0.0.1
Then run:
dart pub get
๐ง Basic Usage
import 'package:smart_api_executor/smart_api_executor.dart';
final result = await ApiExecutor.execute(
action: () async {
return "Hello World";
},
);
if (result.status == ApiStatus.success) {
print(result.data);
} else {
print(result.error);
}
๐ No-Internet Handling
final result = await ApiExecutor.execute(
action: () async {
throw Exception("No Internet");
},
isNoInternet: (error) =>
error.toString().contains("No Internet"),
);
if (result.status == ApiStatus.noInternet) {
print("No connection available");
}
๐ฅ Example with BLoC
emit(state.copyWith(status: DashboardStatus.loading));
final result = await ApiExecutor.execute(
action: () => repository.getDashboard(),
);
switch (result.status) {
case ApiStatus.success:
emit(state.copyWith(
status: DashboardStatus.success,
data: result.data,
));
break;
case ApiStatus.failure:
case ApiStatus.noInternet:
emit(state.copyWith(
status: DashboardStatus.failure,
error: result.error,
));
break;
default:
break;
}
๐ License
MIT License ยฉ 2026 Yesu Balan