Skip to main content

flutter_lan_sync 0.1.5 copy "flutter_lan_sync: ^0.1.5" to clipboard
flutter_lan_sync: ^0.1.5 copied to clipboard

Secure offline peer-to-peer data synchronization for Flutter apps over local Wi-Fi, with encrypted transfers, discovery, and conflict handling.

example/lib/main.dart

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

final navigatorKey = GlobalKey<NavigatorState>();

Future<void> main() async {
  WidgetsFlutterBinding.ensureInitialized();

  await LanSync.initialize(
    LanSyncConfig(
      // Use the same application secret on trusted peer installations.
      // Load production secrets from your secure application configuration.
      appSecret: 'replace-with-a-secure-application-secret',
      packageName: 'com.example.flutter_lan_sync_example',
      deviceName: 'Example device',
      facilityId: 'example-facility',
      instanceType: 'training',
      requireScopedPeers: true,
      navigatorKey: navigatorKey,
      onReceive: (items) async {
        // Validate and persist received maps in the host application's store.
        debugPrint('Received ${items.length} item(s)');
      },
    ),
  );

  runApp(const ExampleApp());
}

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      navigatorKey: navigatorKey,
      title: 'LAN Sync Example',
      home: LanTransferListener(
        navigatorKey: navigatorKey,
        child: const ExampleHomePage(),
      ),
    );
  }
}

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

  @override
  Widget build(BuildContext context) {
    final items = <LanSyncItem>[
      const LanSyncItem(
        id: 'record-1',
        displayName: 'Example record',
        dataType: 'record',
        data: <String, dynamic>{'id': 'record-1', 'status': 'ready'},
      ),
    ];

    return Scaffold(
      appBar: AppBar(title: const Text('LAN Sync Example')),
      body: Center(
        child: FilledButton(
          onPressed: () {
            Navigator.of(context).push(
              MaterialPageRoute<void>(
                builder: (_) => LanSyncScreen(
                  items: items,
                  itemLabel: 'Record',
                ),
              ),
            );
          },
          child: const Text('Open LAN sync'),
        ),
      ),
    );
  }
}
0
likes
160
points
672
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

Secure offline peer-to-peer data synchronization for Flutter apps over local Wi-Fi, with encrypted transfers, discovery, and conflict handling.

Repository (GitHub)
View/report issues

License

MIT (license)

Dependencies

crypto, cryptography, device_info_plus, flutter, flutter_secure_storage, http, intl, package_info_plus, path, path_provider, shelf, shelf_router, sqflite, uuid

More

Packages that depend on flutter_lan_sync