dio_handler 0.0.2 copy "dio_handler: ^0.0.2" to clipboard
dio_handler: ^0.0.2 copied to clipboard

DioHandler provides utility functions and customization options to streamline API request handling in your Flutter applications.

dio_handler_main_banner

DioHandler #

Pub Version License


Introduction #

DioHandler is a Flutter package designed to simplify network API calls using the Dio HTTP client. It provides utility functions and customization options to streamline API request handling in your Flutter applications.

Features #

  • Simplified API calls with Dio.
  • Customizable error and loading dialogs.
  • Network connectivity check.
  • Callback time measurement.

Table of Contents #


Installation #

To use DioHandler in your Flutter project, add it as a dependency in your pubspec.yaml file:

dependencies:
  dio_handler: <latest_version>

Then, run flutter pub get to install the package.


Usage #

Import the Package #

First, import the dio_handler package in your Dart file:

import 'package:dio_handler/dio_handler.dart';

Create a DioHandler Instance #

Create an instance of DioHandler by providing a Dio instance and other optional parameters:

final DioHandler dioHandler = DioHandler(
  customErrorDialog: MyCustomErrorDialog(), // Optional: Provide a custom error dialog widget
  customLoadingDialog: MyCustomLoadingDialog(), // Optional: Provide a custom loading dialog widget
  isCheckNetworkConnectivity: true, // Optional: Enable network connectivity check
  isAlertDialogs: true, // Optional: Show alert dialogs for errors
  isCallBackTime: true, // Optional: Measure API callback time (debug mode)
);

Replace MyCustomErrorDialog() and MyCustomLoadingDialog() with your actual custom error and loading dialog widgets if needed.

Make API Requests #

To make an API request and handle responses, use the callAPI() method:

dioHandler.callAPI(
  serviceUrl: 'https://api.example.com/data',
  method: 'GET',
  success: (response) {
    // Handle successful response here
    print('API Request Successful');
    print(response.data);
  },
  error: (error) {
    // Handle error response here
    print('API Request Error');
    print(error);
  },
  showProcess: true, // Set to true to display a loading dialog
);

Example #

You can find an example of how to use DioHandler in the example folder of this package. To run the example, follow these steps:

  1. Clone this repository.
  2. Navigate to the example folder.
  3. Run flutter run to launch the example app.

Get in touch #

If you have any questions, feel free to reach out:


Contributing #

Contributions to the dio_handler package are welcome! If you find a bug or want to add a new feature, feel free to open an issue or submit a pull request.

Contributors #


License #

This package is released under the Apache License. See the LICENSE file for details.


Feel free to explore the features of the DioHandler package and customize it to suit your needs. If you have any questions or feedback, don't hesitate to reach out. Happy coding!

13
likes
120
pub points
22%
popularity
screenshot

Publisher

verified publisherarfaz.tech

DioHandler provides utility functions and customization options to streamline API request handling in your Flutter applications.

Homepage
Repository (GitHub)
View/report issues
Contributing

Topics

#dio #api-call #dio-handler #http

Documentation

API reference

License

Apache-2.0 (LICENSE)

Dependencies

connectivity_plus, dio, flutter

More

Packages that depend on dio_handler