Add symbol for offline available sheets

This commit is contained in:
2026-07-03 17:46:50 +02:00
parent e3ee24e06b
commit baf20e1ca8
5 changed files with 19 additions and 0 deletions
+2
View File
@@ -7,12 +7,14 @@ class Sheet {
String name;
String composer;
DateTime updatedAt;
bool availableOffline;
Sheet({
required this.uuid,
required this.name,
required this.composer,
required this.updatedAt,
this.availableOffline = false,
});
/// Creates a [Sheet] from a JSON map returned by the API.
+7
View File
@@ -254,6 +254,13 @@ class ApiClient {
return cachedFile;
}
Future<bool> isPdfFileCached(String sheetUuid) async {
final cacheDir = await getTemporaryDirectory();
final cachedFile = File('${cacheDir.path}/$sheetUuid.pdf');
return await cachedFile.exists();
}
// ---------------------------------------------------------------------------
// Annotation Operations
// ---------------------------------------------------------------------------
+4
View File
@@ -125,6 +125,10 @@ class _HomePageState extends State<HomePage> with RouteAware {
_sheets = await _sortSheetsByRecency(result.sheets);
_isOnline = result.isOnline;
for (var sheet in _sheets) {
sheet.availableOffline = await _apiClient!.isPdfFileCached(sheet.uuid);
}
return result;
}
@@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart';
import '../../../core/models/sheet.dart';
/// A list tile displaying a single sheet's information.
@@ -24,6 +25,10 @@ class SheetListItem extends StatelessWidget {
subtitle: Text(sheet.composer),
onTap: onTap,
onLongPress: onLongPress,
trailing: Visibility(
visible: !kIsWeb && sheet.availableOffline,
child: Icon(Icons.download_done, color: Colors.green),
),
);
}
}
@@ -98,6 +98,7 @@ class _SheetViewerPageState extends State<SheetViewerPage>
// Native: use file cache
final file = await widget.apiClient.getPdfFileCached(widget.sheet.uuid);
_document = await PdfDocument.openFile(file.path);
widget.sheet.availableOffline = true;
}
setState(() {