flutter_api_kit 1.0.0 copy "flutter_api_kit: ^1.0.0" to clipboard
flutter_api_kit: ^1.0.0 copied to clipboard

A robust Flutter package to handle API requests with built-in loading buttons, snackbars, and in-button download progress indicators.

Flutter Api Kit #

A robust and highly customizable Flutter package to handle API requests with built-in loading buttons, snackbars, and progress indicators.

Features #

  • Simplified HTTP Methods: Easy-to-use GET, POST, PUT, and DELETE methods.
  • KitLoadingButton: A button that manages its own loading state and can display circular progress with a percentage.
  • In-Button Progress: Show file download progress directly inside the button without messy popups.
  • Global Config: Set base URLs and default headers easily.
  • Error Handling: Built-in logic for internet issues, timeouts, and status codes.
  • Customizable UI: Full control over colors, sizes, and styles of all components.

Installation #

Add the following to your pubspec.yaml:

dependencies:
  flutter_api_kit: ^1.0.0

Usage #

1. Initialize #

Set up your global settings in your main() function:

void main() {
  ApiKit.config(
    baseUrl: 'https://api.example.com',
    enableLogging: true, // Professional console logging
    headers: {'Api-Key': 'your_key'},
  );
  runApp(MyApp());
}

2. Basic GET Request #

Use KitLoadingButton to automatically show a spinner while the request is pending:

KitLoadingButton(
  label: 'Fetch Data',
  onPressed: (_) async {
    final res = await ApiKit.get(context: context, endpoint: '/users/1');
    if (res.success) {
      print(res.data);
    }
  },
)

3. POST Request with Success Message #

KitLoadingButton(
  label: 'Save Profile',
  backgroundColor: Colors.deepPurple,
  onPressed: (_) async {
    await ApiKit.post(
      context: context,
      endpoint: '/profile',
      body: {'name': 'John Doe'},
      successMessage: 'Profile Saved!',
    );
  },
)

4. Download with In-Button Progress #

Show a real-time percentage and circular indicator inside the button:

KitLoadingButton(
  label: 'Download PDF',
  progressColor: Colors.yellow,
  onPressed: (setProgress) async {
    await ApiKit.download(
      context: context,
      url: 'https://example.com/file.pdf',
      savePath: 'file.pdf',
      showDialog: false, // Hide popup dialog
      onProgress: (p) => setProgress(p), // Show progress in button
    );
  },
)

Customization #

You can customize almost everything:

  • Button: height, width, borderRadius, backgroundColor, textStyle.
  • Loader: loaderColor, progressColor.
  • Snackbar: The package uses KitSnackbar for beautiful notifications.

License #

This project is licensed under the MIT License - see the LICENSE file for details.

3
likes
150
points
97
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

A robust Flutter package to handle API requests with built-in loading buttons, snackbars, and in-button download progress indicators.

Repository (GitHub)

License

MIT (license)

Dependencies

cupertino_icons, dio, flutter

More

Packages that depend on flutter_api_kit