flutter_offline_queue 1.0.4 copy "flutter_offline_queue: ^1.0.4" to clipboard
flutter_offline_queue: ^1.0.4 copied to clipboard

flutter_offline_queue is a Flutter/Dart package to queue API requests offline and retry when online.

flutter_offline_queue #

Pub Version Publisher License Dart Flutter

A reliable Flutter package to ensure your app handles offline API requests gracefully.
It queues failed HTTP calls and retries them once connectivity is restored — ideal for unstable network environments.


Table of Contents #


Features #

  • Automatically detects internet connectivity changes
  • Queues HTTP requests (GET, POST, PUT, DELETE) when offline
  • Persists queued requests locally using SQLite (sqflite)
  • Retries all pending requests once connectivity is restored
  • Allows handling success and failure callbacks for retried requests

Getting Started #

Installation #

Add this to your pubspec.yaml:

dependencies:
  flutter_offline_queue: ^1.0.4

Then run:

flutter pub get

Usage #

Import the package:

import 'package:flutter_offline_queue/flutter_offline_queue.dart';

Initialize the queue early in your app (e.g., in main()):

void main() async {
  WidgetsFlutterBinding.ensureInitialized();
  await OfflineQueue.instance.init(clientType: ClientType.http);
  runApp(MyApp());
}

Queue requests like this:

// POST request example
await OfflineQueue.instance.post(
  url: 'https://your-api.com/endpoint',
  headers: {'Authorization': 'Bearer your_token'},
  body: {'key': 'value'},
);

// GET request example
await OfflineQueue.instance.get(url: 'https://your-api.com/items');

Callbacks #

You can set callbacks to listen for retried or failed requests:

OfflineQueue.instance.onRequestRetried = (request) {
  print('Request retried: ${request.method} ${request.url}');
};

OfflineQueue.instance.onRequestFailed = (request, error) {
  print('Request failed: ${request.method} ${request.url}, error: $error');
};

Supported Methods #

  • GET
  • POST
  • PUT
  • DELETE

Limitations & Notes #

  • Currently supports basic JSON-encoded request bodies.
  • Headers should be provided as a Map<String, String>.
  • Ensure your API supports idempotent operations or handles duplicates appropriately.
  • The package depends on connectivity_plus, http, sqflite, and path.

Example #

Here is a simple example that queues a POST request:

await OfflineQueue.instance.post(
  url: 'https://jsonplaceholder.typicode.com/posts',
  headers: {'Content-Type': 'application/json'},
  body: {
    'title': 'Test Post',
    'content': 'This is a test post',
    'author': 'Mohammad',
    'userId': 1,
  },
);

Contributing #

Contributions are welcome! Feel free to open issues or submit pull requests.


License #

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


Contact #

Created by Mohammad AD — feel free to reach out!
bummycakes.com

3
likes
140
points
53
downloads

Publisher

verified publisherbummycakes.com

Weekly Downloads

flutter_offline_queue is a Flutter/Dart package to queue API requests offline and retry when online.

Repository (GitHub)
View/report issues

Documentation

API reference

License

MIT (license)

Dependencies

connectivity_plus, dio, flutter, http, path, sqflite

More

Packages that depend on flutter_offline_queue