added quotes export to file
This commit is contained in:
@@ -18,4 +18,9 @@ class Quote{
|
||||
body: json['body'],
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return "$body - $author";
|
||||
}
|
||||
}
|
||||
@@ -274,8 +274,15 @@ class ListPage extends StatelessWidget {
|
||||
title: Text(Strings.exportSelectedQuotes),
|
||||
trailing: Icon(Icons.import_export),
|
||||
onTap: () {
|
||||
// TODO: trigger an os dialog FileSave
|
||||
},
|
||||
provider.exportQuotesToFile();
|
||||
Navigator.pop(context);
|
||||
ScaffoldMessenger.of(context).showSnackBar(
|
||||
SnackBar(
|
||||
content: Text(Strings.fileExportedSuccessfully),
|
||||
duration: const Duration(seconds: 3),
|
||||
),
|
||||
);
|
||||
}
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
// gets all quotes from the database and returns them in a list
|
||||
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'package:frontend/model/quote.dart';
|
||||
import 'package:frontend/repository/quote_repository.dart';
|
||||
import 'dart:math';
|
||||
import 'dart:io';
|
||||
|
||||
class QuoteProvider extends ChangeNotifier {
|
||||
List<Quote> _quotes = [];
|
||||
@@ -149,4 +151,30 @@ class QuoteProvider extends ChangeNotifier {
|
||||
populateAuthors();
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
|
||||
Future<Directory> _getSaveDirectory() async {
|
||||
if (Platform.isWindows || Platform.isLinux || Platform.isMacOS) {
|
||||
final path = Platform.isWindows
|
||||
? Platform.environment['USERPROFILE']
|
||||
: Platform.environment['HOME'];
|
||||
|
||||
return Directory(path!);
|
||||
}
|
||||
|
||||
// Mobile fallback
|
||||
return await getApplicationDocumentsDirectory();
|
||||
}
|
||||
|
||||
Future<void> exportQuotesToFile() async {
|
||||
final dir = await _getSaveDirectory();
|
||||
|
||||
final datetime = DateTime.now().toUtc().toString()
|
||||
.replaceAll(" ", "T")
|
||||
.replaceAll(":", "-")
|
||||
.replaceAll(RegExp(r"\..*"), "");
|
||||
|
||||
final file = File('${dir.path}/hlasky_$datetime.txt');
|
||||
await file.writeAsString("${filteredQuotes.join("\n")}\n");
|
||||
}
|
||||
}
|
||||
@@ -22,6 +22,7 @@ class Strings {
|
||||
static const String flipFlashcard = "Otočit flashkartu";
|
||||
static const String nextFlashcard = "Další flashkarta";
|
||||
|
||||
static const String fileExportedSuccessfully = "Soubor byl úspěšně vyexportován.";
|
||||
static const String noUndo = "Tuto akci nelze odčinit.";
|
||||
static const String filterQuery = "Filtrovací požadavek";
|
||||
static const String allQuotesCount = "Celkový počet hlášek";
|
||||
|
||||
Reference in New Issue
Block a user