replaceStringJsonPathAsync function
Implementation
Future<String> replaceStringJsonPathAsync(
String value, Map<String, dynamic> document,
{bool? localized = true}) async {
if (value.contains('{\$.device.position}')) {
try {
var position = await determinePosition();
print("position: {$position}");
//lmLog(position);
value = value.replaceFirst(
'{\$.device.position}', '${position.latitude},${position.longitude}');
} catch (e) {
lmLog(e, level: 1);
}
}
if (value.contains('{\$.device.currentTime}')) {
try {
// Get the current device time
var currentTime = DateTime.now();
print("currentTime: ${currentTime.toIso8601String()}");
// Replace the placeholder with the current time
value = value.replaceFirst(
'{\$.device.currentTime}', currentTime.toIso8601String());
} catch (e) {
lmLog(e, level: 1);
}
}
if (value.contains('{\$.device.language}')) {
try {
// Get the current device time
String language = AppSettings().language ?? "en-us";
print("language: language");
// Replace the placeholder with the current time
value = value.replaceFirst('{\$.device.language}', language);
} catch (e) {
lmLog(e, level: 1);
}
}
String data = replaceStringJsonPath(value, document, localized: localized);
return data;
}