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

Libraries

smart_api_executor