Copy Note to clipboard when it cannot be saved

Also avoid showing the actual exception. It's not very useful to the
user, and we're logging the exception to Sentry anyway.

Related to #124
This commit is contained in:
Vishesh Handa
2020-07-13 17:27:39 +02:00
parent 84fab89f48
commit b14e094e59
3 changed files with 11 additions and 3 deletions

View File

@ -62,7 +62,9 @@ editors:
addImage: Add Image from Gallery
editFileName: Edit File Name
tags: Edit Tags
saveNoteFailed: Failed to Save Note
saveNoteFailed:
title: Failed to Save Note
message: We're sorry, but we cannot seem to save the Note. It has been copied to the clipboard to avoid data loss.
pro: Pro
actions:
newNote: New Note

View File

@ -303,6 +303,10 @@ class Note with NotesNotifier {
await file.writeAsString(contents);
}
String serialize() {
return _serializer.encode(data);
}
// FIXME: What about error handling?
Future<void> remove() async {
assert(_filePath != null);

View File

@ -3,6 +3,7 @@ import 'dart:io';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:collection/collection.dart';
import 'package:flutter/services.dart';
import 'package:gitjournal/core/note.dart';
import 'package:gitjournal/core/md_yaml_doc.dart';
@ -331,11 +332,12 @@ class NoteEditorState extends State<NoteEditor> {
: await stateContainer.updateNote(note);
} catch (e, stackTrace) {
logException(e, stackTrace);
Clipboard.setData(ClipboardData(text: note.serialize()));
await showAlertDialog(
context,
tr("editors.common.saveNoteFailed"),
e.toString(),
tr("editors.common.saveNoteFailed.title"),
tr("editors.common.saveNoteFailed.message"),
);
return false;
}