Add sync status to app drawer

This commit is contained in:
2026-02-06 20:43:26 +01:00
parent 7ec7b20e74
commit 9261ec341e
3 changed files with 67 additions and 13 deletions

View File

@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:sheetless/core/services/sync_service.dart';
/// Callback for shuffle state changes.
typedef ShuffleCallback = void Function(bool enabled);
@@ -12,12 +13,14 @@ class AppDrawer extends StatelessWidget {
final VoidCallback onLogout;
final String? appName;
final String? appVersion;
final Future<SyncResult> syncFuture;
const AppDrawer({
super.key,
required this.isShuffling,
required this.onShuffleChanged,
required this.onLogout,
required this.syncFuture,
this.appName,
this.appVersion,
});
@@ -32,7 +35,7 @@ class AppDrawer extends StatelessWidget {
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
_buildActions(),
_buildAppInfo(),
Column(children: [_buildSyncStatus(), _buildAppInfo()]),
],
),
),
@@ -44,10 +47,7 @@ class AppDrawer extends StatelessWidget {
return Column(
children: [
ListTile(
leading: Icon(
Icons.shuffle,
color: isShuffling ? Colors.blue : null,
),
leading: Icon(Icons.shuffle, color: isShuffling ? Colors.blue : null),
title: const Text('Shuffle'),
onTap: () => onShuffleChanged(!isShuffling),
),
@@ -60,6 +60,47 @@ class AppDrawer extends StatelessWidget {
);
}
Widget _buildSyncStatus() {
return Center(
// padding: const EdgeInsets.all(5.0),
child: FutureBuilder<SyncResult>(
future: syncFuture,
builder: (context, snapshot) {
if (snapshot.connectionState != ConnectionState.done) {
return const Center(child: CircularProgressIndicator());
}
if (snapshot.hasError) {
return Text(
"Error: ${snapshot.error.toString()}",
style: const TextStyle(color: Colors.red),
textAlign: TextAlign.center,
);
}
if (snapshot.hasData) {
final changes = snapshot.data!.changesUnsynced;
final annotations = snapshot.data!.annotationsUnsynced;
if (changes == 0 && annotations == 0) {
return Text(
"All synced!",
style: const TextStyle(color: Colors.black),
textAlign: TextAlign.center,
);
}
return Text(
"$changes changes and $annotations annotations unsynchronized!",
style: const TextStyle(color: Colors.red),
textAlign: TextAlign.center,
);
}
return const Center(child: CircularProgressIndicator());
},
),
);
}
Widget _buildAppInfo() {
final versionText = appName != null && appVersion != null
? '$appName v$appVersion'
@@ -67,10 +108,7 @@ class AppDrawer extends StatelessWidget {
return Padding(
padding: const EdgeInsets.all(16.0),
child: Text(
versionText,
style: const TextStyle(color: Colors.grey),
),
child: Text(versionText, style: const TextStyle(color: Colors.grey)),
);
}
}