fetchly 0.0.1
fetchly: ^0.0.1 copied to clipboard
Fetchly is a simple way to use Dio in Flutter.
Fetchly is a lightweight Dart package designed to streamline your API interactions by simplifying the usage of the Dio HTTP client. It provides an easy-to-use, type-safe, and efficient wrapper around Dio, making your HTTP calls and response handling smooth and hassle-free.
Usage #
To use this plugin, add fetchly as a dependency in your pubspec.yaml file.
Example #
void main() {
UseFetchly(
baseUrl: 'https://dummyjson.com/',
onRequest: (status, data){
// listen request
},
onError: (e, s){
// listen error
}
).init();
runApp(const MyApp());
}
Usage #
To make API requests, extend the Fetchly class and define your methods like so:
import 'package:fetchly/fetchly.dart';
class TodoApi extends Fetchly {
Future<ResHandler> getTodos() async => await get('todos');
}
In this code snippet, we're using Dart's mixin feature to create a reusable block of code named UseApi.
mixin UseApi {
TodoApi todoApi = TodoApi();
// other api
}
class MyClass with UseApi {
Future getTodos() async {
ResHandler res = await todoApi.getTodos();
}
}
For more information and examples, see the example.