Skip to main content

dio_offline_sync 0.0.1 copy "dio_offline_sync: ^0.0.1" to clipboard
dio_offline_sync: ^0.0.1 copied to clipboard

A production-ready Flutter package for plug-and-play offline request queueing and auto-sync with Dio. Handles connectivity, storage, and retries automatically.

example/dio_offline_sync_example.dart

import 'package:dio/dio.dart';
import 'package:dio_offline_sync/offline_sync.dart';
import 'package:hive/hive.dart';

void main() async {
  // Ensure Hive is initialized (Path required for non-Flutter pure Dart)
  // For Flutter, utilize Hive.initFlutter()
  Hive.init('.');

  final dio = Dio(BaseOptions(baseUrl: 'https://jsonplaceholder.typicode.com'));

  // ONE LINE SETUP
  dio.addOfflineSupport(
    storage: HiveOfflineStorage(),
    syncStrategy: SyncStrategy.auto,
    retryPolicy: RetryPolicy.exponential(maxRetries: 4),
  );

  print('Sending Request...');
  try {
    final response = await dio.post(
      '/posts',
      data: {'title': 'foo', 'body': 'bar', 'userId': 1},
    );

    if (response.statusCode == 202) {
      print('⚠️ Device is offline. Request queued!');
    } else {
      print('✅ Success: ${response.data}');
    }
  } catch (e) {
    print('Error: $e');
  }
}
0
likes
110
points
51
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

A production-ready Flutter package for plug-and-play offline request queueing and auto-sync with Dio. Handles connectivity, storage, and retries automatically.

Repository (GitHub)

License

MIT (license)

Dependencies

connectivity_plus, dio, equatable, flutter, hive, uuid

More

Packages that depend on dio_offline_sync