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

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) => p0);
    super.initState();
  }

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

  Future<void> getTenants() async {
    final res = req.post("/getorgs", {"rut": "12498916-7"});
    print(res);
  }

  Future<void> downloadFiles() async {
    List<DownloadItem> urls = [];

    int i = 0;

    while (i < 200) {
      urls.add(DownloadItem(
        url:
            "https://trainfes-storage-agf.s3.amazonaws.com/1655609972209_carbon+(2).png",
        overwrite: true,
        wildcard: "$i",
      ));
      i++;
    }

    final a = await req.downloadFiles(
      urls,
      onDownload: (p0) {
        print("::::::::::::");
        print("ID -> ${p0.id}");
        print("STATUS: ${p0.status}(${p0.statusCode})");
        print("WILDCARD: ${p0.wildcard}");
        print("::::::::::::");
      },
      onProgress: (p0) {
        print("descarga: ${p0.current} (${p0.progress})");
      },
    );

    print(a.data);
  }

  void multi() async {
    getTenants();
    downloadFiles();
    post();
  }

  @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: downloadFiles,
                child: const Text("DOWNLOAD FILES"),
              ),
              const SizedBox(height: 10),
              ElevatedButton(
                onPressed: post,
                child: const Text("POST"),
              ),
              const SizedBox(height: 10),
              ElevatedButton(
                onPressed: getTenants,
                child: const Text("GET TENANTS"),
              ),
              const SizedBox(height: 10),
              ElevatedButton(
                onPressed: multi,
                child: const Text("MULTI TASK"),
              ),
            ],
          ),
        ),
      ),
    );
  }
}
0
likes
140
points
7
downloads

Publisher

unverified uploader

Weekly Downloads

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

Homepage

Documentation

API reference

License

MIT (license)

Dependencies

flutter, plugin_platform_interface

More

Packages that depend on requestor

Packages that implement requestor