call method
Make a call to the Wialon API
Implementation
Future<Map<String, dynamic>> call({
/// [method] is the svc method declarated in the Wialon SDK documentation
required String method,
/// [parameters] is the parameters of the method, should be a Map or a List
/// Refer to the documentation of the desired method to know the parameters
required dynamic parameters,
}) async {
dynamic arguments = {};
if (parameters is List) {
arguments = [...parameters];
} else {
arguments.addAll(parameters);
}
Map<String, dynamic> payload = {
'svc': method,
'params': jsonEncode(arguments),
'sid': sessionId ?? "",
};
if (debug) {
log('Method Call: ${payload["svc"]}');
log('Pararams: ${payload["params"]}');
log('SessionId: ${payload["sid"]}');
}
try {
http.Response response = await http.post(
Uri.parse(baseUrl),
body: payload,
);
return Map<String, dynamic>.from(jsonDecode(response.body));
} catch (e) {
throw SdkException(message: "Internal error: $e");
}
}