offline_sync_core 0.1.0 copy "offline_sync_core: ^0.1.0" to clipboard
offline_sync_core: ^0.1.0 copied to clipboard

A robust, lightweight, and extensible offline-first caching and synchronization package for Flutter using Hive.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'package:offline_sync_core/offline_sync_core.dart';

void main() async {
  WidgetsFlutterBinding.ensureInitialized();

  debugPrint('🚀 Initializing offline_sync_core...');

  await OfflineSyncCore.initialize(storage: HiveStorage());

  debugPrint('✅ offline_sync_core initialized');

  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      title: 'offline_sync_core',
      home: const HomePage(),
    );
  }
}

class HomePage extends StatefulWidget {
  const HomePage({super.key});

  @override
  State<HomePage> createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {
  String status = 'Loading...';

  bool fromCache = false;

  @override
  void initState() {
    super.initState();

    loadUser();
  }

  Future<void> loadUser() async {
    debugPrint('🌐 Fetching user...');

    final user = await OfflineSyncCore.get<Map>(
      key: 'user_profile',

      ttl: const Duration(seconds: 10),

      fetch: () async {
        debugPrint('📡 API request started');

        await Future.delayed(const Duration(seconds: 2));

        debugPrint('✅ API response received');

        return {'name': 'Amarjeet', 'email': 'amarjeet@example.com'};
      },
    );

    debugPrint('💾 Data loaded successfully');

    setState(() {
      status =
          '''
👤 User Data

Name: ${user?['name']}
Email: ${user?['email']}

------------------------

⚡ Cache TTL: 1 minute

🗄 Storage: Hive

🚧 Offline Sync: Coming Soon

🚧 SQLite Support: Coming Soon

🚧 Queue Manager: Coming Soon

🚧 Inspector: Coming Soon
''';
    });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: const Text('offline_sync_core Example')),

      body: SingleChildScrollView(
        padding: const EdgeInsets.all(20),

        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,

          children: [
            const Text(
              'Package Features',
              style: TextStyle(fontSize: 24, fontWeight: FontWeight.bold),
            ),

            const SizedBox(height: 20),

            const Card(
              child: ListTile(
                leading: Icon(Icons.storage),
                title: Text('Smart Cache'),
                subtitle: Text('Store API data locally'),
              ),
            ),

            const Card(
              child: ListTile(
                leading: Icon(Icons.timer),
                title: Text('TTL Support'),
                subtitle: Text('Automatic expiration'),
              ),
            ),

            const Card(
              child: ListTile(
                leading: Icon(Icons.save),
                title: Text('Hive Storage'),
                subtitle: Text('Local persistence'),
              ),
            ),

            const Card(
              child: ListTile(
                leading: Icon(Icons.sync),
                title: Text('Offline Sync'),
                subtitle: Text('Coming Soon'),
              ),
            ),

            const SizedBox(height: 24),

            Text(status, style: const TextStyle(fontSize: 16)),
          ],
        ),
      ),
    );
  }
}
2
likes
0
points
35
downloads

Publisher

unverified uploader

Weekly Downloads

A robust, lightweight, and extensible offline-first caching and synchronization package for Flutter using Hive.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

connectivity_plus, crypto, flutter, hive, hive_flutter, http, json_annotation, logger, path, path_provider, rxdart, sqflite, synchronized, uuid, workmanager

More

Packages that depend on offline_sync_core