checkVersion method
Implementation
Future<
(
VersionStatus status,
ApplicationVersion lastVersion,
ApplicationVersion? updateVersion
)>
checkVersion({required String appToken, required String apiKey}) async {
try {
final info = await PackageInfo.fromPlatform();
final response = await http.post(
Uri.parse("$apiUrl/applications/$appToken/check"),
body: jsonEncode({
"current_version": info.version,
"platform": Platform.operatingSystem.toLowerCase(),
}),
headers: {"Api-Key": apiKey, "Content-Type": "application/json"},
);
if (response.statusCode != 200) {
throw Exception(response.body);
}
final body = jsonDecode(response.body);
return (
VersionStatus.values
.where(
(element) => camelToSnakeCase(element.name) == body["status"])
.first,
ApplicationVersion.fromJson(body["last_version"]),
body["update_version"] != null
? ApplicationVersion.fromJson(body["update_version"])
: null
);
} catch (e) {
rethrow;
}
}