added quotes export to file
This commit is contained in:
@@ -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");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user