Skip to content

Commit

Permalink
Retry reading image in journal card
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasn committed Jul 12, 2022
1 parent da8c040 commit 2543bd4
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 41 deletions.
4 changes: 0 additions & 4 deletions lib/sync/inbox/save_attachments.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ Future<void> saveImageAttachment(
JournalImage? journalImage,
String? b64Secret,
) async {
final loggingDb = getIt<LoggingDb>();
final transaction =
loggingDb.startTransaction('saveImageAttachment()', 'task');
final attachments = message.findContentInfo();

for (final attachment in attachments) {
Expand All @@ -62,7 +59,6 @@ Future<void> saveImageAttachment(
await decryptFile(encrypted, File(filePath), b64Secret);
}
}
await transaction.finish();
}

Future<void> writeToFile(Uint8List? data, String filePath) async {
Expand Down
16 changes: 15 additions & 1 deletion lib/widgets/journal/card_image_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class CardImageWidget extends StatefulWidget {

class _CardImageWidgetState extends State<CardImageWidget> {
Directory? docDir;
int retries = 0;

@override
void initState() {
Expand All @@ -38,10 +39,23 @@ class _CardImageWidgetState extends State<CardImageWidget> {
@override
Widget build(BuildContext context) {
if (docDir != null) {
final file =
final file =
File(getFullImagePathWithDocDir(widget.journalImage, docDir!));

if (retries < 10 && !file.existsSync()) {
Future<void>.delayed(const Duration(milliseconds: 200)).then((_) {
setState(() {
retries++;
});
});
}

if (!file.existsSync()) {
return Container();
}

return Container(
key: Key('${file.path}-$retries'),
color: Colors.black,
height: widget.height.toDouble(),
child: Image.file(
Expand Down
61 changes: 26 additions & 35 deletions lib/widgets/journal/journal_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -219,43 +219,34 @@ class JournalImageCard extends StatelessWidget {

@override
Widget build(BuildContext context) {
return BlocBuilder<AudioPlayerCubit, AudioPlayerState>(
builder: (BuildContext context, AudioPlayerState state) {
return Card(
color: colorConfig().entryCardColor,
elevation: 8,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
child: ClipRRect(
borderRadius: BorderRadius.circular(8),
child: GFListTile(
margin: EdgeInsets.zero,
padding: const EdgeInsets.only(right: 8),
avatar: LimitedBox(
maxWidth: (MediaQuery.of(context).size.width / 2) - 40,
child: CardImageWidget(
journalImage: item,
height: 160,
fit: BoxFit.cover,
),
),
title: SizedBox(
height: 160,
child: JournalCardTitle(item: item),
),
onTap: () {
item.mapOrNull(
journalAudio: (JournalAudio audioNote) {
context.read<AudioPlayerCubit>().setAudioNote(audioNote);
},
);
pushNamedRoute('/journal/${item.meta.id}');
},
return Card(
color: colorConfig().entryCardColor,
elevation: 8,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(8),
),
child: ClipRRect(
borderRadius: BorderRadius.circular(8),
child: GFListTile(
margin: EdgeInsets.zero,
padding: const EdgeInsets.only(right: 8),
avatar: LimitedBox(
maxWidth: (MediaQuery.of(context).size.width / 2) - 40,
child: CardImageWidget(
journalImage: item,
height: 160,
fit: BoxFit.cover,
),
),
);
},
title: SizedBox(
height: 160,
child: JournalCardTitle(item: item),
),
onTap: () {
pushNamedRoute('/journal/${item.meta.id}');
},
),
),
);
}
}
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: lotti
description: A Smart Journal.
publish_to: 'none'
version: 0.8.102+1150
version: 0.8.102+1151

msix_config:
display_name: Lotti
Expand Down

0 comments on commit 2543bd4

Please sign in to comment.