37 lines
1.2 KiB
Dart
37 lines
1.2 KiB
Dart
library makerbook.utils.global;
|
|
|
|
import 'dart:convert';
|
|
import 'dart:io';
|
|
|
|
import 'package:path_provider/path_provider.dart';
|
|
|
|
// Variáveis globais
|
|
String apiEndpoint = "http://54.94.231.207:3035/api";
|
|
String bookPath = "http://54.94.231.207/maker_book/materials/";
|
|
String epub_Key = "d8df841b92a6cbedbb26f3d06dbde1c9";
|
|
|
|
Future<String?> getLastLocation(int book_id) async {
|
|
String? lastLocation = null;
|
|
final directoryReal = await getApplicationDocumentsDirectory();
|
|
print("[LOG] Diretorio Json: ${'${directoryReal.path}/${book_id}.json'}");
|
|
final jsonFile = File('${directoryReal.path}/${book_id}.json');
|
|
if (await jsonFile.exists()) {
|
|
final jsonData = jsonDecode(await jsonFile.readAsString());
|
|
lastLocation = jsonData['lastLocation'];
|
|
print("[LOG] Last Location: ${lastLocation}");
|
|
}
|
|
return lastLocation;
|
|
}
|
|
|
|
Future<void> saveLastLocation(int book_id, String? lastLocation) async {
|
|
if (lastLocation == null) return;
|
|
final directory = await getApplicationDocumentsDirectory();
|
|
final file = File('${directory.path}/${book_id}.json');
|
|
Map<String, dynamic> data = {};
|
|
if (await file.exists()) {
|
|
data = jsonDecode(await file.readAsString());
|
|
}
|
|
data['lastLocation'] = lastLocation;
|
|
await file.writeAsString(jsonEncode(data));
|
|
}
|