smart_api_executor 0.1.0 copy "smart_api_executor: ^0.1.0" to clipboard
smart_api_executor: ^0.1.0 copied to clipboard

A lightweight API lifecycle executor for Dart and Flutter applications. Simplifies loading, success, failure and no-internet handling.

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 #

  • โšก Simplifies try/catch API calls into a clean execution flow
  • ๐Ÿ” Retry support for transient network failures
  • โฑ๏ธ Timeout handling for long-running requests
  • ๐ŸŒ Optional no-internet detection
  • ๐Ÿง  Developer-friendly result handling with when()
  • ๐Ÿงฑ Works with BLoC, Riverpod, Provider, GetX
  • ๐Ÿงช Fully testable and framework-agnostic
  • ๐Ÿ“ฆ Pure Dart โ€“ no UI dependencies
  • ๐Ÿš€ 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.1.0

Then run:

dart pub get

โ— The Problem #

Handling API calls usually looks like this:

try {
  final data = await api.getUsers();
  // handle success
} catch (e) {
  // handle error
}

This logic is repeated across many screens and projects.


โœ… The Solution #

final result = await ApiExecutor.execute(
  action: () => api.getUsers(),
);

result.when(
  success: (data) => print(data),
  failure: (e) => print(e),
  noInternet: (_) => print("No Internet"),
  loading: () {},
  initial: () {},
);

๐ŸŒ 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;
}

๐Ÿ’ก Why smart_api_executor? #

Unlike many API helper utilities, smart_api_executor:

  • Does not depend on any HTTP client
  • Works with any architecture
  • Adds no UI dependencies
  • Encourages clean, testable code

You can use it with:

  • Dio
  • http
  • Retrofit
  • GraphQL
  • Custom API clients

โšก Advanced Example #

final result = await ApiExecutor.execute(
  action: () => api.getUsers(),
  retry: 2,
  timeout: Duration(seconds: 10),
);

๐Ÿ“Š Without smart_api_executor #

try {
  final data = await api.getUsers();
} catch (e) {
  if (e is SocketException) {
    // no internet
  } else {
    // failure
  }
}

๐Ÿ“Š With smart_api_executor #

final result = await ApiExecutor.execute(
  action: () => api.getUsers(),
);

Cleaner. Reusable. Testable.


๐Ÿ“„ License #

MIT License ยฉ 2026 Yesu Balan

๐Ÿ“š Documentation #

https://jesus-balan.github.io/smart_api_executor

11
likes
140
points
175
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

A lightweight API lifecycle executor for Dart and Flutter applications. Simplifies loading, success, failure and no-internet handling.

Homepage
Repository (GitHub)
View/report issues

License

MIT (license)

More

Packages that depend on smart_api_executor