requestor 0.0.10
requestor: ^0.0.10 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://jsonplaceholder.typicode.com");
super.initState();
}
Future<void> get() async {
String url = "/comments";
await req.get(url);
}
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),
],
),
),
),
);
}
}