httpagent 0.0.8
httpagent: ^0.0.8 copied to clipboard
httpagent is a comprehensive library of custom http api calling for Flutter.
example/lib/main.dart
// ignore_for_file: avoid_print
import 'package:flutter/material.dart';
import 'package:httpagent/httpagent.dart';
void main() {
runApp(const TestScreen());
}
class TestScreen extends StatefulWidget {
const TestScreen({super.key});
@override
State<TestScreen> createState() => _TestScreenState();
}
class _TestScreenState extends State<TestScreen> implements NetworkResponce {
//
@override
void onTaskComplete(String result, String caller) {
print("Result :: $result \nCaller :: $caller");
}
@override
void onTaskError(String error, String caller) {
print("Error :: $error \nCaller :: $caller");
}
// GET Request
getData() async {
NetworkUtils task =
NetworkUtils("https://example.com/api", 'getData', this);
await task.get();
}
// POST Request
postData() async {
NetworkUtils task =
NetworkUtils("https://example.com/api", 'postData', this);
await task.post(data: {'key': 'value'});
}
// PUT Request
putData() async {
NetworkUtils task =
NetworkUtils("https://example.com/api/1", 'putData', this);
await task.put(data: {'key': 'newValue'});
}
// DELETE Request
deleteData() async {
NetworkUtils task =
NetworkUtils("https://example.com/api/1", 'deleteData', this);
await task.delete();
}
// Multipart POST Request
multipartPostData() async {
NetworkUtils task =
NetworkUtils("https://example.com/upload", 'uploadFile', this);
await task.multipartPost(
data: {'description': 'file upload'}, filePath: '/path/to/file.jpg');
}
@override
void initState() {
super.initState();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text("HTTP Agent Example"),
),
body: Column(
children: [
ElevatedButton(
onPressed: () {
getData();
},
child: const Text("Fetch Data"))
],
),
);
}
}