httpagent 0.0.7 copy "httpagent: ^0.0.7" to clipboard
httpagent: ^0.0.7 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"))
        ],
      ),
    );
  }
}
9
likes
0
points
19
downloads

Publisher

unverified uploader

Weekly Downloads

httpagent is a comprehensive library of custom http api calling for Flutter.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter, http

More

Packages that depend on httpagent