~repos /only-bible-app

#kotlin#android#ios

GIT_CONFIG_PARAMETERS="'http.version=HTTP/1.1'" git clone https://git.pyrossh.dev/only-bible-app.git
Discussions: https://groups.google.com/g/rust-embed-devs

The only bible app you will ever need. No ads. No in-app purchases. No distractions.



lib/store/app_persistor.dart



import "dart:convert";
import "dart:io";
import "package:path_provider/path_provider.dart";
import "package:async_redux/async_redux.dart";
import "package:only_bible_app/store/app_state.dart";
class AppPersistor extends Persistor<AppState> {
static const _fileName = "app_state.json";
Future<File> get _file async {
final dir = await getApplicationDocumentsDirectory();
return File("${dir.path}/$_fileName");
}
@override
Future<AppState?> readState() async {
return null;
}
Future<Map<String, dynamic>?> readJson() async {
try {
final file = await _file;
if (await file.exists()) {
final contents = await file.readAsString();
return jsonDecode(contents) as Map<String, dynamic>;
}
} catch (_) {}
return null;
}
@override
Future<void> deleteState() async {
final file = await _file;
if (await file.exists()) {
await file.delete();
}
}
@override
Future<void> persistDifference({
required AppState? lastPersistedState,
required AppState newState,
}) async {
final file = await _file;
final contents = jsonEncode(newState.toJson());
await file.writeAsString(contents);
}
@override
Duration? get throttle => const Duration(seconds: 1);
}