Skip to content

Commit

Permalink
Merge pull request #6 from RowEchelonForm/import-encoding-fix
Browse files Browse the repository at this point in the history
Fix encoding when importing recipies
  • Loading branch information
judemont authored May 30, 2024
2 parents 9dbad5c + 5587924 commit 81985d4
Showing 1 changed file with 10 additions and 6 deletions.
16 changes: 10 additions & 6 deletions lib/utilities/utils.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'dart:convert';
import 'dart:io';
import 'package:pdf/pdf.dart';
import 'package:pdf/widgets.dart' as pw;
Expand All @@ -8,6 +9,8 @@ import 'package:reciper/utilities/database.dart';
import 'package:share_plus/share_plus.dart';

class Utils {
static const Encoding _textFileEncoding = utf8;

static Future<void> userExport() async {
Directory directory = await getTemporaryDirectory();
String appDocumentsPath = directory.path;
Expand All @@ -16,10 +19,10 @@ class Utils {
File file = File(filePath);

DatabaseService db = DatabaseService();
db.export().then((String result) {
file.writeAsString(result);
Share.shareXFiles([XFile(filePath)]);
});
String result = await db.export();
var fileBytes = _textFileEncoding.encode(result);
await file.writeAsBytes(fileBytes);
await Share.shareXFiles([XFile(filePath)]);
}

static Future<int> userImport() async {
Expand All @@ -31,9 +34,10 @@ class Utils {
await openFile(acceptedTypeGroups: <XTypeGroup>[typeGroup]);

if (file != null) {
String backupContent = await file.readAsString();
var fileBytes = await file.readAsBytes();
String backupContent = _textFileEncoding.decode(fileBytes);
DatabaseService db = DatabaseService();
db.import(backupContent);
await db.import(backupContent);
}
return 1;
}
Expand Down

0 comments on commit 81985d4

Please sign in to comment.