40 lines
1.2 KiB
Dart
40 lines
1.2 KiB
Dart
// This file holds a class to represent the configuration/settings of the app
|
|
|
|
import 'dart:io';
|
|
|
|
import 'package:json_annotation/json_annotation.dart';
|
|
import 'dart:convert';
|
|
import 'package:path_provider/path_provider.dart';
|
|
import 'package:path/path.dart' as path;
|
|
|
|
part 'generated/config.g.dart';
|
|
|
|
@JsonSerializable()
|
|
class RTimeConfig {
|
|
final String language;
|
|
|
|
RTimeConfig({required this.language});
|
|
|
|
factory RTimeConfig.fromJson(Map<String, dynamic> json) =>
|
|
_$RTimeConfigFromJson(json);
|
|
|
|
Map<String, dynamic> toJson() => _$RTimeConfigToJson(this);
|
|
|
|
static Future<RTimeConfig?> readFromConfig() async {
|
|
final directory = await getApplicationDocumentsDirectory();
|
|
final configName = "rtime_config.json";
|
|
final configPath = path.join(directory.path, configName);
|
|
|
|
final string = jsonDecode(await File(configPath).readAsString());
|
|
return RTimeConfig.fromJson(string);
|
|
}
|
|
|
|
void writeConfig() async {
|
|
final directory = await getApplicationDocumentsDirectory();
|
|
final configName = "rtime_config.json";
|
|
final configPath = path.join(directory.path, configName);
|
|
|
|
await File(configPath).writeAsString(jsonEncode(toJson()));
|
|
}
|
|
}
|