11import 'dart:io' ;
22
33import 'package:flutter/material.dart' ;
4+ import 'package:powersync_attachments_helper/powersync_attachments_helper.dart' ;
45import 'package:powersync_flutter_demo/attachments/camera_helpers.dart' ;
56import 'package:powersync_flutter_demo/attachments/photo_capture_widget.dart' ;
67import 'package:powersync_flutter_demo/attachments/queue.dart' ;
@@ -23,8 +24,10 @@ class PhotoWidget extends StatefulWidget {
2324class _ResolvedPhotoState {
2425 String ? photoPath;
2526 bool fileExists;
27+ Attachment ? attachment;
2628
27- _ResolvedPhotoState ({required this .photoPath, required this .fileExists});
29+ _ResolvedPhotoState (
30+ {required this .photoPath, required this .fileExists, this .attachment});
2831}
2932
3033class _PhotoWidgetState extends State <PhotoWidget > {
@@ -38,7 +41,17 @@ class _PhotoWidgetState extends State<PhotoWidget> {
3841
3942 bool fileExists = await File (photoPath).exists ();
4043
41- return _ResolvedPhotoState (photoPath: photoPath, fileExists: fileExists);
44+ final row = await attachmentQueue.db
45+ .getOptional ('SELECT * FROM attachments_queue WHERE id = ?' , [photoId]);
46+
47+ if (row != null ) {
48+ Attachment attachment = Attachment .fromRow (row);
49+ return _ResolvedPhotoState (
50+ photoPath: photoPath, fileExists: fileExists, attachment: attachment);
51+ }
52+
53+ return _ResolvedPhotoState (
54+ photoPath: photoPath, fileExists: fileExists, attachment: null );
4255 }
4356
4457 @override
@@ -84,6 +97,20 @@ class _PhotoWidgetState extends State<PhotoWidget> {
8497
8598 String ? filePath = data.photoPath;
8699 bool fileIsDownloading = ! data.fileExists;
100+ bool fileArchived =
101+ data.attachment? .state == AttachmentState .archived.index;
102+
103+ if (fileArchived) {
104+ return Column (
105+ crossAxisAlignment: CrossAxisAlignment .center,
106+ mainAxisAlignment: MainAxisAlignment .center,
107+ children: [
108+ const Text ("Unavailable" ),
109+ const SizedBox (height: 8 ),
110+ takePhotoButton
111+ ],
112+ );
113+ }
87114
88115 if (fileIsDownloading) {
89116 return const Text ("Downloading..." );
0 commit comments