flutter_offline_sync_ui
Flutter UI widgets for flutter_offline_sync_core. Watches Drift job streams and shows sync status per screen or feature.
Install
dependencies:
flutter_offline_sync_ui: ^0.1.0
Quick start
import 'package:flutter_offline_sync_ui/flutter_offline_sync_ui.dart';
OfflineSyncScope(
db: db,
engine: engine,
child: MaterialApp(
home: CreatePostScreen(),
),
);
class CreatePostScreen extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Create post'),
actions: [
SyncStatusBadge(
db: OfflineSyncScope.of(context).db,
screen: 'create_post_screen',
),
],
),
body: Column(
children: [
SyncScreenBanner(screen: 'create_post_screen'),
// ... rest of screen
],
),
);
}
}
When enqueueing jobs, set meta so list tiles can show a label and record
details (meta is free-form per feature):
await JobBuilder(
db,
feature: 'posts',
screen: 'create_post_screen',
meta: {
'label': 'Upload photo',
'subtitle': 'Site report · doc-123', // optional second line
},
)
.addStep('uploadImage', taskType: 'uploadImage', input: {'filePath': path})
.enqueue();
UI conventions: label → title, subtitle → record line under the title.
Other keys are ignored by the stock tile but available to your app.
Widgets
| Widget | Purpose |
|---|---|
OfflineSyncScope |
Provides SyncDatabase + SyncEngine to descendants |
SyncJobsBuilder |
Rebuilds on watchJobsForScreen / watchJobsForFeature |
SyncStatusBadge |
Compact chip: "2 pending", "1 failed", etc. |
SyncActivityIndicator |
Busy chip from push/pull streams (+ optional running jobs) |
SyncScreenBanner |
Screen-level banner with job list + discard pending |
SyncJobListTile |
Single job row with retry for failed jobs |
Sync activity chip
SyncActivityIndicator(
isPushing: engine.isSyncingStream,
isPulling: pullCoordinator.isPullingStream,
initialPushing: engine.isSyncing,
initialPulling: pullCoordinator.isPulling,
db: syncDb, // optional: also light up for JobStatus.running
feature: 'documents', // or screen: '...'
pushingLabel: 'Uploading…',
pullingLabel: 'Updating…',
busyLabel: 'Syncing…',
);
Placement and localized copy belong in the host app; the widget stays generic.
Helpers
countJobs— group jobs by statusactiveJobs— filter out success/cancelledhistoryJobs— recent success/cancelled jobs (newest first)jobMetaMap/jobDisplayLabel/jobDisplaySubtitle— readmetajobStatusAppearance— icon/color perJobStatus
History without a second database
Successful jobs already stay in SyncDatabase. Prefer showing them with
historyJobs and optionally calling SyncDatabase.pruneCompletedJobs
(default: drop success/cancelled older than 7 days) to bound storage. A
separate history DB is only needed if you must delete outbox step payloads
while keeping a thinner long-term audit log.
This package re-exports flutter_offline_sync_core.
Conflict resolution
SyncJobListTile exposes onConflictTap for conflicted jobs. Wire it to your
app's resolution UI, then call engine.resolveConflict(...).
Example
cd packages/flutter_offline_sync_ui/example
flutter run
The example app demonstrates OfflineSyncScope, SyncStatusBadge,
SyncScreenBanner, and SyncJobListTile wired to live Drift streams.