getUnReadCount method
dynamic
getUnReadCount()
Implementation
getUnReadCount() async {
HttpWithMiddleware http = HttpWithMiddleware.build(middlewares: [
HttpLogger(logLevel: LogLevel.BODY),
]);
final url = Uri.parse(API_URL + un_read_notification_count);
SessionManager sessionManager = SessionManager();
Map<String, String> jsonBody = {
'logged_in_master_user_id': sessionManager.getMasterUserId().toString(),
'from_application' : IS_FROM_APP
};
final response = await http.post(url, body: jsonBody, headers: {
"Authorization": sessionManager.getAuthToken().toString().trim(),
});
final statusCode = response.statusCode;
final body = response.body;
Map<String, dynamic> apiResponse = jsonDecode(body);
var dataResponse = UnReadNotificationCount.fromJson(apiResponse);
if (statusCode == 200 && dataResponse.success == 1) {
if (dataResponse.unReadTotal != null) {
if (int.parse(checkValidString(dataResponse.unReadTotal)) > 0) {
sessionManager.setUnreadNotificationCount(int.parse(checkValidString(dataResponse.unReadTotal)));
} else {
sessionManager.setUnreadNotificationCount(0);
}
} else {
sessionManager.setUnreadNotificationCount(0);
}
} else {
sessionManager.setUnreadNotificationCount(0);
}
}