requestor 0.0.12 copy "requestor: ^0.0.12" to clipboard
requestor: ^0.0.12 copied to clipboard

outdated

A Flutter package for making HTTP requests and downloading files efficiently.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';
import 'package:requestor/requestor.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatefulWidget {
  const MyApp({super.key});

  @override
  State<MyApp> createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  final req = Requestor();

  @override
  void initState() {
    req.setOrigin("https://apiv2.tfdev.click");

    req.addInterceptor((p0) {
      print("INTECEPTOP: $p0");
      return p0;
    });

    super.initState();
  }

  Future<void> post() async {
    String path = "/login";
    final res = await req
        .post(path, {"rut": "13730077-k", "password": "1373", "tenant": "agF"});
    print(res.statusCode);
    print(res.data);
  }

  Future<void> get() async {
    String url = "/comments";
    await req.get(url, headers: {"token": "Bearer 241234u52o3456o452u"});
  }

  Future<void> downloadFiles() async {
    List<DownloadItem> urls = [
      DownloadItem(url: "https://example.com/asset1.png", overwrite: false),
    ];

    await req.downloadFiles(
      urls,
      threads: 2,
      onDownload: (p0) {},
      onProgress: (p0) {},
    );
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: const Text('Requestor example app'),
        ),
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            crossAxisAlignment: CrossAxisAlignment.center,
            mainAxisSize: MainAxisSize.max,
            children: [
              ElevatedButton(
                onPressed: get,
                child: const Text("GET"),
              ),
              const SizedBox(height: 10),
              ElevatedButton(
                onPressed: downloadFiles,
                child: const Text("DOWNLOAD FILES"),
              ),
              const SizedBox(height: 10),
              ElevatedButton(
                onPressed: post,
                child: const Text("POST"),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
0
likes
0
points
7
downloads

Publisher

unverified uploader

Weekly Downloads

A Flutter package for making HTTP requests and downloading files efficiently.

Homepage

License

unknown (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on requestor

Packages that implement requestor