flutter_http_provider 2.0.0 copy "flutter_http_provider: ^2.0.0" to clipboard
flutter_http_provider: ^2.0.0 copied to clipboard

A robust Flutter package for HTTP request handling with advanced file upload capabilities, isolate support, automatic retries, and comprehensive error management.

Flutter HTTP Provider #

pub package License: MIT

A robust Flutter package for HTTP request handling with advanced file upload capabilities, isolate support, automatic retries, and comprehensive error management.

Features #

  • Full HTTP Support: GET, POST, PUT, DELETE, and UPLOAD operations
  • Automatic Retries: Configurable retry logic for failed requests
  • Isolate Support: Background execution for heavy operations
  • Large File Uploads: Automatic chunked uploads for large files
  • Certificate Handling: Option to ignore self-signed certificates in development
  • Configurable Timeouts: Granular timeout control per request
  • Cross-Platform: Compatible with iOS, Android, Web, macOS, Linux, and Windows
  • Robust Error Handling: Comprehensive network exception handling

Installation #

Add the package to your pubspec.yaml:

dependencies:
  flutter_http_provider: ^1.0.0

Then run:

flutter pub get

Usage #

Import #

import 'package:flutter_http_provider/flutter_http_provider.dart';

Initialization #

FlutterHttpProvider uses the Singleton pattern:

final httpProvider = FlutterHttpProvider(enableDebugLogs: true);

GET Request #

final response = await httpProvider.httpAccion(
  'GET',
  'https://api.example.com/data',
  false, // runIsolate
  'query_hash',
  'collection_name',
  headers: {
    'Authorization': 'Bearer your_token',
    'Content-Type': 'application/json',
  },
  timeOut: 10,
);

if (response.containsKey('data_ok')) {
  final data = response['data'];
  print('Data received: $data');
} else {
  print('Error: ${response['error']}');
}

POST Request #

final response = await httpProvider.httpAccion(
  'POST',
  'https://api.example.com/users',
  false,
  'create_user_hash',
  'users',
  headers: {
    'Content-Type': 'application/json',
    'Authorization': 'Bearer your_token',
  },
  body: jsonEncode({'name': 'John Doe', 'email': 'john@example.com'}),
  encoding: Encoding.getByName('utf-8'),
);

File Upload #

final response = await httpProvider.httpAccion(
  'UPLOAD',
  'https://api.example.com/upload',
  false,
  'upload_hash',
  'files',
  headers: {'Authorization': 'Bearer your_token'},
  fileBytes: fileBytes,
  imagenNombre: 'my_file.jpg',
  timeOut: 30,
);

Large File Upload with Chunks #

For large files, use the chunked upload functionality:

final uploadSession = httpProvider.createUploadSession(
  file: fileBytes,
  token: 'your_token',
  imagenNombre: 'large_file.mp4',
  partSize: 1024 * 1024, // 1MB per chunk
  urlStreaming: 'https://api.example.com/upload/start',
  urlPart: 'https://api.example.com/upload/part/',
);

// Start transaction
final transactionId = await uploadSession.iniciarTransaccion();

// Upload file parts
await uploadSession.subirArchivo(
  idTransaccion: transactionId,
  runIsolate: true,
);

// Finalize transaction
final filePath = await uploadSession.finalizarTransaccion(transactionId);

Using Isolates #

For heavy operations that might block the UI:

final response = await httpProvider.httpAccion(
  'GET',
  'https://api.example.com/heavy-data',
  true, // runIsolate = true
  'heavy_operation_hash',
  'heavy_data',
  timeOut: 60,
);

Response Structure #

Success Response #

{
  'data_ok': 'OK',
  'status': '200',
  'inStatus': '000',
  'msgStatus': 'Operation successful',
  'data': { /* response data */ },
  'total_items': 10,
  'hash_query': 'your_hash_query',
  'coleccion': 'your_collection',
}

Error Response #

{
  'data_nok': 'NOK',
  'error': 'Error description',
  'status': '400',
}

Special Status Codes #

  • 999: No internet connection
  • 200, 203, 302: Valid success codes

Configuration #

Debug Logging #

Enable debug logs during development:

final httpProvider = FlutterHttpProvider(enableDebugLogs: true);

Isolate Limits #

The package automatically limits concurrent isolates to 5 to prevent system overload.

Dependencies #

Platform Support #

Platform Support
Android
iOS
Web
macOS
Linux
Windows

License #

This project is licensed under the MIT License - see the LICENSE file for details.

Contributing #

Contributions are welcome! Please feel free to submit a Pull Request.

0
likes
135
points
228
downloads

Publisher

unverified uploader

Weekly Downloads

A robust Flutter package for HTTP request handling with advanced file upload capabilities, isolate support, automatic retries, and comprehensive error management.

Topics

#http #http-client #networking #file-upload #api

Documentation

API reference

License

MIT (license)

Dependencies

flutter, flutter_models_provider, http, retry

More

Packages that depend on flutter_http_provider