flutter_synckit library

Flutter Sync Kit - 一款集成 WebDAV 的轻量级同步库

支持断点续传、离线优先、冲突处理等高级功能。 一行代码即可同步,网络细节全屏蔽。

主要功能:

  • 多协议兼容:原生支持 WebDAV,可一键接入 Nextcloud、OwnCloud 及任意标准 WebDAV 服务
  • 断点续传:智能分块,状态持久化,网络中断后秒级续传
  • 离线优先:SQLite + SharedPreferences 双缓存,离线读写无感
  • 冲突处理:自动检测版本冲突,提供多种解决策略
  • 完整校验:上传前 SHA-256 预校验,下载后二次比对

使用示例:

import 'package:flutter_synckit/flutter_synckit.dart';

void main() async {
  final syncKit = FlutterSyncKit();

  // 初始化配置
  await syncKit.initialize(
    SyncConfig(
      serverUrl: 'https://your-webdav-server.com',
      username: 'your-username',
      password: 'your-password',
      localDirectory: '/path/to/local/dir',
    ),
  );

  // 执行同步
  final result = await syncKit.sync();
  print('Sync completed: ${result.successCount}/${result.totalFiles}');

  // 监听同步事件
  syncKit.eventStream.listen((event) {
    print('Event: ${event.type}');
  });
}

Classes

BatchSyncResult
批量同步结果
CacheService
缓存服务
ChunkInfo
分块信息
ChunkService
分块服务
CryptoUtil
加密工具类
DatabaseService
数据库服务
ErrorCodes
错误码定义
FileSyncResult
文件同步结果
FileUtil
文件工具类
FlutterSyncKit
Flutter Sync Kit 主类
Logger
日志记录器
LoggerConfig
日志配置
SyncConfig
同步配置
SyncConstants
库常量
SyncEvent
同步事件
SyncFile
同步文件模型
SyncManager
同步管理器
SyncTask
同步任务模型
WebDAVClient
WebDAV 客户端
WebDAVConfig
WebDAV 客户端配置
WebDAVFileInfo
WebDAV 文件信息

Enums

ConflictStrategy
冲突解决策略
LogLevel
日志级别
NetworkState
网络状态
SyncEventType
同步事件类型
SyncResultStatus
同步结果状态
SyncState
同步状态
SyncStatus
文件同步状态
SyncTaskState
同步任务状态
SyncTaskType
同步任务类型

Functions

basename(String path) String
Gets the part of path after the last separator.
dirname(String path) String
Gets the part of path before the last separator.
extension(String path, [int level = 1]) String
Gets the file extension of path: the portion of basename from the last . to the end (including the . itself).
join(String part1, [String? part2, String? part3, String? part4, String? part5, String? part6, String? part7, String? part8, String? part9, String? part10, String? part11, String? part12, String? part13, String? part14, String? part15, String? part16]) String
Joins the given path parts into a single path using the current platform's separator. Example:
normalize(String path) String
Normalizes path, simplifying it by handling .., and ., and removing redundant path separators whenever possible.
relative(String path, {String? from}) String
Attempts to convert path to an equivalent relative path from the current directory.
split(String path) List<String>
Splits path into its components using the current platform's separator.

Exceptions / Errors

ConfigurationException
配置异常
DatabaseException
数据库异常
FileException
文件异常
HttpException
HTTP 异常
NetworkException
网络异常
SyncException
同步异常基类
SynchronizationException
同步异常
WebDAVException
WebDAV 异常