From 0f18ce3873bff51b5ae25ce35fda84901d081f1b Mon Sep 17 00:00:00 2001 From: Nikhil Rajput Date: Thu, 10 Nov 2022 04:18:09 +0530 Subject: [PATCH] updated to version 1.0.1+24 --- lib/apis/providers/api_provider.dart | 592 ++++++++++-------- lib/apis/services/auth_service.dart | 88 +-- lib/e2ee/signal_protocol_manager.dart | 12 +- lib/extensions/date_extensions.dart | 12 +- .../reactivate_account_controller.dart | 82 +-- .../chat/controllers/p2p_chat_controller.dart | 2 +- .../chat/widgets/chat_bubble_widget.dart | 65 +- .../followers_list_controller.dart | 122 +--- .../following_list_controller.dart | 115 +--- .../home/controllers/profile_controller.dart | 36 +- .../post/controllers/comment_controller.dart | 111 +--- .../create_comment_controller.dart | 36 +- .../controllers/create_post_controller.dart | 96 ++- .../controllers/post_details_controller.dart | 40 +- .../post_liked_users_controller.dart | 25 +- .../controllers/edit_about_controller.dart | 36 +- .../controllers/edit_dob_controller.dart | 40 +- .../controllers/edit_gender_controller.dart | 40 +- .../controllers/edit_name_controller.dart | 36 +- .../edit_profession_controller.dart | 42 +- .../edit_profile_picture_controller.dart | 177 +----- .../controllers/edit_username_controller.dart | 72 +-- .../controllers/edit_website_controller.dart | 40 +- .../account_privacy_controller.dart | 46 +- .../controllers/change_email_controller.dart | 78 +-- .../change_password_controller.dart | 44 +- .../controllers/change_phone_controller.dart | 78 +-- .../deactivate_account_controller.dart | 42 +- lib/modules/user/user_details_controller.dart | 66 +- .../verify_password_controller.dart | 39 +- lib/utils/file_utility.dart | 26 + 31 files changed, 696 insertions(+), 1640 deletions(-) diff --git a/lib/apis/providers/api_provider.dart b/lib/apis/providers/api_provider.dart index e65e38b..8df01ec 100644 --- a/lib/apis/providers/api_provider.dart +++ b/lib/apis/providers/api_provider.dart @@ -309,242 +309,231 @@ class ApiProvider { return response; } - Future getPreKeyBundle(String token, String userId) async { - final response = await _client.get( - Uri.parse('${baseUrl!}${AppUrls.preKeyBundleEndpoint}?id=$userId'), - headers: { - "content-type": "application/json", - "authorization": "Bearer $token", - }, + Future getPreKeyBundle(String token, String userId) async { + var queryParameters = {}; + queryParameters['id'] = userId; + + final response = await _catchAsyncApiError( + endPoint: AppUrls.preKeyBundleEndpoint, + method: 'GET', + feature: 'Get Pre Key Bundle', + headers: {"authorization": "Bearer $token"}, + queryParams: queryParameters, ); return response; } - Future savePreKeyBundle( + Future savePreKeyBundle( String token, Map body) async { - final response = await _client.post( - Uri.parse('${baseUrl!}${AppUrls.preKeyBundleEndpoint}'), - headers: { - "content-type": "application/json", - "authorization": "Bearer $token", - }, - body: jsonEncode(body), + final response = await _catchAsyncApiError( + endPoint: AppUrls.preKeyBundleEndpoint, + method: 'POST', + body: body, + feature: 'Save Pre Key Bundle', + headers: {"authorization": "Bearer $token"}, ); return response; } - Future getDeviceId(String token, String userId) async { - final response = await _client.get( - Uri.parse('${baseUrl!}${AppUrls.deviceIdEndpoint}?id=$userId'), - headers: { - "content-type": "application/json", - "authorization": "Bearer $token", - }, + Future getDeviceId(String token, String userId) async { + var queryParameters = {}; + queryParameters['id'] = userId; + + final response = await _catchAsyncApiError( + endPoint: AppUrls.deviceIdEndpoint, + method: 'GET', + feature: 'Get Device Id', + headers: {"authorization": "Bearer $token"}, + queryParams: queryParameters, ); return response; } - Future saveDeviceId( + Future saveDeviceId( String token, Map body) async { - final response = await _client.post( - Uri.parse('${baseUrl!}${AppUrls.deviceIdEndpoint}'), - headers: { - "content-type": "application/json", - "authorization": "Bearer $token", - }, - body: jsonEncode(body), + final response = await _catchAsyncApiError( + endPoint: AppUrls.deviceIdEndpoint, + method: 'POST', + body: body, + feature: 'Save Device Id', + headers: {"authorization": "Bearer $token"}, ); return response; } - Future saveFcmToken(String token, String fcmToken) async { - final response = await _client.post( - Uri.parse('${baseUrl!}${AppUrls.fcmTokenEndpoint}'), - headers: { - "content-type": "application/json", - "authorization": "Bearer $token", - }, - body: jsonEncode({ - "fcmToken": fcmToken, - }), + Future saveFcmToken(String token, String fcmToken) async { + final response = await _catchAsyncApiError( + endPoint: AppUrls.fcmTokenEndpoint, + method: 'POST', + body: {"fcmToken": fcmToken}, + feature: 'Save FCM Token', + headers: {"authorization": "Bearer $token"}, ); return response; } - Future uploadProfilePicture( + Future uploadProfilePicture( String token, Map body, ) async { - final response = await _client.post( - Uri.parse(baseUrl! + AppUrls.uploadProfilePicEndpoint), - headers: { - "content-type": "application/json", - "authorization": "Bearer $token", - }, - body: jsonEncode(body), + final response = await _catchAsyncApiError( + endPoint: AppUrls.uploadProfilePicEndpoint, + method: 'POST', + body: body, + feature: 'Upload Profile Picture', + headers: {"authorization": "Bearer $token"}, ); return response; } - Future deleteProfilePicture(String token) async { - final response = await _client.delete( - Uri.parse('${baseUrl!}${AppUrls.deleteProfilePicEndpoint}'), - headers: { - "content-type": "application/json", - "authorization": "Bearer $token", - }, + Future deleteProfilePicture(String token) async { + final response = await _catchAsyncApiError( + endPoint: AppUrls.deleteProfilePicEndpoint, + method: 'DELETE', + feature: 'Delete Profile Picture', + headers: {"authorization": "Bearer $token"}, ); return response; } - Future updateProfile( + Future updateProfile( String token, Map body) async { - final response = await _client.put( - Uri.parse('${baseUrl!}${AppUrls.updateProfileEndpoint}'), - headers: { - "content-type": "application/json", - "authorization": "Bearer $token", - }, - body: jsonEncode(body), + final response = await _catchAsyncApiError( + endPoint: AppUrls.updateProfileEndpoint, + method: 'PUT', + body: body, + feature: 'Update Profile', + headers: {"authorization": "Bearer $token"}, ); return response; } - Future changePassword( + Future changePassword( String token, Map body) async { - final response = await _client.post( - Uri.parse('${baseUrl!}${AppUrls.changePasswordEndpoint}'), - headers: { - "content-type": "application/json", - "authorization": "Bearer $token", - }, - body: jsonEncode(body), + final response = await _catchAsyncApiError( + endPoint: AppUrls.changePasswordEndpoint, + method: 'POST', + body: body, + feature: 'Change Password', + headers: {"authorization": "Bearer $token"}, ); return response; } - Future sendChangeEmailOtp( + Future sendChangeEmailOtp( String token, Map body, ) async { - final response = await _client.post( - Uri.parse('${baseUrl!}${AppUrls.changeEmailEndpoint}'), - headers: { - "content-type": "application/json", - "authorization": "Bearer $token", - }, - body: jsonEncode(body), + final response = await _catchAsyncApiError( + endPoint: AppUrls.changeEmailEndpoint, + method: 'POST', + body: body, + feature: 'Send Change Email OTP', + headers: {"authorization": "Bearer $token"}, ); return response; } - Future changeEmail( + Future changeEmail( String token, Map body, ) async { - final response = await _client.put( - Uri.parse('${baseUrl!}${AppUrls.changeEmailEndpoint}'), - headers: { - "content-type": "application/json", - "authorization": "Bearer $token", - }, - body: jsonEncode(body), + final response = await _catchAsyncApiError( + endPoint: AppUrls.changeEmailEndpoint, + method: 'PUT', + body: body, + feature: 'Change Email', + headers: {"authorization": "Bearer $token"}, ); return response; } - Future sendAddChangePhoneOtp( + Future sendAddChangePhoneOtp( String token, Map body, ) async { - final response = await _client.post( - Uri.parse('${baseUrl!}${AppUrls.addChangePhoneEndpoint}'), - headers: { - "content-type": "application/json", - "authorization": "Bearer $token", - }, - body: jsonEncode(body), + final response = await _catchAsyncApiError( + endPoint: AppUrls.addChangePhoneEndpoint, + method: 'POST', + body: body, + feature: 'Send Add/Change Phone OTP', + headers: {"authorization": "Bearer $token"}, ); return response; } - Future addChangePhone( + Future addChangePhone( String token, Map body, ) async { - final response = await _client.put( - Uri.parse('${baseUrl!}${AppUrls.addChangePhoneEndpoint}'), - headers: { - "content-type": "application/json", - "authorization": "Bearer $token", - }, - body: jsonEncode(body), + final response = await _catchAsyncApiError( + endPoint: AppUrls.addChangePhoneEndpoint, + method: 'PUT', + body: body, + feature: 'Add/Change Phone', + headers: {"authorization": "Bearer $token"}, ); return response; } - Future verifyPassword(String token, String password) async { - final response = await _client.post( - Uri.parse('${baseUrl!}${AppUrls.verifyPasswordEndpoint}'), - headers: { - "content-type": "application/json", - "authorization": "Bearer $token", - }, - body: jsonEncode({"password": password}), + Future verifyPassword(String token, String password) async { + final response = await _catchAsyncApiError( + endPoint: AppUrls.verifyPasswordEndpoint, + method: 'POST', + body: {"password": password}, + feature: 'Verify Password', + headers: {"authorization": "Bearer $token"}, ); return response; } - Future deactivateAccount( + Future deactivateAccount( String token, Map body, ) async { - final response = await _client.post( - Uri.parse('${baseUrl!}${AppUrls.deactivateAccountEndpoint}'), - headers: { - "content-type": "application/json", - "authorization": "Bearer $token", - }, - body: jsonEncode(body), + final response = await _catchAsyncApiError( + endPoint: AppUrls.deactivateAccountEndpoint, + method: 'POST', + body: body, + feature: 'Deactivate Account', + headers: {"authorization": "Bearer $token"}, ); return response; } - Future sendReactivateAccountOtp( + Future sendReactivateAccountOtp( Map body) async { - final response = await _client.post( - Uri.parse('${baseUrl!}${AppUrls.reactivateAccountEndpoint}'), - headers: { - "content-type": "application/json", - }, - body: jsonEncode(body), + final response = await _catchAsyncApiError( + endPoint: AppUrls.reactivateAccountEndpoint, + method: 'POST', + body: body, + feature: 'Send Reactivate Account OTP', ); return response; } - Future reactivateAccount(Map body) async { - final response = await _client.put( - Uri.parse('${baseUrl!}${AppUrls.reactivateAccountEndpoint}'), - headers: { - "content-type": "application/json", - }, - body: jsonEncode(body), + Future reactivateAccount(Map body) async { + final response = await _catchAsyncApiError( + endPoint: AppUrls.reactivateAccountEndpoint, + method: 'PUT', + body: body, + feature: 'Reactivate Account', ); return response; @@ -552,15 +541,14 @@ class ApiProvider { /// Post --------------------------------------------------------------------- - Future createPost( + Future createPost( String token, Map body) async { - final response = await _client.post( - Uri.parse(baseUrl! + AppUrls.createPostEndpoint), - headers: { - "content-type": "application/json", - "authorization": "Bearer $token", - }, - body: jsonEncode(body), + final response = await _catchAsyncApiError( + endPoint: AppUrls.createPostEndpoint, + method: 'POST', + body: body, + feature: 'Create Post', + headers: {"authorization": "Bearer $token"}, ); return response; @@ -588,15 +576,26 @@ class ApiProvider { return response; } - Future getPostsByTag(String token, + Future getPostsByTag(String token, String tag, {int? page, int? limit}) async { - final response = await _client.get( - Uri.parse( - '${baseUrl! + AppUrls.getPostsByTagEndpoint}?page=$page&limit=$limit'), - headers: { - "content-type": "application/json", - "authorization": "Bearer $token", - }, + var queryParameters = {}; + + queryParameters['q'] = tag; + + if (page != null) { + queryParameters['page'] = page.toString(); + } + + if (limit != null) { + queryParameters['limit'] = limit.toString(); + } + + final response = await _catchAsyncApiError( + endPoint: AppUrls.getPostsByTagEndpoint, + method: 'GET', + feature: 'Get Posts By Tag', + headers: {"authorization": "Bearer $token"}, + queryParams: queryParameters, ); return response; @@ -614,13 +613,13 @@ class ApiProvider { return response; } - Future getPostLikedUsers(String token, String postId) async { - final response = await _client.get( - Uri.parse('${baseUrl!}${AppUrls.getPostLikedUsersEndpoint}?id=$postId'), - headers: { - "content-type": "application/json", - "authorization": "Bearer $token", - }, + Future getPostLikedUsers(String token, String postId) async { + final response = await _catchAsyncApiError( + endPoint: AppUrls.getPostLikedUsersEndpoint, + method: 'GET', + feature: 'Get Post Liked Users', + headers: {"authorization": "Bearer $token"}, + queryParams: {'id': postId}, ); return response; @@ -775,26 +774,26 @@ class ApiProvider { return response; } - Future getUserDetailsById(String token, String userId) async { - final response = await _client.get( - Uri.parse('${baseUrl! + AppUrls.userDetailsEndpoint}?id=$userId'), - headers: { - "content-type": "application/json", - "authorization": "Bearer $token", - }, + Future getUserDetailsById(String token, String userId) async { + final response = await _catchAsyncApiError( + endPoint: AppUrls.userDetailsEndpoint, + method: 'GET', + feature: 'Get User Details By Id', + headers: {"authorization": "Bearer $token"}, + queryParams: {'id': userId}, ); return response; } - Future getUserDetailsByUsername( + Future getUserDetailsByUsername( String token, String username) async { - final response = await _client.get( - Uri.parse('${baseUrl! + AppUrls.userDetailsEndpoint}?username=$username'), - headers: { - "content-type": "application/json", - "authorization": "Bearer $token", - }, + final response = await _catchAsyncApiError( + endPoint: AppUrls.userDetailsEndpoint, + method: 'GET', + feature: 'Get User Details By Username', + headers: {"authorization": "Bearer $token"}, + queryParams: {'username': username}, ); return response; @@ -825,67 +824,87 @@ class ApiProvider { return response; } - Future checkUsername(String token, String uname) async { - final response = await _client.post( - Uri.parse(baseUrl! + AppUrls.checkUsernameEndpoint), - headers: { - "content-type": "application/json", - "authorization": "Bearer $token", - }, - body: jsonEncode({'uname': uname}), + Future checkUsername(String token, String uname) async { + final response = await _catchAsyncApiError( + endPoint: AppUrls.checkUsernameEndpoint, + method: 'GET', + feature: 'Check Username', + headers: {"authorization": "Bearer $token"}, + queryParams: {'username': uname}, ); return response; } - Future changeUsername(String token, String uname) async { - final response = await _client.post( - Uri.parse(baseUrl! + AppUrls.changeUsernameEndpoint), - headers: { - "content-type": "application/json", - "authorization": "Bearer $token", - }, - body: jsonEncode({'uname': uname}), + Future changeUsername(String token, String uname) async { + final response = await _catchAsyncApiError( + endPoint: AppUrls.changeUsernameEndpoint, + method: 'POST', + feature: 'Change Username', + headers: {"authorization": "Bearer $token"}, + body: {'username': uname}, ); return response; } - Future getFollowers(String token, String userId, + Future getFollowers(String token, String userId, {int? page, int? limit}) async { - final response = await _client.get( - Uri.parse( - '${baseUrl! + AppUrls.getFollowersEndpoint}?id=$userId&page=$page&limit=$limit'), - headers: { - "content-type": "application/json", - "authorization": "Bearer $token", - }, + var queryParameters = {}; + + queryParameters['id'] = userId; + + if (page != null) { + queryParameters['page'] = page.toString(); + } + + if (limit != null) { + queryParameters['limit'] = limit.toString(); + } + + final response = await _catchAsyncApiError( + endPoint: AppUrls.getFollowersEndpoint, + method: 'GET', + feature: 'Get Followers', + headers: {"authorization": "Bearer $token"}, + queryParams: queryParameters, ); return response; } - Future getFollowings(String token, String userId, + Future getFollowings(String token, String userId, {int? page, int? limit}) async { - final response = await _client.get( - Uri.parse( - '${baseUrl! + AppUrls.getFollowingEndpoint}?id=$userId&page=$page&limit=$limit'), - headers: { - "content-type": "application/json", - "authorization": "Bearer $token", - }, + var queryParameters = {}; + + queryParameters['id'] = userId; + + if (page != null) { + queryParameters['page'] = page.toString(); + } + + if (limit != null) { + queryParameters['limit'] = limit.toString(); + } + + final response = await _catchAsyncApiError( + endPoint: AppUrls.getFollowingEndpoint, + method: 'GET', + feature: 'Get Followings', + headers: {"authorization": "Bearer $token"}, + queryParams: queryParameters, ); return response; } - Future getPostDetails(String token, String postId) async { - final response = await _client.get( - Uri.parse('${baseUrl! + AppUrls.postEndpoint}?id=$postId'), - headers: { - "content-type": "application/json", - "authorization": "Bearer $token", - }, + Future getPostDetails(String token, String postId) async { + final response = await _catchAsyncApiError( + endPoint: AppUrls.postEndpoint, + method: 'GET', + feature: 'Get Post Details', + headers: {"authorization": "Bearer $token"}, + queryParams: {'id': postId}, ); return response; @@ -895,15 +914,26 @@ class ApiProvider { /// Search ------------------------------------------------------------------- - Future searchTag(String token, String text, + Future searchTag(String token, String text, {int? page, int? limit}) async { - final response = await _client.get( - Uri.parse( - '${baseUrl! + AppUrls.searchTagEndpoint}?q=$text&page=$page&limit=$limit'), - headers: { - "content-type": "application/json", - "authorization": "Bearer $token", - }, + var queryParameters = {}; + + queryParameters['q'] = text; + + if (page != null) { + queryParameters['page'] = page.toString(); + } + + if (limit != null) { + queryParameters['limit'] = limit.toString(); + } + + final response = await _catchAsyncApiError( + endPoint: AppUrls.searchTagEndpoint, + method: 'GET', + feature: 'Search Tag', + headers: {"authorization": "Bearer $token"}, + queryParams: queryParameters, ); return response; @@ -959,31 +989,54 @@ class ApiProvider { return response; } - Future searchFollowers( - String token, String userId, String text, + Future searchFollowers(String token, String userId, String text, {int? page, int? limit}) async { - final response = await _client.get( - Uri.parse( - '${baseUrl! + AppUrls.searchFollowersEndpoint}?id=$userId&q=$text&page=$page&limit=$limit'), - headers: { - "content-type": "application/json", - "authorization": "Bearer $token", - }, + var queryParameters = {}; + + queryParameters['id'] = userId; + queryParameters['q'] = text; + + if (page != null) { + queryParameters['page'] = page.toString(); + } + + if (limit != null) { + queryParameters['limit'] = limit.toString(); + } + + final response = await _catchAsyncApiError( + endPoint: AppUrls.searchFollowersEndpoint, + method: 'GET', + feature: 'Search Followers', + headers: {"authorization": "Bearer $token"}, + queryParams: queryParameters, ); return response; } - Future searchFollowings( + Future searchFollowings( String token, String userId, String text, {int? page, int? limit}) async { - final response = await _client.get( - Uri.parse( - '${baseUrl! + AppUrls.searchFollowingEndpoint}?id=$userId&q=$text&page=$page&limit=$limit'), - headers: { - "content-type": "application/json", - "authorization": "Bearer $token", - }, + var queryParameters = {}; + + queryParameters['id'] = userId; + queryParameters['q'] = text; + + if (page != null) { + queryParameters['page'] = page.toString(); + } + + if (limit != null) { + queryParameters['limit'] = limit.toString(); + } + + final response = await _catchAsyncApiError( + endPoint: AppUrls.searchFollowingEndpoint, + method: 'GET', + feature: 'Search Followings', + headers: {"authorization": "Bearer $token"}, + queryParams: queryParameters, ); return response; @@ -993,54 +1046,63 @@ class ApiProvider { /// Comment ------------------------------------------------------------------ - Future addComment( + Future addComment( String token, String postId, String comment) async { - final response = await _client.post( - Uri.parse('${baseUrl! + AppUrls.addCommentEndpoint}?postId=$postId'), - headers: { - "content-type": "application/json", - "authorization": "Bearer $token", - }, - body: jsonEncode({'comment': comment}), + final response = await _catchAsyncApiError( + endPoint: AppUrls.addCommentEndpoint, + method: 'POST', + feature: 'Add Comment', + headers: {"authorization": "Bearer $token"}, + body: {'postId': postId, 'text': comment}, ); return response; } - Future getComments(String token, String postId, + Future getComments(String token, String postId, {int? page, int? limit}) async { - final response = await _client.get( - Uri.parse( - '${baseUrl! + AppUrls.getCommentsEndpoint}?postId=$postId&page=$page&limit=$limit'), - headers: { - "content-type": "application/json", - "authorization": "Bearer $token", - }, + var queryParameters = {}; + + queryParameters['postId'] = postId; + + if (page != null) { + queryParameters['page'] = page.toString(); + } + + if (limit != null) { + queryParameters['limit'] = limit.toString(); + } + + final response = await _catchAsyncApiError( + endPoint: AppUrls.getCommentsEndpoint, + method: 'GET', + feature: 'Get Comments', + headers: {"authorization": "Bearer $token"}, + queryParams: queryParameters, ); return response; } - Future deleteComment(String token, String commentId) async { - final response = await _client.delete( - Uri.parse('${baseUrl! + AppUrls.deleteCommentEndpoint}?id=$commentId'), - headers: { - "content-type": "application/json", - "authorization": "Bearer $token", - }, + Future deleteComment(String token, String commentId) async { + final response = await _catchAsyncApiError( + endPoint: AppUrls.deleteCommentEndpoint, + method: 'DELETE', + feature: 'Delete Comment', + headers: {"authorization": "Bearer $token"}, + queryParams: {'id': commentId}, ); return response; } - Future likeUnlikeComment( - String token, String commentId) async { - final response = await _client.get( - Uri.parse('${baseUrl! + AppUrls.likeCommentEndpoint}?id=$commentId'), - headers: { - "content-type": "application/json", - "authorization": "Bearer $token", - }, + Future likeUnlikeComment(String token, String commentId) async { + final response = await _catchAsyncApiError( + endPoint: AppUrls.likeCommentEndpoint, + method: 'GET', + feature: 'Like Unlike Comment', + headers: {"authorization": "Bearer $token"}, + queryParams: {'id': commentId}, ); return response; diff --git a/lib/apis/services/auth_service.dart b/lib/apis/services/auth_service.dart index 73a6171..b8e75a7 100644 --- a/lib/apis/services/auth_service.dart +++ b/lib/apis/services/auth_service.dart @@ -1,6 +1,5 @@ import 'dart:async'; import 'dart:convert'; -import 'dart:io'; import 'dart:math' show Random; import 'package:connectivity/connectivity.dart'; @@ -235,101 +234,52 @@ class AuthService extends GetxService { } Future saveDeviceIdToServer(String deviceId) async { - AppUtility.log("Save DeviceId Request"); + var body = {'deviceId': deviceId}; try { - final response = await _apiProvider.saveDeviceId( - token, - {'deviceId': deviceId}, - ); + final response = await _apiProvider.saveDeviceId(token, body); - final decodedData = jsonDecode(utf8.decode(response.bodyBytes)); - - if (response.statusCode == 200) { - AppUtility.log("Save DeviceId Success"); - AppUtility.log(decodedData[StringValues.message], tag: 'info'); + if (response.isSuccessful) { + final decodedData = response.data; + AppUtility.log(decodedData[StringValues.message]); } else { - AppUtility.log("Save DeviceId Error"); + final decodedData = response.data; AppUtility.log(decodedData[StringValues.message], tag: 'error'); } - } on SocketException { - AppUtility.log("Save DeviceId Error"); - AppUtility.log(StringValues.internetConnError, tag: 'error'); - } on TimeoutException { - AppUtility.log("Save DeviceId Error"); - AppUtility.log(StringValues.connTimedOut, tag: 'error'); - } on FormatException catch (e) { - AppUtility.log("Save DeviceId Error"); - AppUtility.log('Format Exception: $e', tag: 'error'); } catch (exc) { - AppUtility.printLog("Save DeviceId Error"); - AppUtility.log('Error: $exc', tag: 'error'); + AppUtility.log('Error: ${exc.toString()}', tag: 'error'); } } Future savePreKeyBundle(Map preKeyBundle) async { - AppUtility.printLog("Save PreKeyBundle Request"); - + var body = {'preKeyBundle': preKeyBundle}; try { - final response = await _apiProvider.savePreKeyBundle( - _token, - {'preKeyBundle': preKeyBundle}, - ); - - final decodedData = jsonDecode(utf8.decode(response.bodyBytes)); + final response = await _apiProvider.savePreKeyBundle(_token, body); - if (response.statusCode == 200) { - AppUtility.printLog(decodedData[StringValues.message]); - AppUtility.printLog("Save PreKeyBundle Success"); + if (response.isSuccessful) { + final decodedData = response.data; + AppUtility.log(decodedData[StringValues.message]); } else { - AppUtility.printLog(decodedData[StringValues.message]); - AppUtility.printLog("Save PreKeyBundle Error"); + final decodedData = response.data; + AppUtility.log(decodedData[StringValues.message], tag: 'error'); } - } on SocketException { - AppUtility.printLog("Save PreKeyBundle Error"); - AppUtility.printLog(StringValues.internetConnError); - } on TimeoutException { - AppUtility.printLog("Save PreKeyBundle Error"); - AppUtility.printLog(StringValues.connTimedOut); - } on FormatException catch (e) { - AppUtility.log("Save DeviceId Error"); - AppUtility.log('Format Exception: $e', tag: 'error'); } catch (exc) { - AppUtility.printLog("Save DeviceId Error"); AppUtility.log('Error: $exc', tag: 'error'); } } Future saveFcmToken(String fcmToken) async { - AppUtility.log("Save FcmToken Request"); - try { - final response = await _apiProvider.saveFcmToken( - _token, - fcmToken, - ); - - final decodedData = jsonDecode(utf8.decode(response.bodyBytes)); + final response = await _apiProvider.saveFcmToken(_token, fcmToken); - if (response.statusCode == 200) { + if (response.isSuccessful) { + final decodedData = response.data; AppUtility.log(decodedData[StringValues.message]); - AppUtility.printLog("Save FcmToken Success"); } else { - AppUtility.log( - "Save FcmToken Error: ${decodedData[StringValues.message]}", - tag: 'error'); + final decodedData = response.data; + AppUtility.log("${decodedData[StringValues.message]}", tag: 'error'); } - } on SocketException { - AppUtility.log("Save FcmToken Error"); - AppUtility.log(StringValues.internetConnError); - } on TimeoutException { - AppUtility.log("Save FcmToken Error"); - AppUtility.log(StringValues.connTimedOut); - } on FormatException catch (e) { - AppUtility.log("Save DeviceId Error"); - AppUtility.log('Format Exception: $e', tag: 'error'); } catch (exc) { - AppUtility.printLog("Save DeviceId Error"); AppUtility.log('Error: $exc', tag: 'error'); } } diff --git a/lib/e2ee/signal_protocol_manager.dart b/lib/e2ee/signal_protocol_manager.dart index d6b3e1e..9d90f2b 100644 --- a/lib/e2ee/signal_protocol_manager.dart +++ b/lib/e2ee/signal_protocol_manager.dart @@ -34,14 +34,12 @@ class SignalProtocolManager { remoteAddress, ); - // Get preKeyBundleFromServer - AppUtility.printLog('Get PreKeyBundle Request'); + /// Get preKeyBundle From Server var response = await _apiProvider.getPreKeyBundle(_auth.token, remoteUserId); - final decodedData = jsonDecode(utf8.decode(response.bodyBytes)); - if (response.statusCode == 200) { - AppUtility.printLog('Get PreKeyBundle Success'); + if (response.isSuccessful) { + final decodedData = response.data; AppUtility.printLog(decodedData[StringValues.message]); var serverKey = ServerKey.fromJson(decodedData['data']['preKeyBundle']); var preKeyBundle = @@ -50,8 +48,8 @@ class SignalProtocolManager { var sessionCipher = SessionCipher.fromStore(store, remoteAddress); await store.storeSessionCipher(remoteUserId, sessionCipher); } else { - AppUtility.printLog('Get PreKeyBundle Error'); - AppUtility.printLog(decodedData[StringValues.message]); + final decodedData = response.data; + AppUtility.log(decodedData[StringValues.message], tag: 'error'); throw Exception(decodedData[StringValues.message]); } } diff --git a/lib/extensions/date_extensions.dart b/lib/extensions/date_extensions.dart index ac0961e..8edd529 100644 --- a/lib/extensions/date_extensions.dart +++ b/lib/extensions/date_extensions.dart @@ -31,19 +31,23 @@ extension DateHelper on DateTime { if (!is24Hour) { if (hr >= 13) { - hr -= 12; + hrStr = (hr - 12).toString(); + hrStr = hrStr.length == 1 ? '0$hrStr' : hrStr; } if (hr == 0) { - hr = 12; + hrStr = '12'; } - time = '$hr:$minStr'; - time += ' ${hr >= 12 ? 'PM' : 'AM'}'; + time = '$hrStr:$minStr'; } if (showSeconds) { time += ':$secStr'; } + if (!is24Hour) { + time += ' ${hr >= 12 ? 'PM' : 'AM'}'; + } + return time; } diff --git a/lib/modules/auth/controllers/reactivate_account_controller.dart b/lib/modules/auth/controllers/reactivate_account_controller.dart index 5bf60ed..0b258ad 100644 --- a/lib/modules/auth/controllers/reactivate_account_controller.dart +++ b/lib/modules/auth/controllers/reactivate_account_controller.dart @@ -1,6 +1,4 @@ import 'dart:async'; -import 'dart:convert'; -import 'dart:io'; import 'package:flutter/cupertino.dart'; import 'package:get/get.dart'; @@ -64,7 +62,6 @@ class ReactivateAccountController extends GetxController { 'password': password, }; - AppUtility.printLog("Send Reactivate Account OTP Request"); AppUtility.showLoadingDialog(); _isLoading.value = true; update(); @@ -72,10 +69,8 @@ class ReactivateAccountController extends GetxController { try { final response = await _apiProvider.sendReactivateAccountOtp(body); - final decodedData = jsonDecode(utf8.decode(response.bodyBytes)); - - if (response.statusCode == 200) { - AppUtility.printLog("Send Reactivate Account OTP Success"); + if (response.isSuccessful) { + final decodedData = response.data; AppUtility.closeDialog(); _isLoading.value = false; _otpSent.value = true; @@ -85,46 +80,21 @@ class ReactivateAccountController extends GetxController { StringValues.success, ); } else { + final decodedData = response.data; AppUtility.closeDialog(); _isLoading.value = false; update(); - AppUtility.printLog("Send Reactivate Account OTP Error"); AppUtility.showSnackBar( decodedData[StringValues.message], StringValues.error, ); } - } on SocketException { - AppUtility.closeDialog(); - _isLoading.value = false; - update(); - AppUtility.printLog("Send Reactivate Account OTP Error"); - AppUtility.printLog(StringValues.internetConnError); - AppUtility.showSnackBar( - StringValues.internetConnError, StringValues.error); - } on TimeoutException { - AppUtility.closeDialog(); - _isLoading.value = false; - update(); - AppUtility.printLog("Send Reactivate Account OTP Error"); - AppUtility.printLog(StringValues.connTimedOut); - AppUtility.showSnackBar(StringValues.connTimedOut, StringValues.error); - } on FormatException catch (e) { - AppUtility.closeDialog(); - _isLoading.value = false; - update(); - AppUtility.printLog("Send Reactivate Account OTP Error"); - AppUtility.printLog(StringValues.formatExcError); - AppUtility.printLog(e); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); } catch (exc) { AppUtility.closeDialog(); _isLoading.value = false; update(); - AppUtility.printLog("Send Reactivate Account OTP Error"); - AppUtility.printLog(StringValues.errorOccurred); - AppUtility.printLog(exc); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); + AppUtility.log('Error: $exc', tag: 'error'); + AppUtility.showSnackBar('Error: $exc', StringValues.error); } } @@ -143,7 +113,6 @@ class ReactivateAccountController extends GetxController { 'otp': otp, }; - AppUtility.printLog("Reactivate Account Request"); AppUtility.showLoadingDialog(); _isLoading.value = true; update(); @@ -151,14 +120,12 @@ class ReactivateAccountController extends GetxController { try { final response = await _apiProvider.reactivateAccount(body); - final decodedData = jsonDecode(utf8.decode(response.bodyBytes)); - - if (response.statusCode == 200) { + if (response.isSuccessful) { + final decodedData = response.data; _clearTextControllers(); AppUtility.closeDialog(); _isLoading.value = false; update(); - AppUtility.printLog("Reactivate Account Success"); RouteManagement.goToBack(); RouteManagement.goToLoginView(); AppUtility.showSnackBar( @@ -166,46 +133,19 @@ class ReactivateAccountController extends GetxController { StringValues.success, ); } else { + final decodedData = response.data; AppUtility.closeDialog(); _isLoading.value = false; update(); - AppUtility.printLog("Reactivate Account Error"); AppUtility.showSnackBar( - decodedData[StringValues.message], - StringValues.error, - ); + decodedData[StringValues.message], StringValues.error); } - } on SocketException { - AppUtility.closeDialog(); - _isLoading.value = false; - update(); - AppUtility.printLog("Reactivate Account Error"); - AppUtility.printLog(StringValues.internetConnError); - AppUtility.showSnackBar( - StringValues.internetConnError, StringValues.error); - } on TimeoutException { - AppUtility.closeDialog(); - _isLoading.value = false; - update(); - AppUtility.printLog("Reactivate Account Error"); - AppUtility.printLog(StringValues.connTimedOut); - AppUtility.showSnackBar(StringValues.connTimedOut, StringValues.error); - } on FormatException catch (e) { - AppUtility.closeDialog(); - _isLoading.value = false; - update(); - AppUtility.printLog("Reactivate Account Error"); - AppUtility.printLog(StringValues.formatExcError); - AppUtility.printLog(e); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); } catch (exc) { AppUtility.closeDialog(); _isLoading.value = false; update(); - AppUtility.printLog("Reactivate Account Error"); - AppUtility.printLog(StringValues.errorOccurred); - AppUtility.printLog(exc); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); + AppUtility.log('Error: $exc', tag: 'error'); + AppUtility.showSnackBar('Error: $exc', StringValues.error); } } diff --git a/lib/modules/chat/controllers/p2p_chat_controller.dart b/lib/modules/chat/controllers/p2p_chat_controller.dart index 3e5e6ac..164a652 100644 --- a/lib/modules/chat/controllers/p2p_chat_controller.dart +++ b/lib/modules/chat/controllers/p2p_chat_controller.dart @@ -212,7 +212,7 @@ class P2PChatController extends GetxController { "mediaType": "image" }; } catch (err) { - AppUtility.log(err); + AppUtility.log('Image upload failed. Error: $err', tag: 'error'); AppUtility.showSnackBar('Image upload failed.', StringValues.error); return null; } diff --git a/lib/modules/chat/widgets/chat_bubble_widget.dart b/lib/modules/chat/widgets/chat_bubble_widget.dart index ff70b3e..6ad246c 100644 --- a/lib/modules/chat/widgets/chat_bubble_widget.dart +++ b/lib/modules/chat/widgets/chat_bubble_widget.dart @@ -125,6 +125,23 @@ class ChatBubble extends StatelessWidget { avatar: message.sender!.avatar, size: Dimens.sixTeen, ), + if (isYourMessage && _setMessageStatus(isYourMessage) == 'Pending') + Padding( + padding: EdgeInsets.only(bottom: Dimens.eight), + child: Row( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + NxCircularProgressIndicator( + size: Dimens.twenty, + strokeWidth: Dimens.one, + color: ColorValues.lightGrayColor, + ), + Dimens.boxWidth8, + ], + ), + ), GestureDetector( behavior: HitTestBehavior.opaque, onLongPress: showChatDetailsAndOptions, @@ -183,9 +200,7 @@ class ChatBubble extends StatelessWidget { color: _setMessageColor(isYourMessage), ), ), - if (message.message != null && - message.message!.isNotEmpty) - Dimens.boxHeight8, + Dimens.boxHeight8, Text( message.createdAt!.getTime(), style: AppStyles.style12Normal.copyWith( @@ -194,27 +209,12 @@ class ChatBubble extends StatelessWidget { ), ), if (isYourMessage) - Row( - mainAxisSize: MainAxisSize.min, - mainAxisAlignment: MainAxisAlignment.start, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - Text( - _setMessageStatus(isYourMessage), - style: AppStyles.style12Normal.copyWith( - fontSize: Dimens.ten, - color: _setMessageStatusColor(), - ), - ), - Dimens.boxWidth8, - if (_setMessageStatus(isYourMessage) == - 'Pending') - NxCircularProgressIndicator( - size: Dimens.fourteen, - strokeWidth: Dimens.one, - color: _setMessageStatusColor(), - ), - ], + Text( + _setMessageStatus(isYourMessage), + style: AppStyles.style12Normal.copyWith( + fontSize: Dimens.ten, + color: _setMessageStatusColor(), + ), ), ], ), @@ -223,6 +223,23 @@ class ChatBubble extends StatelessWidget { ), ), ), + if (!isYourMessage && _setMessageStatus(isYourMessage) == 'Pending') + Padding( + padding: EdgeInsets.only(bottom: Dimens.eight), + child: Row( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + Dimens.boxWidth8, + NxCircularProgressIndicator( + size: Dimens.twenty, + strokeWidth: Dimens.one, + color: ColorValues.lightGrayColor, + ), + ], + ), + ), if (isYourMessage) AvatarWidget( avatar: profile.profileDetails!.user!.avatar, diff --git a/lib/modules/follower/controllers/followers_list_controller.dart b/lib/modules/follower/controllers/followers_list_controller.dart index f3dbab9..a3de539 100644 --- a/lib/modules/follower/controllers/followers_list_controller.dart +++ b/lib/modules/follower/controllers/followers_list_controller.dart @@ -1,6 +1,4 @@ import 'dart:async'; -import 'dart:convert'; -import 'dart:io'; import 'package:flutter/widgets.dart'; import 'package:get/get.dart'; @@ -54,10 +52,8 @@ class FollowersListController extends GetxController { } Future _getFollowersList() async { - AppUtility.printLog("Get Followers List Request"); - if (_userId.value.isEmpty) { - AppUtility.printLog("UserId not found"); + AppUtility.log('User id is empty', tag: 'error'); return; } @@ -65,68 +61,39 @@ class FollowersListController extends GetxController { update(); try { - final response = await _apiProvider.getFollowers( - _auth.token, - _userId.value, - ); - - final decodedData = jsonDecode(utf8.decode(response.bodyBytes)); + final response = + await _apiProvider.getFollowers(_auth.token, _userId.value); - if (response.statusCode == 200) { + if (response.isSuccessful) { + final decodedData = response.data; setFollowersListData = FollowerResponse.fromJson(decodedData); _followersList.clear(); _followersList.addAll(_followersData.value.results!); _isLoading.value = false; update(); - AppUtility.printLog("Get Followers List Success"); } else { + final decodedData = response.data; _isLoading.value = false; update(); - AppUtility.printLog("Get Followers List Error"); AppUtility.showSnackBar( decodedData[StringValues.message], StringValues.error, ); } - } on SocketException { - _isLoading.value = false; - update(); - AppUtility.printLog("Get Followers List Error"); - AppUtility.printLog(StringValues.internetConnError); - AppUtility.showSnackBar( - StringValues.internetConnError, StringValues.error); - } on TimeoutException { - _isLoading.value = false; - update(); - AppUtility.printLog("Get Followers List Error"); - AppUtility.printLog(StringValues.connTimedOut); - AppUtility.showSnackBar(StringValues.connTimedOut, StringValues.error); - } on FormatException catch (e) { - _isLoading.value = false; - update(); - AppUtility.printLog("Get Followers List Error"); - AppUtility.printLog(StringValues.formatExcError); - AppUtility.printLog(e); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); } catch (exc) { _isLoading.value = false; update(); - AppUtility.printLog("Get Followers List Error"); - AppUtility.printLog(StringValues.errorOccurred); - AppUtility.printLog(exc); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); + AppUtility.log('Error: ${exc.toString()}', tag: 'error'); + AppUtility.showSnackBar('Error: ${exc.toString()}', StringValues.error); } } Future _loadMore({int? page}) async { - AppUtility.printLog("Get Followers List Request"); - if (_userId.value.isEmpty) { - AppUtility.printLog("UserId not found"); + AppUtility.log('User id is empty', tag: 'error'); return; } - AppUtility.printLog("Get More Followers List Request"); _isMoreLoading.value = true; update(); @@ -137,50 +104,26 @@ class FollowersListController extends GetxController { page: page, ); - final decodedData = jsonDecode(utf8.decode(response.bodyBytes)); - - if (response.statusCode == 200) { + if (response.isSuccessful) { + final decodedData = response.data; setFollowersListData = FollowerResponse.fromJson(decodedData); _followersList.addAll(_followersData.value.results!); _isMoreLoading.value = false; update(); - AppUtility.printLog("Get More Followers List Success"); } else { + final decodedData = response.data; _isMoreLoading.value = false; update(); - AppUtility.printLog("Get More Followers List Error"); AppUtility.showSnackBar( decodedData[StringValues.message], StringValues.error, ); } - } on SocketException { - _isMoreLoading.value = false; - update(); - AppUtility.printLog("Get More Followers List Error"); - AppUtility.printLog(StringValues.internetConnError); - AppUtility.showSnackBar( - StringValues.internetConnError, StringValues.error); - } on TimeoutException { - _isMoreLoading.value = false; - update(); - AppUtility.printLog("Get More Followers List Error"); - AppUtility.printLog(StringValues.connTimedOut); - AppUtility.showSnackBar(StringValues.connTimedOut, StringValues.error); - } on FormatException catch (e) { - _isMoreLoading.value = false; - update(); - AppUtility.printLog("Get More Followers List Error"); - AppUtility.printLog(StringValues.formatExcError); - AppUtility.printLog(e); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); } catch (exc) { _isMoreLoading.value = false; update(); - AppUtility.printLog("Get More Followers List Error"); - AppUtility.printLog(StringValues.errorOccurred); - AppUtility.printLog(exc); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); + AppUtility.log('Error: ${exc.toString()}', tag: 'error'); + AppUtility.showSnackBar('Error: ${exc.toString()}', StringValues.error); } } @@ -190,7 +133,6 @@ class FollowersListController extends GetxController { return; } - AppUtility.printLog("Search Followers Request"); _isLoading.value = true; update(); @@ -201,51 +143,27 @@ class FollowersListController extends GetxController { searchText, ); - final decodedData = jsonDecode(utf8.decode(response.bodyBytes)); - - if (response.statusCode == 200) { + if (response.isSuccessful) { + final decodedData = response.data; setFollowersListData = FollowerResponse.fromJson(decodedData); _followersList.clear(); _followersList.addAll(_followersData.value.results!); _isLoading.value = false; update(); - AppUtility.printLog("Search Followers Success"); } else { + final decodedData = response.data; _isLoading.value = false; update(); - AppUtility.printLog("Search Followers Error"); AppUtility.showSnackBar( decodedData[StringValues.message], StringValues.error, ); } - } on SocketException { - _isLoading.value = false; - update(); - AppUtility.printLog("Search Followers Error"); - AppUtility.printLog(StringValues.internetConnError); - AppUtility.showSnackBar( - StringValues.internetConnError, StringValues.error); - } on TimeoutException { - _isLoading.value = false; - update(); - AppUtility.printLog("Search Followers Error"); - AppUtility.printLog(StringValues.connTimedOut); - AppUtility.showSnackBar(StringValues.connTimedOut, StringValues.error); - } on FormatException catch (e) { - _isLoading.value = false; - update(); - AppUtility.printLog("Search Followers Error"); - AppUtility.printLog(StringValues.formatExcError); - AppUtility.printLog(e); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); } catch (exc) { _isLoading.value = false; update(); - AppUtility.printLog("Search Followers Error"); - AppUtility.printLog(StringValues.errorOccurred); - AppUtility.printLog(exc); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); + AppUtility.log('Error: ${exc.toString()}', tag: 'error'); + AppUtility.showSnackBar('Error: ${exc.toString()}', StringValues.error); } } @@ -307,6 +225,7 @@ class FollowersListController extends GetxController { } } catch (exc) { _toggleFollowUser(user); + AppUtility.log('Error: ${exc.toString()}', tag: 'error'); AppUtility.showSnackBar('Error: ${exc.toString()}', StringValues.error); } } @@ -335,6 +254,7 @@ class FollowersListController extends GetxController { } } catch (exc) { _toggleFollowUser(user); + AppUtility.log('Error: ${exc.toString()}', tag: 'error'); AppUtility.showSnackBar('Error: ${exc.toString()}', StringValues.error); } } diff --git a/lib/modules/follower/controllers/following_list_controller.dart b/lib/modules/follower/controllers/following_list_controller.dart index 16565fe..d6fb9a2 100644 --- a/lib/modules/follower/controllers/following_list_controller.dart +++ b/lib/modules/follower/controllers/following_list_controller.dart @@ -1,6 +1,4 @@ import 'dart:async'; -import 'dart:convert'; -import 'dart:io'; import 'package:flutter/widgets.dart'; import 'package:get/get.dart'; @@ -54,10 +52,8 @@ class FollowingListController extends GetxController { } Future _getFollowingList() async { - AppUtility.printLog("Get Following List Request"); - if (_userId.value.isEmpty) { - AppUtility.printLog("UserId not found"); + AppUtility.log('User id is empty', tag: 'error'); return; } @@ -70,59 +66,33 @@ class FollowingListController extends GetxController { _userId.value, ); - final decodedData = jsonDecode(utf8.decode(response.bodyBytes)); - - if (response.statusCode == 200) { + if (response.isSuccessful) { + final decodedData = response.data; setFollowingListData = FollowerResponse.fromJson(decodedData); _followingList.clear(); _followingList.addAll(_followingData.value.results!); _isLoading.value = false; update(); - AppUtility.printLog("Get Following List Success"); } else { + final decodedData = response.data; _isLoading.value = false; update(); - AppUtility.printLog("Get Following List Error"); AppUtility.showSnackBar( decodedData[StringValues.message], StringValues.error, ); } - } on SocketException { - _isLoading.value = false; - update(); - AppUtility.printLog("Get Following List Error"); - AppUtility.printLog(StringValues.internetConnError); - AppUtility.showSnackBar( - StringValues.internetConnError, StringValues.error); - } on TimeoutException { - _isLoading.value = false; - update(); - AppUtility.printLog("Get Following List Error"); - AppUtility.printLog(StringValues.connTimedOut); - AppUtility.showSnackBar(StringValues.connTimedOut, StringValues.error); - } on FormatException catch (e) { - _isLoading.value = false; - update(); - AppUtility.printLog("Get Following List Error"); - AppUtility.printLog(StringValues.formatExcError); - AppUtility.printLog(e); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); } catch (exc) { _isLoading.value = false; update(); - AppUtility.printLog("Get Following List Error"); - AppUtility.printLog(StringValues.errorOccurred); - AppUtility.printLog(exc); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); + AppUtility.log('Error: ${exc.toString()}', tag: 'error'); + AppUtility.showSnackBar('Error: ${exc.toString()}', StringValues.error); } } Future _loadMore({int? page}) async { - AppUtility.printLog("Get Following List Request"); - if (_userId.value.isEmpty) { - AppUtility.printLog("UserId not found"); + AppUtility.log('User id is empty', tag: 'error'); return; } @@ -136,50 +106,26 @@ class FollowingListController extends GetxController { page: page, ); - final decodedData = jsonDecode(utf8.decode(response.bodyBytes)); - - if (response.statusCode == 200) { + if (response.isSuccessful) { + final decodedData = response.data; setFollowingListData = FollowerResponse.fromJson(decodedData); _followingList.addAll(_followingData.value.results!); _isMoreLoading.value = false; update(); - AppUtility.printLog("Get More Following List Success"); } else { + final decodedData = response.data; _isMoreLoading.value = false; update(); - AppUtility.printLog("Get More Following List Error"); AppUtility.showSnackBar( decodedData[StringValues.message], StringValues.error, ); } - } on SocketException { - _isMoreLoading.value = false; - update(); - AppUtility.printLog("Get More Following List Error"); - AppUtility.printLog(StringValues.internetConnError); - AppUtility.showSnackBar( - StringValues.internetConnError, StringValues.error); - } on TimeoutException { - _isMoreLoading.value = false; - update(); - AppUtility.printLog("Get More Following List Error"); - AppUtility.printLog(StringValues.connTimedOut); - AppUtility.showSnackBar(StringValues.connTimedOut, StringValues.error); - } on FormatException catch (e) { - _isMoreLoading.value = false; - update(); - AppUtility.printLog("Get More Following List Error"); - AppUtility.printLog(StringValues.formatExcError); - AppUtility.printLog(e); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); } catch (exc) { _isMoreLoading.value = false; update(); - AppUtility.printLog("Get More Following List Error"); - AppUtility.printLog(StringValues.errorOccurred); - AppUtility.printLog(exc); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); + AppUtility.log('Error: ${exc.toString()}', tag: 'error'); + AppUtility.showSnackBar('Error: ${exc.toString()}', StringValues.error); } } @@ -189,7 +135,6 @@ class FollowingListController extends GetxController { return; } - AppUtility.printLog("Search Followings Request"); _isLoading.value = true; update(); @@ -200,51 +145,27 @@ class FollowingListController extends GetxController { searchText, ); - final decodedData = jsonDecode(utf8.decode(response.bodyBytes)); - - if (response.statusCode == 200) { + if (response.isSuccessful) { + final decodedData = response.data; setFollowingListData = FollowerResponse.fromJson(decodedData); _followingList.clear(); _followingList.addAll(_followingData.value.results!); _isLoading.value = false; update(); - AppUtility.printLog("Search Followings Success"); } else { + final decodedData = response.data; _isLoading.value = false; update(); - AppUtility.printLog("Search Followings Error"); AppUtility.showSnackBar( decodedData[StringValues.message], StringValues.error, ); } - } on SocketException { - _isLoading.value = false; - update(); - AppUtility.printLog("Search Followings Error"); - AppUtility.printLog(StringValues.internetConnError); - AppUtility.showSnackBar( - StringValues.internetConnError, StringValues.error); - } on TimeoutException { - _isLoading.value = false; - update(); - AppUtility.printLog("Search Followings Error"); - AppUtility.printLog(StringValues.connTimedOut); - AppUtility.showSnackBar(StringValues.connTimedOut, StringValues.error); - } on FormatException catch (e) { - _isLoading.value = false; - update(); - AppUtility.printLog("Search Followings Error"); - AppUtility.printLog(StringValues.formatExcError); - AppUtility.printLog(e); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); } catch (exc) { _isLoading.value = false; update(); - AppUtility.printLog("Search Followings Error"); - AppUtility.printLog(StringValues.errorOccurred); - AppUtility.printLog(exc); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); + AppUtility.log('Error: ${exc.toString()}', tag: 'error'); + AppUtility.showSnackBar('Error: ${exc.toString()}', StringValues.error); } } @@ -306,6 +227,7 @@ class FollowingListController extends GetxController { } } catch (exc) { _toggleFollowUser(user); + AppUtility.log('Error: ${exc.toString()}', tag: 'error'); AppUtility.showSnackBar('Error: ${exc.toString()}', StringValues.error); } } @@ -334,6 +256,7 @@ class FollowingListController extends GetxController { } } catch (exc) { _toggleFollowUser(user); + AppUtility.log('Error: ${exc.toString()}', tag: 'error'); AppUtility.showSnackBar('Error: ${exc.toString()}', StringValues.error); } } diff --git a/lib/modules/home/controllers/profile_controller.dart b/lib/modules/home/controllers/profile_controller.dart index e9152b8..ba84ed3 100644 --- a/lib/modules/home/controllers/profile_controller.dart +++ b/lib/modules/home/controllers/profile_controller.dart @@ -1,6 +1,5 @@ import 'dart:async'; import 'dart:convert'; -import 'dart:io'; import 'package:get/get.dart'; import 'package:http/http.dart' as http; @@ -308,8 +307,6 @@ class ProfileController extends GetxController { } Future _updateProfile(Map details) async { - AppUtility.printLog("Update Profile Request"); - if (details.isEmpty) { AppUtility.printLog("No Data To Update"); return; @@ -320,44 +317,23 @@ class ProfileController extends GetxController { try { final response = await _apiProvider.updateProfile(_auth.token, body); - final decodedData = jsonDecode(utf8.decode(response.bodyBytes)); - - if (response.statusCode == 200) { - AppUtility.printLog("Update Profile Success"); - + if (response.isSuccessful) { + final decodedData = response.data; await _fetchProfileDetails(fetchPost: false); - AppUtility.showSnackBar( - StringValues.updateProfileSuccessful, + decodedData[StringValues.message], StringValues.success, ); } else { - AppUtility.printLog("Update Profile Error"); - + final decodedData = response.data; AppUtility.showSnackBar( decodedData[StringValues.message], StringValues.error, ); } - } on SocketException { - AppUtility.printLog("Update Profile Error"); - - AppUtility.printLog(StringValues.internetConnError); - AppUtility.showSnackBar( - StringValues.internetConnError, StringValues.error); - } on TimeoutException { - AppUtility.printLog("Update Profile Error"); - - AppUtility.printLog(StringValues.connTimedOut); - AppUtility.showSnackBar(StringValues.connTimedOut, StringValues.error); - } on FormatException catch (e) { - AppUtility.printLog("Update Profile Error"); - - AppUtility.printLog(StringValues.formatExcError); - AppUtility.printLog(e); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); } catch (exc) { - AppUtility.showSnackBar('Error: ${exc.toString()}', StringValues.error); + AppUtility.log('Error: $exc', tag: 'error'); + AppUtility.showSnackBar('Error: $exc', StringValues.error); } } diff --git a/lib/modules/post/controllers/comment_controller.dart b/lib/modules/post/controllers/comment_controller.dart index 4ba9187..e8fd254 100644 --- a/lib/modules/post/controllers/comment_controller.dart +++ b/lib/modules/post/controllers/comment_controller.dart @@ -1,6 +1,4 @@ import 'dart:async'; -import 'dart:convert'; -import 'dart:io'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; @@ -40,8 +38,6 @@ class CommentController extends GetxController { } Future _fetchComments() async { - AppUtility.printLog("Fetch Comment Request"); - var postId = Get.arguments; if (postId == '' || postId == null) return; @@ -52,57 +48,31 @@ class CommentController extends GetxController { try { final response = await _apiProvider.getComments(_auth.token, postId); - final decodedData = jsonDecode(utf8.decode(response.bodyBytes)); - - if (response.statusCode == 200) { + if (response.isSuccessful) { + final decodedData = response.data; setCommentData = CommentsResponse.fromJson(decodedData); _commentList.clear(); _commentList.addAll(_commentsData.value.results!); _isLoading.value = false; update(); - AppUtility.printLog("Fetch Comment Success"); } else { + final decodedData = response.data; _isLoading.value = false; update(); - AppUtility.printLog("Fetch Comment Error"); AppUtility.showSnackBar( decodedData[StringValues.message], StringValues.error, ); } - } on SocketException { - _isLoading.value = false; - update(); - AppUtility.printLog("Fetch Comment Error"); - AppUtility.printLog(StringValues.internetConnError); - AppUtility.showSnackBar( - StringValues.internetConnError, StringValues.error); - } on TimeoutException { - _isLoading.value = false; - update(); - AppUtility.printLog("Fetch Comment Error"); - AppUtility.printLog(StringValues.connTimedOut); - AppUtility.showSnackBar(StringValues.connTimedOut, StringValues.error); - } on FormatException catch (e) { - _isLoading.value = false; - update(); - AppUtility.printLog("Fetch Comment Error"); - AppUtility.printLog(StringValues.formatExcError); - AppUtility.printLog(e); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); } catch (exc) { _isLoading.value = false; update(); - AppUtility.printLog("Fetch Comment Error"); - AppUtility.printLog(StringValues.errorOccurred); - AppUtility.printLog(exc); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); + AppUtility.log('Error: ${exc.toString()}', tag: 'error'); + AppUtility.showSnackBar('Error: ${exc.toString()}', StringValues.error); } } Future _loadMore({int? page}) async { - AppUtility.printLog("Fetch More Comment Request"); - var postId = Get.arguments; if (postId == '' || postId == null) return; @@ -117,56 +87,30 @@ class CommentController extends GetxController { page: page, ); - final decodedData = jsonDecode(utf8.decode(response.bodyBytes)); - - if (response.statusCode == 200) { + if (response.isSuccessful) { + final decodedData = response.data; setCommentData = CommentsResponse.fromJson(decodedData); _commentList.addAll(_commentsData.value.results!); _isMoreLoading.value = false; update(); - AppUtility.printLog("Fetch More Comment Success"); } else { + final decodedData = response.data; _isMoreLoading.value = false; update(); - AppUtility.printLog("Fetch More Comment Error"); AppUtility.showSnackBar( decodedData[StringValues.message], StringValues.error, ); } - } on SocketException { - _isMoreLoading.value = false; - update(); - AppUtility.printLog("Fetch More Comment Error"); - AppUtility.printLog(StringValues.internetConnError); - AppUtility.showSnackBar( - StringValues.internetConnError, StringValues.error); - } on TimeoutException { - _isMoreLoading.value = false; - update(); - AppUtility.printLog("Fetch More Comment Error"); - AppUtility.printLog(StringValues.connTimedOut); - AppUtility.showSnackBar(StringValues.connTimedOut, StringValues.error); - } on FormatException catch (e) { - _isMoreLoading.value = false; - update(); - AppUtility.printLog("Fetch More Comment Error"); - AppUtility.printLog(StringValues.formatExcError); - AppUtility.printLog(e); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); } catch (exc) { _isMoreLoading.value = false; update(); - AppUtility.printLog("Fetch More Comment Error"); - AppUtility.printLog(StringValues.errorOccurred); - AppUtility.printLog(exc); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); + AppUtility.log('Error: ${exc.toString()}', tag: 'error'); + AppUtility.showSnackBar('Error: ${exc.toString()}', StringValues.error); } } Future _deleteComment(String commentId) async { - AppUtility.printLog("Delete Comment Request"); - if (commentId.isEmpty) return; var index = _commentList.indexWhere((element) => element.id == commentId); @@ -180,52 +124,27 @@ class CommentController extends GetxController { try { final response = await _apiProvider.deleteComment(_auth.token, commentId); - final decodedData = jsonDecode(utf8.decode(response.bodyBytes)); - - if (response.statusCode == 200) { - // await _fetchComments(); - AppUtility.printLog("Delete Comment Success"); + if (response.isSuccessful) { + final decodedData = response.data; AppUtility.showSnackBar( decodedData[StringValues.message], StringValues.success, duration: 2, ); } else { + final decodedData = response.data; _commentList.insert(index, comment); update(); - AppUtility.printLog("Delete Comment Error"); AppUtility.showSnackBar( decodedData[StringValues.message], StringValues.error, ); } - } on SocketException { - _commentList.insert(index, comment); - update(); - AppUtility.printLog("Delete Comment Error"); - AppUtility.printLog(StringValues.internetConnError); - AppUtility.showSnackBar( - StringValues.internetConnError, StringValues.error); - } on TimeoutException { - _commentList.insert(index, comment); - update(); - AppUtility.printLog("Delete Comment Error"); - AppUtility.printLog(StringValues.connTimedOut); - AppUtility.showSnackBar(StringValues.connTimedOut, StringValues.error); - } on FormatException catch (e) { - _commentList.insert(index, comment); - update(); - AppUtility.printLog("Delete Comment Error"); - AppUtility.printLog(StringValues.formatExcError); - AppUtility.printLog(e); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); } catch (exc) { _commentList.insert(index, comment); update(); - AppUtility.printLog("Delete Comment Error"); - AppUtility.printLog(StringValues.errorOccurred); - AppUtility.printLog(exc); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); + AppUtility.log('Error: ${exc.toString()}', tag: 'error'); + AppUtility.showSnackBar('Error: ${exc.toString()}', StringValues.error); } } diff --git a/lib/modules/post/controllers/create_comment_controller.dart b/lib/modules/post/controllers/create_comment_controller.dart index 61d8e7c..4fbec6a 100644 --- a/lib/modules/post/controllers/create_comment_controller.dart +++ b/lib/modules/post/controllers/create_comment_controller.dart @@ -1,6 +1,4 @@ import 'dart:async'; -import 'dart:convert'; -import 'dart:io'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; @@ -36,7 +34,6 @@ class CreateCommentController extends GetxController { bool get isLoading => _isLoading.value; Future _createNewComment(String comment, String postId) async { - AppUtility.printLog("Add Comment Request"); commentTextController.clear(); _comment.value = ''; _isLoading.value = true; @@ -46,10 +43,8 @@ class CreateCommentController extends GetxController { final response = await _apiProvider.addComment(_auth.token, postId, comment); - final decodedData = jsonDecode(utf8.decode(response.bodyBytes)); - - if (response.statusCode == 200) { - AppUtility.printLog("Add Comment Success"); + if (response.isSuccessful) { + final decodedData = response.data; _commentController.commentList .insert(0, Comment.fromJson(decodedData['comment'])); _commentController.update(); @@ -61,7 +56,7 @@ class CreateCommentController extends GetxController { duration: 2, ); } else { - AppUtility.printLog("Add Comment Error"); + final decodedData = response.data; _isLoading.value = false; update(); AppUtility.showSnackBar( @@ -69,33 +64,12 @@ class CreateCommentController extends GetxController { StringValues.error, ); } - } on SocketException { - AppUtility.printLog("Add Comment Error"); - _isLoading.value = false; - update(); - AppUtility.printLog(StringValues.internetConnError); - AppUtility.showSnackBar( - StringValues.internetConnError, StringValues.error); - } on TimeoutException { - AppUtility.printLog("Add Comment Error"); - _isLoading.value = false; - update(); - AppUtility.printLog(StringValues.connTimedOut); - AppUtility.showSnackBar(StringValues.connTimedOut, StringValues.error); - } on FormatException catch (e) { - AppUtility.printLog("Add Comment Error"); - _isLoading.value = false; - update(); - AppUtility.printLog(StringValues.formatExcError); - AppUtility.printLog(e); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); } catch (exc) { AppUtility.printLog("Add Comment Error"); _isLoading.value = false; update(); - AppUtility.printLog(StringValues.errorOccurred); - AppUtility.printLog(exc); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); + AppUtility.log('Error: ${exc.toString()}', tag: 'error'); + AppUtility.showSnackBar('Error: ${exc.toString()}', StringValues.error); } } diff --git a/lib/modules/post/controllers/create_post_controller.dart b/lib/modules/post/controllers/create_post_controller.dart index 9bf7b01..ca9af1f 100644 --- a/lib/modules/post/controllers/create_post_controller.dart +++ b/lib/modules/post/controllers/create_post_controller.dart @@ -1,5 +1,4 @@ import 'dart:async'; -import 'dart:convert'; import 'dart:io'; import 'package:cloudinary/cloudinary.dart'; @@ -170,7 +169,7 @@ class CreatePostController extends GetxController { folder: 'social_media_api/posts/thumbnails', progressCallback: (count, total) { var progress = ((count / total) * 100).toStringAsFixed(2); - AppUtility.printLog('Uploading Thumbnail : $progress %'); + AppUtility.log('Uploading Thumbnail : $progress %'); }, ); @@ -190,7 +189,7 @@ class CreatePostController extends GetxController { folder: "social_media_api/posts/videos", progressCallback: (count, total) { var progress = ((count / total) * 100).toStringAsFixed(2); - AppUtility.printLog('Uploading Video : $progress %'); + AppUtility.log('Uploading Video : $progress %'); }, ) .then((value) { @@ -204,8 +203,9 @@ class CreatePostController extends GetxController { "mediaType": "video" }); }).catchError((err) { - AppUtility.printLog(err); - AppUtility.showSnackBar('Video upload failed.', StringValues.error); + AppUtility.log('Video upload failed. Error: $err', tag: 'error'); + AppUtility.showSnackBar( + 'Video upload failed. Error: $err', StringValues.error); return; }); } else { @@ -217,7 +217,7 @@ class CreatePostController extends GetxController { folder: "social_media_api/posts/images", progressCallback: (count, total) { var progress = ((count / total) * 100).toStringAsFixed(2); - AppUtility.printLog('Uploading : $progress %'); + AppUtility.log('Uploading : $progress %'); }, ) .then((value) { @@ -227,8 +227,9 @@ class CreatePostController extends GetxController { "mediaType": "image" }); }).catchError((err) { - AppUtility.printLog(err); - AppUtility.showSnackBar('Image upload failed.', StringValues.error); + AppUtility.log('Image upload failed. Error: $err', tag: 'error'); + AppUtility.showSnackBar( + 'Image upload failed. Error: $err', StringValues.error); return; }); } @@ -245,9 +246,8 @@ class CreatePostController extends GetxController { final response = await _apiProvider.createPost(_auth.token, body); - final decodedData = jsonDecode(utf8.decode(response.bodyBytes)); - - if (response.statusCode == 201) { + if (response.isSuccessful) { + final decodedData = response.data; _caption.value = ''; _pickedFileList.clear(); _postController.postList.insert(0, Post.fromJson(decodedData['post'])); @@ -261,6 +261,7 @@ class CreatePostController extends GetxController { StringValues.success, ); } else { + final decodedData = response.data; AppUtility.closeDialog(); _isLoading.value = false; update(); @@ -269,33 +270,12 @@ class CreatePostController extends GetxController { StringValues.error, ); } - } on SocketException { - AppUtility.closeDialog(); - _isLoading.value = false; - update(); - AppUtility.printLog(StringValues.internetConnError); - AppUtility.showSnackBar( - StringValues.internetConnError, StringValues.error); - } on TimeoutException { - AppUtility.closeDialog(); - _isLoading.value = false; - update(); - AppUtility.printLog(StringValues.connTimedOut); - AppUtility.showSnackBar(StringValues.connTimedOut, StringValues.error); - } on FormatException catch (e) { - AppUtility.closeDialog(); - _isLoading.value = false; - update(); - AppUtility.printLog(StringValues.formatExcError); - AppUtility.printLog(e); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); } catch (exc) { AppUtility.closeDialog(); _isLoading.value = false; update(); - AppUtility.printLog(StringValues.errorOccurred); - AppUtility.printLog(exc); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); + AppUtility.log('Error: $exc', tag: 'error'); + AppUtility.showSnackBar('Error: $exc', StringValues.error); } } @@ -337,7 +317,7 @@ class CreatePostController extends GetxController { var croppedImage = File(croppedFile!.path); File? resultFile = croppedImage; var size = croppedImage.lengthSync(); - AppUtility.printLog('Original file size: ${resultFile.sizeToKb()} KB'); + AppUtility.log('Original file size: ${resultFile.sizeToKb()} KB'); if (size > (5 * maxImageBytes)) { AppUtility.showSnackBar( @@ -345,8 +325,8 @@ class CreatePostController extends GetxController { '', ); } else if (size < (maxImageBytes / 2)) { - AppUtility.printLog('Result $resultFile'); - AppUtility.printLog('Result file size: ${resultFile.sizeToKb()} KB'); + AppUtility.log('Result $resultFile'); + AppUtility.log('Result file size: ${resultFile.sizeToKb()} KB'); _pickedFileList.add(resultFile); update(); } else { @@ -356,7 +336,7 @@ class CreatePostController extends GetxController { AppUtility.showLoadingDialog(message: 'Compressing...'); var timestamp = DateTime.now().millisecondsSinceEpoch; - AppUtility.printLog('Compressing...'); + AppUtility.log('Compressing...'); resultFile = await FlutterImageCompress.compressAndGetFile( resultFile.path, '${tempDir.absolute.path}/temp$timestamp.jpg', @@ -367,8 +347,8 @@ class CreatePostController extends GetxController { AppUtility.closeDialog(); /// ---------------------------------------------------------------- - AppUtility.printLog('Result $resultFile'); - AppUtility.printLog('Result file size: ${resultFile.sizeToKb()} KB'); + AppUtility.log('Result $resultFile'); + AppUtility.log('Result file size: ${resultFile.sizeToKb()} KB'); _pickedFileList.add(resultFile); update(); } @@ -417,7 +397,7 @@ class CreatePostController extends GetxController { var croppedImage = File(croppedFile!.path); File? resultFile = croppedImage; var size = croppedImage.lengthSync(); - AppUtility.printLog('Original file size: ${resultFile.sizeToKb()} KB'); + AppUtility.log('Original file size: ${resultFile.sizeToKb()} KB'); if (size > (5 * maxImageBytes)) { AppUtility.showSnackBar( @@ -425,8 +405,8 @@ class CreatePostController extends GetxController { '', ); } else if (size < (maxImageBytes / 2)) { - AppUtility.printLog('Result $resultFile'); - AppUtility.printLog('Result file size: ${resultFile.sizeToKb()} KB'); + AppUtility.log('Result $resultFile'); + AppUtility.log('Result file size: ${resultFile.sizeToKb()} KB'); _pickedFileList.add(resultFile); update(); } else { @@ -436,7 +416,7 @@ class CreatePostController extends GetxController { AppUtility.showLoadingDialog(message: 'Compressing...'); var timestamp = DateTime.now().millisecondsSinceEpoch; - AppUtility.printLog('Compressing...'); + AppUtility.log('Compressing...'); resultFile = await FlutterImageCompress.compressAndGetFile( resultFile.path, '${tempDir.absolute.path}/temp$timestamp.jpg', @@ -447,8 +427,8 @@ class CreatePostController extends GetxController { AppUtility.closeDialog(); /// ---------------------------------------------------------------- - AppUtility.printLog('Result $resultFile'); - AppUtility.printLog('Result file size: ${resultFile.sizeToKb()} KB'); + AppUtility.log('Result $resultFile'); + AppUtility.log('Result file size: ${resultFile.sizeToKb()} KB'); _pickedFileList.add(resultFile); update(); } @@ -472,7 +452,7 @@ class CreatePostController extends GetxController { var videoFile = File(pickedVideo.path); var videoSize = videoFile.lengthSync(); - AppUtility.printLog('Original video size: ${videoFile.sizeToMb()} MB'); + AppUtility.log('Original video size: ${videoFile.sizeToMb()} MB'); if (videoSize > (10 * maxVideoBytes)) { AppUtility.showSnackBar( @@ -480,8 +460,8 @@ class CreatePostController extends GetxController { '', ); } else if (videoSize < maxVideoBytes) { - AppUtility.printLog('Result $videoFile'); - AppUtility.printLog('Result video size: ${videoFile.sizeToMb()} MB'); + AppUtility.log('Result $videoFile'); + AppUtility.log('Result video size: ${videoFile.sizeToMb()} MB'); _pickedFileList.add(videoFile); update(); @@ -494,14 +474,14 @@ class CreatePostController extends GetxController { quality: VideoQuality.DefaultQuality, ); AppUtility.closeDialog(); - AppUtility.printLog('Result ${info!.toJson()}'); + AppUtility.log('Result ${info!.toJson()}'); videoFile = info.file!; videoSize = info.filesize!; /// ------------------------------------------------------------------ - AppUtility.printLog('Result $videoFile'); - AppUtility.printLog('Result video size: ${videoFile.sizeToMb()} MB'); + AppUtility.log('Result $videoFile'); + AppUtility.log('Result video size: ${videoFile.sizeToMb()} MB'); if (videoSize > (2 * maxVideoBytes)) { AppUtility.showSnackBar( @@ -538,7 +518,7 @@ class CreatePostController extends GetxController { var videoFile = File(file.path!); var videoSize = file.size; - AppUtility.printLog('Original video size: ${videoFile.sizeToMb()} MB'); + AppUtility.log('Original video size: ${videoFile.sizeToMb()} MB'); if (videoSize > (10 * maxVideoBytes)) { AppUtility.showSnackBar( @@ -546,8 +526,8 @@ class CreatePostController extends GetxController { '', ); } else if (videoSize < maxVideoBytes) { - AppUtility.printLog('Result $videoFile'); - AppUtility.printLog('Result video size: ${videoFile.sizeToMb()} MB'); + AppUtility.log('Result $videoFile'); + AppUtility.log('Result video size: ${videoFile.sizeToMb()} MB'); _pickedFileList.add(videoFile); update(); @@ -560,14 +540,14 @@ class CreatePostController extends GetxController { quality: VideoQuality.DefaultQuality, ); AppUtility.closeDialog(); - AppUtility.printLog('Result ${info!.toJson()}'); + AppUtility.log('Result ${info!.toJson()}'); videoFile = info.file!; videoSize = info.filesize!; /// ------------------------------------------------------------------ - AppUtility.printLog('Result $videoFile'); - AppUtility.printLog('Result video size: ${videoFile.sizeToMb()} MB'); + AppUtility.log('Result $videoFile'); + AppUtility.log('Result video size: ${videoFile.sizeToMb()} MB'); if (videoSize > (2 * maxVideoBytes)) { AppUtility.showSnackBar( diff --git a/lib/modules/post/controllers/post_details_controller.dart b/lib/modules/post/controllers/post_details_controller.dart index 544d3ce..29ef236 100644 --- a/lib/modules/post/controllers/post_details_controller.dart +++ b/lib/modules/post/controllers/post_details_controller.dart @@ -1,6 +1,4 @@ import 'dart:async'; -import 'dart:convert'; -import 'dart:io'; import 'package:get/get.dart'; import 'package:http/http.dart' as http; @@ -53,8 +51,6 @@ class PostDetailsController extends GetxController { } Future _fetchPostDetails() async { - AppUtility.printLog("Fetch Post Details Request"); - if (postId == '' || postId == null) return; _isLoading.value = true; @@ -63,49 +59,25 @@ class PostDetailsController extends GetxController { try { final response = await _apiProvider.getPostDetails(_auth.token, postId!); - final decodedData = jsonDecode(utf8.decode(response.bodyBytes)); - - if (response.statusCode == 200) { + if (response.isSuccessful) { + final decodedData = response.data; setPostDetailsData = PostDetailsResponse.fromJson(decodedData); _isLoading.value = false; update(); - AppUtility.printLog("Fetch Post Details Success"); } else { + final decodedData = response.data; _isLoading.value = false; update(); - AppUtility.printLog("Fetch Post Details Error"); AppUtility.showSnackBar( decodedData[StringValues.message], StringValues.error, ); } - } on SocketException { - _isLoading.value = false; - update(); - AppUtility.printLog("Fetch Post Details Error"); - AppUtility.printLog(StringValues.internetConnError); - AppUtility.showSnackBar( - StringValues.internetConnError, StringValues.error); - } on TimeoutException { - _isLoading.value = false; - update(); - AppUtility.printLog("Fetch Post Details Error"); - AppUtility.printLog(StringValues.connTimedOut); - AppUtility.showSnackBar(StringValues.connTimedOut, StringValues.error); - } on FormatException catch (e) { - _isLoading.value = false; - update(); - AppUtility.printLog("Fetch Post Details Error"); - AppUtility.printLog(StringValues.formatExcError); - AppUtility.printLog(e); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); } catch (exc) { _isLoading.value = false; update(); - AppUtility.printLog("Fetch Post Details Error"); - AppUtility.printLog(StringValues.errorOccurred); - AppUtility.printLog(exc); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); + AppUtility.log('Error: ${exc.toString()}', tag: 'error'); + AppUtility.showSnackBar('Error: ${exc.toString()}', StringValues.error); } } @@ -133,6 +105,7 @@ class PostDetailsController extends GetxController { } } catch (exc) { update(); + AppUtility.log('Error: ${exc.toString()}', tag: 'error'); AppUtility.showSnackBar('Error: ${exc.toString()}', StringValues.error); } } @@ -172,6 +145,7 @@ class PostDetailsController extends GetxController { } } catch (exc) { _toggleLike(post); + AppUtility.log('Error: ${exc.toString()}', tag: 'error'); AppUtility.showSnackBar('Error: ${exc.toString()}', StringValues.error); } } diff --git a/lib/modules/post/controllers/post_liked_users_controller.dart b/lib/modules/post/controllers/post_liked_users_controller.dart index b479973..f7c5007 100644 --- a/lib/modules/post/controllers/post_liked_users_controller.dart +++ b/lib/modules/post/controllers/post_liked_users_controller.dart @@ -1,5 +1,4 @@ import 'dart:async'; -import 'dart:convert'; import 'package:get/get.dart'; import 'package:http/http.dart' as http; @@ -43,8 +42,6 @@ class PostLikedUsersController extends GetxController { } Future _fetchPostLikedUsers() async { - AppUtility.printLog("Fetch Post Liked Users Request"); - var postId = Get.arguments; if (postId == '' || postId == null) return; @@ -56,19 +53,17 @@ class PostLikedUsersController extends GetxController { final response = await _apiProvider.getPostLikedUsers(_auth.token, postId); - final decodedData = jsonDecode(utf8.decode(response.bodyBytes)); - - if (response.statusCode == 200) { + if (response.isSuccessful) { + final decodedData = response.data; setPostLikedUsersData = PostLikeResponse.fromJson(decodedData); _postLikedUsersList.clear(); _postLikedUsersList.addAll(_postLikedUsersData.value.results!); _isLoading.value = false; update(); - AppUtility.printLog("Fetch Post Liked Users Success"); } else { + final decodedData = response.data; _isLoading.value = false; update(); - AppUtility.printLog("Fetch Post Liked Users Error"); AppUtility.showSnackBar( decodedData[StringValues.message], StringValues.error, @@ -77,13 +72,12 @@ class PostLikedUsersController extends GetxController { } catch (exc) { _isLoading.value = false; update(); + AppUtility.log('Error: ${exc.toString()}', tag: 'error'); AppUtility.showSnackBar('Error: ${exc.toString()}', StringValues.error); } } Future _loadMore({int? page}) async { - AppUtility.printLog("Fetch More Post Liked Users Request"); - var postId = Get.arguments; if (postId == '' || postId == null) return; @@ -98,18 +92,16 @@ class PostLikedUsersController extends GetxController { page: page, ); - final decodedData = jsonDecode(utf8.decode(response.bodyBytes)); - - if (response.statusCode == 200) { + if (response.isSuccessful) { + final decodedData = response.data; setPostLikedUsersData = PostLikeResponse.fromJson(decodedData); _postLikedUsersList.addAll(_postLikedUsersData.value.results!); _isMoreLoading.value = false; update(); - AppUtility.printLog("Fetch More Post Liked Users Success"); } else { + final decodedData = response.data; _isMoreLoading.value = false; update(); - AppUtility.printLog("Fetch More Post Liked Users Error"); AppUtility.showSnackBar( decodedData[StringValues.message], StringValues.error, @@ -118,6 +110,7 @@ class PostLikedUsersController extends GetxController { } catch (exc) { _isMoreLoading.value = false; update(); + AppUtility.log('Error: ${exc.toString()}', tag: 'error'); AppUtility.showSnackBar('Error: ${exc.toString()}', StringValues.error); } } @@ -180,6 +173,7 @@ class PostLikedUsersController extends GetxController { } } catch (exc) { _toggleFollowUser(user); + AppUtility.log('Error: ${exc.toString()}', tag: 'error'); AppUtility.showSnackBar('Error: ${exc.toString()}', StringValues.error); } } @@ -208,6 +202,7 @@ class PostLikedUsersController extends GetxController { } } catch (exc) { _toggleFollowUser(user); + AppUtility.log('Error: ${exc.toString()}', tag: 'error'); AppUtility.showSnackBar('Error: ${exc.toString()}', StringValues.error); } } diff --git a/lib/modules/profile/controllers/edit_about_controller.dart b/lib/modules/profile/controllers/edit_about_controller.dart index f4f1d7f..0311c5a 100644 --- a/lib/modules/profile/controllers/edit_about_controller.dart +++ b/lib/modules/profile/controllers/edit_about_controller.dart @@ -1,6 +1,4 @@ import 'dart:async'; -import 'dart:convert'; -import 'dart:io'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; @@ -44,7 +42,6 @@ class EditAboutController extends GetxController { Future _updateAbout(String about) async { final body = {'about': about}; - AppUtility.printLog("Update About Request..."); AppUtility.showLoadingDialog(); _isLoading.value = true; update(); @@ -52,19 +49,19 @@ class EditAboutController extends GetxController { try { final response = await _apiProvider.updateProfile(_auth.token, body); - final decodedData = jsonDecode(utf8.decode(response.bodyBytes)); - - if (response.statusCode == 200) { + if (response.isSuccessful) { + final decodedData = response.data; await _profile.fetchProfileDetails(fetchPost: false); AppUtility.closeDialog(); _isLoading.value = false; update(); RouteManagement.goToBack(); AppUtility.showSnackBar( - StringValues.updateProfileSuccessful, + decodedData['message'], StringValues.success, ); } else { + final decodedData = response.data; AppUtility.closeDialog(); _isLoading.value = false; update(); @@ -73,33 +70,12 @@ class EditAboutController extends GetxController { StringValues.error, ); } - } on SocketException { - AppUtility.closeDialog(); - _isLoading.value = false; - update(); - AppUtility.printLog(StringValues.internetConnError); - AppUtility.showSnackBar( - StringValues.internetConnError, StringValues.error); - } on TimeoutException { - AppUtility.closeDialog(); - _isLoading.value = false; - update(); - AppUtility.printLog(StringValues.connTimedOut); - AppUtility.showSnackBar(StringValues.connTimedOut, StringValues.error); - } on FormatException catch (e) { - AppUtility.closeDialog(); - _isLoading.value = false; - update(); - AppUtility.printLog(StringValues.formatExcError); - AppUtility.printLog(e); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); } catch (exc) { AppUtility.closeDialog(); _isLoading.value = false; update(); - AppUtility.printLog(StringValues.errorOccurred); - AppUtility.printLog(exc); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); + AppUtility.log('Error: $exc', tag: 'error'); + AppUtility.showSnackBar('Error: $exc', StringValues.error); } } diff --git a/lib/modules/profile/controllers/edit_dob_controller.dart b/lib/modules/profile/controllers/edit_dob_controller.dart index 120738f..3a2ac69 100644 --- a/lib/modules/profile/controllers/edit_dob_controller.dart +++ b/lib/modules/profile/controllers/edit_dob_controller.dart @@ -1,6 +1,4 @@ import 'dart:async'; -import 'dart:convert'; -import 'dart:io'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; @@ -46,11 +44,8 @@ class EditDOBController extends GetxController { return; } - final body = { - 'dob': dob, - }; + final body = {'dob': dob}; - AppUtility.printLog("Update DOB Request..."); AppUtility.showLoadingDialog(); _isLoading.value = true; update(); @@ -58,19 +53,19 @@ class EditDOBController extends GetxController { try { final response = await _apiProvider.updateProfile(_auth.token, body); - final decodedData = jsonDecode(utf8.decode(response.bodyBytes)); - - if (response.statusCode == 200) { + if (response.isSuccessful) { + final decodedData = response.data; await _profile.fetchProfileDetails(fetchPost: false); AppUtility.closeDialog(); _isLoading.value = false; update(); RouteManagement.goToBack(); AppUtility.showSnackBar( - StringValues.updateProfileSuccessful, + decodedData['message'], StringValues.success, ); } else { + final decodedData = response.data; AppUtility.closeDialog(); _isLoading.value = false; update(); @@ -79,33 +74,12 @@ class EditDOBController extends GetxController { StringValues.error, ); } - } on SocketException { - AppUtility.closeDialog(); - _isLoading.value = false; - update(); - AppUtility.printLog(StringValues.internetConnError); - AppUtility.showSnackBar( - StringValues.internetConnError, StringValues.error); - } on TimeoutException { - AppUtility.closeDialog(); - _isLoading.value = false; - update(); - AppUtility.printLog(StringValues.connTimedOut); - AppUtility.showSnackBar(StringValues.connTimedOut, StringValues.error); - } on FormatException catch (e) { - AppUtility.closeDialog(); - _isLoading.value = false; - update(); - AppUtility.printLog(StringValues.formatExcError); - AppUtility.printLog(e); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); } catch (exc) { AppUtility.closeDialog(); _isLoading.value = false; update(); - AppUtility.printLog(StringValues.errorOccurred); - AppUtility.printLog(exc); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); + AppUtility.log('Error: $exc', tag: 'error'); + AppUtility.showSnackBar('Error: $exc', StringValues.error); } } diff --git a/lib/modules/profile/controllers/edit_gender_controller.dart b/lib/modules/profile/controllers/edit_gender_controller.dart index 6af7231..1a62d7a 100644 --- a/lib/modules/profile/controllers/edit_gender_controller.dart +++ b/lib/modules/profile/controllers/edit_gender_controller.dart @@ -1,6 +1,4 @@ import 'dart:async'; -import 'dart:convert'; -import 'dart:io'; import 'package:get/get.dart'; import 'package:http/http.dart' as http; @@ -49,11 +47,8 @@ class EditGenderController extends GetxController { return; } - final body = { - 'gender': gender, - }; + final body = {'gender': gender}; - AppUtility.printLog("Update Gender Request..."); AppUtility.showLoadingDialog(); _isLoading.value = true; update(); @@ -61,19 +56,19 @@ class EditGenderController extends GetxController { try { final response = await _apiProvider.updateProfile(_auth.token, body); - final decodedData = jsonDecode(utf8.decode(response.bodyBytes)); - - if (response.statusCode == 200) { + if (response.isSuccessful) { + final decodedData = response.data; await _profile.fetchProfileDetails(fetchPost: false); AppUtility.closeDialog(); _isLoading.value = false; update(); RouteManagement.goToBack(); AppUtility.showSnackBar( - StringValues.updateProfileSuccessful, + decodedData['message'], StringValues.success, ); } else { + final decodedData = response.data; AppUtility.closeDialog(); _isLoading.value = false; update(); @@ -82,33 +77,12 @@ class EditGenderController extends GetxController { StringValues.error, ); } - } on SocketException { - AppUtility.closeDialog(); - _isLoading.value = false; - update(); - AppUtility.printLog(StringValues.internetConnError); - AppUtility.showSnackBar( - StringValues.internetConnError, StringValues.error); - } on TimeoutException { - AppUtility.closeDialog(); - _isLoading.value = false; - update(); - AppUtility.printLog(StringValues.connTimedOut); - AppUtility.showSnackBar(StringValues.connTimedOut, StringValues.error); - } on FormatException catch (e) { - AppUtility.closeDialog(); - _isLoading.value = false; - update(); - AppUtility.printLog(StringValues.formatExcError); - AppUtility.printLog(e); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); } catch (exc) { AppUtility.closeDialog(); _isLoading.value = false; update(); - AppUtility.printLog(StringValues.errorOccurred); - AppUtility.printLog(exc); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); + AppUtility.log('Error: $exc', tag: 'error'); + AppUtility.showSnackBar('Error: $exc', StringValues.error); } } diff --git a/lib/modules/profile/controllers/edit_name_controller.dart b/lib/modules/profile/controllers/edit_name_controller.dart index 58a08c3..da83581 100644 --- a/lib/modules/profile/controllers/edit_name_controller.dart +++ b/lib/modules/profile/controllers/edit_name_controller.dart @@ -1,6 +1,4 @@ import 'dart:async'; -import 'dart:convert'; -import 'dart:io'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; @@ -68,7 +66,6 @@ class EditNameController extends GetxController { 'lname': lname, }; - AppUtility.printLog("Update Name Request..."); AppUtility.showLoadingDialog(); _isLoading.value = true; update(); @@ -76,19 +73,19 @@ class EditNameController extends GetxController { try { final response = await _apiProvider.updateProfile(_auth.token, body); - final decodedData = jsonDecode(utf8.decode(response.bodyBytes)); - - if (response.statusCode == 200) { + if (response.isSuccessful) { + final decodedData = response.data; await _profile.fetchProfileDetails(fetchPost: false); AppUtility.closeDialog(); _isLoading.value = false; update(); RouteManagement.goToBack(); AppUtility.showSnackBar( - StringValues.updateProfileSuccessful, + decodedData['message'], StringValues.success, ); } else { + final decodedData = response.data; AppUtility.closeDialog(); _isLoading.value = false; update(); @@ -97,33 +94,12 @@ class EditNameController extends GetxController { StringValues.error, ); } - } on SocketException { - AppUtility.closeDialog(); - _isLoading.value = false; - update(); - AppUtility.printLog(StringValues.internetConnError); - AppUtility.showSnackBar( - StringValues.internetConnError, StringValues.error); - } on TimeoutException { - AppUtility.closeDialog(); - _isLoading.value = false; - update(); - AppUtility.printLog(StringValues.connTimedOut); - AppUtility.showSnackBar(StringValues.connTimedOut, StringValues.error); - } on FormatException catch (e) { - AppUtility.closeDialog(); - _isLoading.value = false; - update(); - AppUtility.printLog(StringValues.formatExcError); - AppUtility.printLog(e); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); } catch (exc) { AppUtility.closeDialog(); _isLoading.value = false; update(); - AppUtility.printLog(StringValues.errorOccurred); - AppUtility.printLog(exc); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); + AppUtility.log('Error: $exc', tag: 'error'); + AppUtility.showSnackBar('Error: $exc', StringValues.error); } } diff --git a/lib/modules/profile/controllers/edit_profession_controller.dart b/lib/modules/profile/controllers/edit_profession_controller.dart index e95215d..9bdde9a 100644 --- a/lib/modules/profile/controllers/edit_profession_controller.dart +++ b/lib/modules/profile/controllers/edit_profession_controller.dart @@ -1,6 +1,4 @@ import 'dart:async'; -import 'dart:convert'; -import 'dart:io'; import 'package:flutter/widgets.dart'; import 'package:get/get.dart'; @@ -68,7 +66,6 @@ class EditProfessionController extends GetxController { final body = {'profession': profession}; - AppUtility.printLog("Update Profession Request"); AppUtility.showLoadingDialog(); _isLoading.value = true; update(); @@ -76,60 +73,33 @@ class EditProfessionController extends GetxController { try { final response = await _apiProvider.updateProfile(_auth.token, body); - final decodedData = jsonDecode(utf8.decode(response.bodyBytes)); - - if (response.statusCode == 200) { + if (response.isSuccessful) { + final decodedData = response.data; await _profile.fetchProfileDetails(fetchPost: false); AppUtility.closeDialog(); _isLoading.value = false; update(); - AppUtility.printLog("Update Profession Success"); RouteManagement.goToBack(); AppUtility.showSnackBar( - StringValues.updateProfileSuccessful, + decodedData['message'], StringValues.success, ); } else { + final decodedData = response.data; AppUtility.closeDialog(); _isLoading.value = false; update(); - AppUtility.printLog("Update Profession Error"); AppUtility.showSnackBar( decodedData[StringValues.message], StringValues.error, ); } - } on SocketException { - AppUtility.closeDialog(); - _isLoading.value = false; - update(); - AppUtility.printLog("Update Profession Error"); - AppUtility.printLog(StringValues.internetConnError); - AppUtility.showSnackBar( - StringValues.internetConnError, StringValues.error); - } on TimeoutException { - AppUtility.closeDialog(); - _isLoading.value = false; - update(); - AppUtility.printLog("Update Profession Error"); - AppUtility.printLog(StringValues.connTimedOut); - AppUtility.showSnackBar(StringValues.connTimedOut, StringValues.error); - } on FormatException catch (e) { - AppUtility.closeDialog(); - _isLoading.value = false; - update(); - AppUtility.printLog("Update Profession Error"); - AppUtility.printLog(StringValues.formatExcError); - AppUtility.printLog(e); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); } catch (exc) { AppUtility.closeDialog(); _isLoading.value = false; update(); - AppUtility.printLog("Update Profession Error"); - AppUtility.printLog(StringValues.errorOccurred); - AppUtility.printLog(exc); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); + AppUtility.log('Error: $exc', tag: 'error'); + AppUtility.showSnackBar('Error: $exc', StringValues.error); } } diff --git a/lib/modules/profile/controllers/edit_profile_picture_controller.dart b/lib/modules/profile/controllers/edit_profile_picture_controller.dart index 0bebb20..b0823a6 100644 --- a/lib/modules/profile/controllers/edit_profile_picture_controller.dart +++ b/lib/modules/profile/controllers/edit_profile_picture_controller.dart @@ -1,21 +1,16 @@ import 'dart:async'; -import 'dart:convert'; import 'dart:io'; import 'package:cloudinary/cloudinary.dart'; -import 'package:flutter/material.dart'; -import 'package:flutter_image_compress/flutter_image_compress.dart'; import 'package:get/get.dart'; import 'package:http/http.dart' as http; -import 'package:image_cropper/image_cropper.dart'; import 'package:image_picker/image_picker.dart'; -import 'package:path_provider/path_provider.dart'; import 'package:social_media_app/apis/providers/api_provider.dart'; import 'package:social_media_app/apis/services/auth_service.dart'; import 'package:social_media_app/constants/secrets.dart'; import 'package:social_media_app/constants/strings.dart'; -import 'package:social_media_app/extensions/file_extensions.dart'; import 'package:social_media_app/modules/home/controllers/profile_controller.dart'; +import 'package:social_media_app/utils/file_utility.dart'; import 'package:social_media_app/utils/utility.dart'; class EditProfilePictureController extends GetxController { @@ -39,83 +34,26 @@ class EditProfilePictureController extends GetxController { var uploadPreset = const String.fromEnvironment('CLOUDINARY_UPLOAD_PRESET', defaultValue: AppSecrets.cloudinaryUploadPreset); - Future selectSingleImage({ImageSource? imageSource}) async { - final imagePicker = ImagePicker(); - final imageCropper = ImageCropper(); - const maxImageBytes = 1048576; + Future selectProfileImage({ImageSource? imageSource}) async { + var imageFile = await FileUtility.selectImage(source: imageSource); - final pickedImage = await imagePicker.pickImage( - maxWidth: 1080.0, - maxHeight: 1080.0, - source: imageSource ?? ImageSource.gallery, - ); - - if (pickedImage != null) { - var croppedFile = await imageCropper.cropImage( - maxWidth: 1080, - maxHeight: 1080, - sourcePath: pickedImage.path, - compressFormat: ImageCompressFormat.jpg, - aspectRatio: const CropAspectRatio(ratioX: 1.0, ratioY: 1.0), - cropStyle: CropStyle.circle, - uiSettings: [ - AndroidUiSettings( - toolbarColor: Theme.of(Get.context!).scaffoldBackgroundColor, - toolbarTitle: StringValues.cropImage, - toolbarWidgetColor: Theme.of(Get.context!).colorScheme.primary, - backgroundColor: Theme.of(Get.context!).scaffoldBackgroundColor, - ), - IOSUiSettings( - title: StringValues.cropImage, - minimumAspectRatio: 1.0, - ), - ], - compressQuality: 100, - ); - - var croppedImage = File(croppedFile!.path); - File? resultFile = croppedImage; - var size = croppedImage.lengthSync(); - AppUtility.printLog('Original file size: ${resultFile.sizeToKb()} KB'); - - if (size > (5 * maxImageBytes)) { - AppUtility.showSnackBar( - 'Image size must be less than 5mb', - '', - ); - } else if (size < (maxImageBytes / 2)) { - AppUtility.printLog('Result $resultFile'); - AppUtility.printLog('Result file size: ${resultFile.sizeToKb()} KB'); - _pickedImage.value = croppedImage; - update(); - } else { - var tempDir = await getTemporaryDirectory(); - - /// --------- Compressing Image ------------------------------------ + if (imageFile == null) { + AppUtility.log('Image file is null', tag: 'error'); + return; + } - AppUtility.showLoadingDialog(message: 'Compressing...'); - var timestamp = DateTime.now().millisecondsSinceEpoch; - AppUtility.printLog('Compressing...'); - resultFile = await FlutterImageCompress.compressAndGetFile( - resultFile.path, - '${tempDir.absolute.path}/temp$timestamp.jpg', - quality: 60, - format: CompressFormat.jpeg, - ); - size = resultFile!.lengthSync(); - AppUtility.closeDialog(); + var compressdFile = await FileUtility.compressImage(imageFile.path); - /// ---------------------------------------------------------------- - AppUtility.printLog('Result $resultFile'); - AppUtility.printLog('Result file size: ${resultFile.sizeToKb()} KB'); - _pickedImage.value = croppedImage; - update(); - } + if (compressdFile == null) { + AppUtility.log('Compressed file is null', tag: 'error'); + return; } + _pickedImage.value = compressdFile; + update(); } Future chooseImage() async { - await selectSingleImage(); + await selectProfileImage(); if (_pickedImage.value == null) { AppUtility.showSnackBar( @@ -129,7 +67,6 @@ class EditProfilePictureController extends GetxController { Future _uploadProfilePicture() async { final cloudinary = Cloudinary.unsignedConfig(cloudName: cloudName); - AppUtility.printLog("Update Profile Picture Request"); var filePath = _pickedImage.value!.path; @@ -148,15 +85,15 @@ class EditProfilePictureController extends GetxController { folder: "social_media_api/avatars", progressCallback: (count, total) { var progress = ((count / total) * 100).toStringAsFixed(2); - AppUtility.printLog('Uploading : $progress %'); + AppUtility.log('Uploading : $progress %'); }, ) .then((value) { publicId = value.publicId; url = value.secureUrl; }).catchError((err) { - AppUtility.printLog(err); - AppUtility.showSnackBar('image upload failed.', StringValues.error); + AppUtility.log('Error: $err', tag: 'error'); + AppUtility.showSnackBar('Error: $err', StringValues.error); }); final body = { @@ -165,16 +102,12 @@ class EditProfilePictureController extends GetxController { }; try { - final response = await _apiProvider.uploadProfilePicture( - _auth.token, - body, - ); + final response = + await _apiProvider.uploadProfilePicture(_auth.token, body); - final decodedData = jsonDecode(utf8.decode(response.bodyBytes)); - - if (response.statusCode == 200) { + if (response.isSuccessful) { + final decodedData = response.data; AppUtility.closeDialog(); - AppUtility.printLog("Update Profile Picture Success"); await _profile.fetchProfileDetails(fetchPost: false); _isLoading.value = false; update(); @@ -183,8 +116,8 @@ class EditProfilePictureController extends GetxController { StringValues.success, ); } else { + final decodedData = response.data; AppUtility.closeDialog(); - AppUtility.printLog("Update Profile Picture Error"); _isLoading.value = false; update(); AppUtility.showSnackBar( @@ -192,53 +125,26 @@ class EditProfilePictureController extends GetxController { StringValues.error, ); } - } on SocketException { - AppUtility.closeDialog(); - AppUtility.printLog("Update Profile Picture Error"); - _isLoading.value = false; - update(); - AppUtility.printLog(StringValues.internetConnError); - AppUtility.showSnackBar( - StringValues.internetConnError, StringValues.error); - } on TimeoutException { - AppUtility.closeDialog(); - AppUtility.printLog("Update Profile Picture Error"); - _isLoading.value = false; - update(); - AppUtility.printLog(StringValues.connTimedOut); - AppUtility.showSnackBar(StringValues.connTimedOut, StringValues.error); - } on FormatException catch (e) { - AppUtility.closeDialog(); - AppUtility.printLog("Update Profile Picture Error"); - _isLoading.value = false; - update(); - AppUtility.printLog(StringValues.formatExcError); - AppUtility.printLog(e); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); } catch (exc) { AppUtility.closeDialog(); - AppUtility.printLog("Update Profile Picture Error"); _isLoading.value = false; update(); - AppUtility.printLog(StringValues.errorOccurred); - AppUtility.printLog(exc); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); + AppUtility.log('Error: $exc', tag: 'error'); + AppUtility.showSnackBar('Error: $exc', StringValues.error); } } Future _removeProfilePicture() async { - AppUtility.printLog("Remove Profile Picture Request"); AppUtility.showLoadingDialog(); _isLoading.value = true; update(); try { final response = await _apiProvider.deleteProfilePicture(_auth.token); - final decodedData = jsonDecode(utf8.decode(response.bodyBytes)); - if (response.statusCode == 200) { + if (response.isSuccessful) { + final decodedData = response.data; AppUtility.closeDialog(); - AppUtility.printLog("Remove Profile Picture Success"); await _profile.fetchProfileDetails(); _isLoading.value = false; update(); @@ -247,8 +153,8 @@ class EditProfilePictureController extends GetxController { StringValues.success, ); } else { + final decodedData = response.data; AppUtility.closeDialog(); - AppUtility.printLog("Remove Profile Picture Error"); _isLoading.value = false; update(); AppUtility.showSnackBar( @@ -256,37 +162,12 @@ class EditProfilePictureController extends GetxController { StringValues.error, ); } - } on SocketException { - AppUtility.closeDialog(); - AppUtility.printLog("Remove Profile Picture Error"); - _isLoading.value = false; - update(); - AppUtility.printLog(StringValues.internetConnError); - AppUtility.showSnackBar( - StringValues.internetConnError, StringValues.error); - } on TimeoutException { - AppUtility.closeDialog(); - AppUtility.printLog("Remove Profile Picture Error"); - _isLoading.value = false; - update(); - AppUtility.printLog(StringValues.connTimedOut); - AppUtility.showSnackBar(StringValues.connTimedOut, StringValues.error); - } on FormatException catch (e) { - AppUtility.closeDialog(); - AppUtility.printLog("Remove Profile Picture Error"); - _isLoading.value = false; - update(); - AppUtility.printLog(StringValues.formatExcError); - AppUtility.printLog(e); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); } catch (exc) { AppUtility.closeDialog(); - AppUtility.printLog("Remove Profile Picture Error"); _isLoading.value = false; update(); - AppUtility.printLog(StringValues.errorOccurred); - AppUtility.printLog(exc); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); + AppUtility.log('Error: $exc', tag: 'error'); + AppUtility.showSnackBar('Error: $exc', StringValues.error); } } diff --git a/lib/modules/profile/controllers/edit_username_controller.dart b/lib/modules/profile/controllers/edit_username_controller.dart index 94ff68e..d249180 100644 --- a/lib/modules/profile/controllers/edit_username_controller.dart +++ b/lib/modules/profile/controllers/edit_username_controller.dart @@ -1,6 +1,4 @@ import 'dart:async'; -import 'dart:convert'; -import 'dart:io'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; @@ -68,43 +66,23 @@ class EditUsernameController extends GetxController { return; } - AppUtility.printLog("Check Username Request"); - try { final response = await _apiProvider.checkUsername(_auth.token, uname); - final decodedData = jsonDecode(utf8.decode(response.bodyBytes)); - - if (response.statusCode == 200) { + if (response.isSuccessful) { + final decodedData = response.data; AppUtility.printLog(decodedData); _isUnameAvailable.value = StringValues.success; update(); - AppUtility.printLog("Check Username Success"); } else { - AppUtility.printLog(decodedData); + final decodedData = response.data; + AppUtility.log(decodedData['message'], tag: 'error'); _isUnameAvailable.value = StringValues.error; update(); - AppUtility.printLog("Check Username Error"); } - } on SocketException { - AppUtility.printLog("Check Username Error"); - AppUtility.printLog(StringValues.internetConnError); - AppUtility.showSnackBar( - StringValues.internetConnError, StringValues.error); - } on TimeoutException { - AppUtility.printLog("Check Username Error"); - AppUtility.printLog(StringValues.connTimedOut); - AppUtility.showSnackBar(StringValues.connTimedOut, StringValues.error); - } on FormatException catch (e) { - AppUtility.printLog("Check Username Error"); - AppUtility.printLog(StringValues.formatExcError); - AppUtility.printLog(e); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); } catch (exc) { - AppUtility.printLog("Check Username Error"); - AppUtility.printLog(StringValues.errorOccurred); - AppUtility.printLog(exc); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); + AppUtility.log('Error: ${exc.toString()}', tag: 'error'); + AppUtility.showSnackBar('Error: ${exc.toString()}', StringValues.error); } } @@ -117,7 +95,6 @@ class EditUsernameController extends GetxController { return; } - AppUtility.printLog("Update Username Request"); AppUtility.showLoadingDialog(); _isLoading.value = true; update(); @@ -125,60 +102,33 @@ class EditUsernameController extends GetxController { try { final response = await _apiProvider.changeUsername(_auth.token, uname); - final decodedData = jsonDecode(utf8.decode(response.bodyBytes)); - - if (response.statusCode == 200) { + if (response.isSuccessful) { + final decodedData = response.data; await _profile.fetchProfileDetails(fetchPost: false); AppUtility.closeDialog(); _isLoading.value = false; update(); - AppUtility.printLog("Update Username Success"); RouteManagement.goToBack(); AppUtility.showSnackBar( decodedData[StringValues.message], StringValues.success, ); } else { + final decodedData = response.data; AppUtility.closeDialog(); _isLoading.value = false; update(); - AppUtility.printLog("Update Username Error"); AppUtility.showSnackBar( decodedData[StringValues.message], StringValues.error, ); } - } on SocketException { - AppUtility.closeDialog(); - _isLoading.value = false; - update(); - AppUtility.printLog("Update Username Error"); - AppUtility.printLog(StringValues.internetConnError); - AppUtility.showSnackBar( - StringValues.internetConnError, StringValues.error); - } on TimeoutException { - AppUtility.closeDialog(); - _isLoading.value = false; - update(); - AppUtility.printLog("Update Username Error"); - AppUtility.printLog(StringValues.connTimedOut); - AppUtility.showSnackBar(StringValues.connTimedOut, StringValues.error); - } on FormatException catch (e) { - AppUtility.closeDialog(); - _isLoading.value = false; - update(); - AppUtility.printLog("Update Username Error"); - AppUtility.printLog(StringValues.formatExcError); - AppUtility.printLog(e); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); } catch (exc) { AppUtility.closeDialog(); _isLoading.value = false; update(); - AppUtility.printLog("Update Username Error"); - AppUtility.printLog(StringValues.errorOccurred); - AppUtility.printLog(exc); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); + AppUtility.log('Error: ${exc.toString()}', tag: 'error'); + AppUtility.showSnackBar('Error: ${exc.toString()}', StringValues.error); } } diff --git a/lib/modules/profile/controllers/edit_website_controller.dart b/lib/modules/profile/controllers/edit_website_controller.dart index 48ac15c..f329c16 100644 --- a/lib/modules/profile/controllers/edit_website_controller.dart +++ b/lib/modules/profile/controllers/edit_website_controller.dart @@ -1,6 +1,4 @@ import 'dart:async'; -import 'dart:convert'; -import 'dart:io'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; @@ -63,7 +61,6 @@ class EditWebsiteController extends GetxController { final body = {'website': website}; - AppUtility.printLog("Update Website Request"); AppUtility.showLoadingDialog(); _isLoading.value = true; update(); @@ -71,60 +68,33 @@ class EditWebsiteController extends GetxController { try { final response = await _apiProvider.updateProfile(_auth.token, body); - final decodedData = jsonDecode(utf8.decode(response.bodyBytes)); - - if (response.statusCode == 200) { + if (response.isSuccessful) { + final decodedData = response.data; await _profile.fetchProfileDetails(fetchPost: false); AppUtility.closeDialog(); _isLoading.value = false; update(); - AppUtility.printLog("Update Website Success"); RouteManagement.goToBack(); AppUtility.showSnackBar( decodedData[StringValues.message], StringValues.success, ); } else { + final decodedData = response.data; AppUtility.closeDialog(); _isLoading.value = false; update(); - AppUtility.printLog("Update Website Error"); AppUtility.showSnackBar( decodedData[StringValues.message], StringValues.error, ); } - } on SocketException { - AppUtility.closeDialog(); - _isLoading.value = false; - update(); - AppUtility.printLog("Update Website Error"); - AppUtility.printLog(StringValues.internetConnError); - AppUtility.showSnackBar( - StringValues.internetConnError, StringValues.error); - } on TimeoutException { - AppUtility.closeDialog(); - _isLoading.value = false; - update(); - AppUtility.printLog("Update Website Error"); - AppUtility.printLog(StringValues.connTimedOut); - AppUtility.showSnackBar(StringValues.connTimedOut, StringValues.error); - } on FormatException catch (e) { - AppUtility.closeDialog(); - _isLoading.value = false; - update(); - AppUtility.printLog("Update Website Error"); - AppUtility.printLog(StringValues.formatExcError); - AppUtility.printLog(e); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); } catch (exc) { AppUtility.closeDialog(); _isLoading.value = false; update(); - AppUtility.printLog("Update Website Error"); - AppUtility.printLog(StringValues.errorOccurred); - AppUtility.printLog(exc); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); + AppUtility.log('Error: $exc', tag: 'error'); + AppUtility.showSnackBar('Error: $exc', StringValues.error); } } diff --git a/lib/modules/settings/controllers/account_privacy_controller.dart b/lib/modules/settings/controllers/account_privacy_controller.dart index a60ee52..35ef516 100644 --- a/lib/modules/settings/controllers/account_privacy_controller.dart +++ b/lib/modules/settings/controllers/account_privacy_controller.dart @@ -1,6 +1,4 @@ import 'dart:async'; -import 'dart:convert'; -import 'dart:io'; import 'package:get/get.dart'; import 'package:http/http.dart' as http; @@ -30,7 +28,6 @@ class AccountPrivacyController extends GetxController { final body = {'isPrivate': "$accountPrivacy"}; - AppUtility.printLog("Update AccountPrivacy Request"); AppUtility.showLoadingDialog(); _isLoading.value = true; update(); @@ -38,61 +35,32 @@ class AccountPrivacyController extends GetxController { try { final response = await _apiProvider.updateProfile(_auth.token, body); - final decodedData = jsonDecode(utf8.decode(response.bodyBytes)); - - AppUtility.printLog(response.statusCode); - - if (response.statusCode == 200) { + if (response.isSuccessful) { + final decodedData = response.data; await _profile.fetchProfileDetails(fetchPost: false); AppUtility.closeDialog(); _isLoading.value = false; update(); - AppUtility.printLog("Update AccountPrivacy Success"); AppUtility.showSnackBar( - StringValues.updateProfileSuccessful, + decodedData['message'], StringValues.success, ); } else { - AppUtility.printLog("Update AccountPrivacy Error"); + final decodedData = response.data; AppUtility.closeDialog(); _isLoading.value = false; update(); AppUtility.showSnackBar( - decodedData[StringValues.message], + decodedData['message'], StringValues.error, ); } - } on SocketException { - AppUtility.closeDialog(); - _isLoading.value = false; - update(); - AppUtility.printLog("Update AccountPrivacy Error"); - AppUtility.printLog(StringValues.internetConnError); - AppUtility.showSnackBar( - StringValues.internetConnError, StringValues.error); - } on TimeoutException { - AppUtility.closeDialog(); - _isLoading.value = false; - update(); - AppUtility.printLog("Update AccountPrivacy Error"); - AppUtility.printLog(StringValues.connTimedOut); - AppUtility.showSnackBar(StringValues.connTimedOut, StringValues.error); - } on FormatException catch (e) { - AppUtility.closeDialog(); - _isLoading.value = false; - update(); - AppUtility.printLog("Update AccountPrivacy Error"); - AppUtility.printLog(StringValues.formatExcError); - AppUtility.printLog(e); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); } catch (exc) { AppUtility.closeDialog(); _isLoading.value = false; update(); - AppUtility.printLog("Update AccountPrivacy Error"); - AppUtility.printLog(StringValues.errorOccurred); - AppUtility.printLog(exc); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); + AppUtility.log('Error: $exc', tag: 'error'); + AppUtility.showSnackBar('Error: $exc', StringValues.error); } } diff --git a/lib/modules/settings/controllers/change_email_controller.dart b/lib/modules/settings/controllers/change_email_controller.dart index cb40fb8..afab9e3 100644 --- a/lib/modules/settings/controllers/change_email_controller.dart +++ b/lib/modules/settings/controllers/change_email_controller.dart @@ -1,6 +1,4 @@ import 'dart:async'; -import 'dart:convert'; -import 'dart:io'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; @@ -51,7 +49,6 @@ class ChangeEmailController extends GetxController { final body = {'email': email}; - AppUtility.printLog("Send Change Email OTP Request"); AppUtility.showLoadingDialog(); _isLoading.value = true; update(); @@ -59,10 +56,8 @@ class ChangeEmailController extends GetxController { try { final response = await _apiProvider.sendChangeEmailOtp(_auth.token, body); - final decodedData = jsonDecode(utf8.decode(response.bodyBytes)); - - if (response.statusCode == 200) { - AppUtility.printLog("Send Change Email OTP Success"); + if (response.isSuccessful) { + final decodedData = response.data; AppUtility.closeDialog(); _isLoading.value = false; _otpSent.value = true; @@ -72,46 +67,21 @@ class ChangeEmailController extends GetxController { StringValues.success, ); } else { + final decodedData = response.data; AppUtility.closeDialog(); _isLoading.value = false; update(); - AppUtility.printLog("Send Change Email OTP Error"); AppUtility.showSnackBar( decodedData[StringValues.message], StringValues.error, ); } - } on SocketException { - AppUtility.closeDialog(); - _isLoading.value = false; - update(); - AppUtility.printLog("Send Change Email OTP Error"); - AppUtility.printLog(StringValues.internetConnError); - AppUtility.showSnackBar( - StringValues.internetConnError, StringValues.error); - } on TimeoutException { - AppUtility.closeDialog(); - _isLoading.value = false; - update(); - AppUtility.printLog("Send Change Email OTP Error"); - AppUtility.printLog(StringValues.connTimedOut); - AppUtility.showSnackBar(StringValues.connTimedOut, StringValues.error); - } on FormatException catch (e) { - AppUtility.closeDialog(); - _isLoading.value = false; - update(); - AppUtility.printLog("Send Change Email OTP Error"); - AppUtility.printLog(StringValues.formatExcError); - AppUtility.printLog(e); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); } catch (exc) { AppUtility.closeDialog(); _isLoading.value = false; update(); - AppUtility.printLog("Send Change Email OTP Error"); - AppUtility.printLog(StringValues.errorOccurred); - AppUtility.printLog(exc); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); + AppUtility.log('Error: $exc', tag: 'error'); + AppUtility.showSnackBar('Error: $exc', StringValues.error); } } @@ -136,7 +106,6 @@ class ChangeEmailController extends GetxController { 'email': email, }; - AppUtility.printLog("Change Email Request"); AppUtility.showLoadingDialog(); _isLoading.value = true; update(); @@ -144,10 +113,8 @@ class ChangeEmailController extends GetxController { try { final response = await _apiProvider.changeEmail(_auth.token, body); - final decodedData = jsonDecode(utf8.decode(response.bodyBytes)); - - if (response.statusCode == 200) { - AppUtility.printLog("Change Email Success"); + if (response.isSuccessful) { + final decodedData = response.data; await profile.fetchProfileDetails(fetchPost: false); AppUtility.closeDialog(); _isLoading.value = false; @@ -158,46 +125,21 @@ class ChangeEmailController extends GetxController { StringValues.success, ); } else { + final decodedData = response.data; AppUtility.closeDialog(); _isLoading.value = false; update(); - AppUtility.printLog("Change Email Error"); AppUtility.showSnackBar( decodedData[StringValues.message], StringValues.error, ); } - } on SocketException { - AppUtility.closeDialog(); - _isLoading.value = false; - update(); - AppUtility.printLog("Change Email Error"); - AppUtility.printLog(StringValues.internetConnError); - AppUtility.showSnackBar( - StringValues.internetConnError, StringValues.error); - } on TimeoutException { - AppUtility.closeDialog(); - _isLoading.value = false; - update(); - AppUtility.printLog("Change Email Error"); - AppUtility.printLog(StringValues.connTimedOut); - AppUtility.showSnackBar(StringValues.connTimedOut, StringValues.error); - } on FormatException catch (e) { - AppUtility.closeDialog(); - _isLoading.value = false; - update(); - AppUtility.printLog("Change Email Error"); - AppUtility.printLog(StringValues.formatExcError); - AppUtility.printLog(e); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); } catch (exc) { AppUtility.closeDialog(); _isLoading.value = false; update(); - AppUtility.printLog("Change Email Error"); - AppUtility.printLog(StringValues.errorOccurred); - AppUtility.printLog(exc); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); + AppUtility.log('Error: $exc', tag: 'error'); + AppUtility.showSnackBar('Error: $exc', StringValues.error); } } diff --git a/lib/modules/settings/controllers/change_password_controller.dart b/lib/modules/settings/controllers/change_password_controller.dart index 6d2d5fb..d78332c 100644 --- a/lib/modules/settings/controllers/change_password_controller.dart +++ b/lib/modules/settings/controllers/change_password_controller.dart @@ -1,6 +1,4 @@ import 'dart:async'; -import 'dart:convert'; -import 'dart:io'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; @@ -77,7 +75,6 @@ class ChangePasswordController extends GetxController { 'confirmPassword': confPassword, }; - AppUtility.printLog("Change Password Request"); AppUtility.showLoadingDialog(); _isLoading.value = true; update(); @@ -85,55 +82,32 @@ class ChangePasswordController extends GetxController { try { final response = await _apiProvider.changePassword(_auth.token, body); - final decodedData = jsonDecode(utf8.decode(response.bodyBytes)); - - if (response.statusCode == 200) { + if (response.isSuccessful) { + final decodedData = response.data; AppUtility.closeDialog(); _isLoading.value = false; update(); - AppUtility.printLog("Change Password Success"); RouteManagement.goToBack(); + AppUtility.showSnackBar( + decodedData['message'], + StringValues.success, + ); } else { + final decodedData = response.data; AppUtility.closeDialog(); _isLoading.value = false; update(); - AppUtility.printLog("Change Password Error"); AppUtility.showSnackBar( decodedData[StringValues.message], StringValues.error, ); } - } on SocketException { - AppUtility.closeDialog(); - _isLoading.value = false; - update(); - AppUtility.printLog("Change Password Error"); - AppUtility.printLog(StringValues.internetConnError); - AppUtility.showSnackBar( - StringValues.internetConnError, StringValues.error); - } on TimeoutException { - AppUtility.closeDialog(); - _isLoading.value = false; - update(); - AppUtility.printLog("Change Password Error"); - AppUtility.printLog(StringValues.connTimedOut); - AppUtility.showSnackBar(StringValues.connTimedOut, StringValues.error); - } on FormatException catch (e) { - AppUtility.closeDialog(); - _isLoading.value = false; - update(); - AppUtility.printLog("Change Password Error"); - AppUtility.printLog(StringValues.formatExcError); - AppUtility.printLog(e); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); } catch (exc) { AppUtility.closeDialog(); _isLoading.value = false; update(); - AppUtility.printLog("Change Password Error"); - AppUtility.printLog(StringValues.errorOccurred); - AppUtility.printLog(exc); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); + AppUtility.log('Error: $exc', tag: 'error'); + AppUtility.showSnackBar('Error: $exc', StringValues.error); } } diff --git a/lib/modules/settings/controllers/change_phone_controller.dart b/lib/modules/settings/controllers/change_phone_controller.dart index 571ed77..467e935 100644 --- a/lib/modules/settings/controllers/change_phone_controller.dart +++ b/lib/modules/settings/controllers/change_phone_controller.dart @@ -1,6 +1,4 @@ import 'dart:async'; -import 'dart:convert'; -import 'dart:io'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; @@ -83,7 +81,6 @@ class ChangePhoneController extends GetxController { "countryCode": code.dialCode, }; - AppUtility.printLog("Send Change Phone OTP Request"); AppUtility.showLoadingDialog(); _isLoading.value = true; update(); @@ -92,10 +89,8 @@ class ChangePhoneController extends GetxController { final response = await _apiProvider.sendAddChangePhoneOtp(_auth.token, body); - final decodedData = jsonDecode(utf8.decode(response.bodyBytes)); - - if (response.statusCode == 200) { - AppUtility.printLog("Send Change Phone OTP Success"); + if (response.isSuccessful) { + final decodedData = response.data; AppUtility.closeDialog(); _isLoading.value = false; _otpSent.value = true; @@ -105,46 +100,21 @@ class ChangePhoneController extends GetxController { StringValues.success, ); } else { + final decodedData = response.data; AppUtility.closeDialog(); _isLoading.value = false; update(); - AppUtility.printLog("Send Change Phone OTP Error"); AppUtility.showSnackBar( decodedData[StringValues.message], StringValues.error, ); } - } on SocketException { - AppUtility.closeDialog(); - _isLoading.value = false; - update(); - AppUtility.printLog("Send Change Phone OTP Error"); - AppUtility.printLog(StringValues.internetConnError); - AppUtility.showSnackBar( - StringValues.internetConnError, StringValues.error); - } on TimeoutException { - AppUtility.closeDialog(); - _isLoading.value = false; - update(); - AppUtility.printLog("Send Change Phone OTP Error"); - AppUtility.printLog(StringValues.connTimedOut); - AppUtility.showSnackBar(StringValues.connTimedOut, StringValues.error); - } on FormatException catch (e) { - AppUtility.closeDialog(); - _isLoading.value = false; - update(); - AppUtility.printLog("Send Change Phone OTP Error"); - AppUtility.printLog(StringValues.formatExcError); - AppUtility.printLog(e); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); } catch (exc) { AppUtility.closeDialog(); _isLoading.value = false; update(); - AppUtility.printLog("Send Change Phone OTP Error"); - AppUtility.printLog(StringValues.errorOccurred); - AppUtility.printLog(exc); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); + AppUtility.log('Error: $exc', tag: 'error'); + AppUtility.showSnackBar('Error: $exc', StringValues.error); } } @@ -171,7 +141,6 @@ class ChangePhoneController extends GetxController { "countryCode": code.dialCode, }; - AppUtility.printLog("Change Phone Request"); AppUtility.showLoadingDialog(); _isLoading.value = true; update(); @@ -179,10 +148,8 @@ class ChangePhoneController extends GetxController { try { final response = await _apiProvider.addChangePhone(_auth.token, body); - final decodedData = jsonDecode(utf8.decode(response.bodyBytes)); - - if (response.statusCode == 200) { - AppUtility.printLog("Change Phone Success"); + if (response.isSuccessful) { + final decodedData = response.data; await profile.fetchProfileDetails(fetchPost: false); AppUtility.closeDialog(); _isLoading.value = false; @@ -193,46 +160,21 @@ class ChangePhoneController extends GetxController { StringValues.success, ); } else { + final decodedData = response.data; AppUtility.closeDialog(); _isLoading.value = false; update(); - AppUtility.printLog("Change Phone Error"); AppUtility.showSnackBar( decodedData[StringValues.message], StringValues.error, ); } - } on SocketException { - AppUtility.closeDialog(); - _isLoading.value = false; - update(); - AppUtility.printLog("Change Phone Error"); - AppUtility.printLog(StringValues.internetConnError); - AppUtility.showSnackBar( - StringValues.internetConnError, StringValues.error); - } on TimeoutException { - AppUtility.closeDialog(); - _isLoading.value = false; - update(); - AppUtility.printLog("Change Phone Error"); - AppUtility.printLog(StringValues.connTimedOut); - AppUtility.showSnackBar(StringValues.connTimedOut, StringValues.error); - } on FormatException catch (e) { - AppUtility.closeDialog(); - _isLoading.value = false; - update(); - AppUtility.printLog("Change Phone Error"); - AppUtility.printLog(StringValues.formatExcError); - AppUtility.printLog(e); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); } catch (exc) { AppUtility.closeDialog(); _isLoading.value = false; update(); - AppUtility.printLog("Change Phone Error"); - AppUtility.printLog(StringValues.errorOccurred); - AppUtility.printLog(exc); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); + AppUtility.log('Error: $exc', tag: 'error'); + AppUtility.showSnackBar('Error: $exc', StringValues.error); } } diff --git a/lib/modules/settings/controllers/deactivate_account_controller.dart b/lib/modules/settings/controllers/deactivate_account_controller.dart index 96bc790..276c83d 100644 --- a/lib/modules/settings/controllers/deactivate_account_controller.dart +++ b/lib/modules/settings/controllers/deactivate_account_controller.dart @@ -1,6 +1,4 @@ import 'dart:async'; -import 'dart:convert'; -import 'dart:io'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; @@ -45,11 +43,10 @@ class DeactivateAccountController extends GetxController { } final body = { - 'email': profile.profileDetails!.user!.email, + 'email': profile.profileDetails!.user!.email.trim(), "password": passwordTextController.text.trim(), }; - AppUtility.printLog("Deactivate Account Request"); AppUtility.showLoadingDialog(); _isLoading.value = true; update(); @@ -57,10 +54,8 @@ class DeactivateAccountController extends GetxController { try { final response = await _apiProvider.deactivateAccount(_auth.token, body); - final decodedData = jsonDecode(utf8.decode(response.bodyBytes)); - - if (response.statusCode == 200) { - AppUtility.printLog("Deactivate Account Success"); + if (response.isSuccessful) { + final decodedData = response.data; await _auth.logout(); AppUtility.closeDialog(); _isLoading.value = false; @@ -71,46 +66,21 @@ class DeactivateAccountController extends GetxController { StringValues.success, ); } else { + final decodedData = response.data; AppUtility.closeDialog(); _isLoading.value = false; update(); - AppUtility.printLog("Deactivate Account Error"); AppUtility.showSnackBar( decodedData[StringValues.message], StringValues.error, ); } - } on SocketException { - AppUtility.closeDialog(); - _isLoading.value = false; - update(); - AppUtility.printLog("Deactivate Account Error"); - AppUtility.printLog(StringValues.internetConnError); - AppUtility.showSnackBar( - StringValues.internetConnError, StringValues.error); - } on TimeoutException { - AppUtility.closeDialog(); - _isLoading.value = false; - update(); - AppUtility.printLog("Deactivate Account Error"); - AppUtility.printLog(StringValues.connTimedOut); - AppUtility.showSnackBar(StringValues.connTimedOut, StringValues.error); - } on FormatException catch (e) { - AppUtility.closeDialog(); - _isLoading.value = false; - update(); - AppUtility.printLog("Deactivate Account Error"); - AppUtility.printLog(StringValues.formatExcError); - AppUtility.printLog(e); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); } catch (exc) { AppUtility.closeDialog(); _isLoading.value = false; update(); - AppUtility.printLog("Deactivate Account Error"); - AppUtility.printLog(StringValues.errorOccurred); - AppUtility.printLog(exc); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); + AppUtility.log('Error: $exc', tag: 'error'); + AppUtility.showSnackBar('Error: $exc', StringValues.error); } } diff --git a/lib/modules/user/user_details_controller.dart b/lib/modules/user/user_details_controller.dart index 0714fb5..6bea097 100644 --- a/lib/modules/user/user_details_controller.dart +++ b/lib/modules/user/user_details_controller.dart @@ -1,6 +1,4 @@ import 'dart:async'; -import 'dart:convert'; -import 'dart:io'; import 'package:get/get.dart'; import 'package:http/http.dart' as http; @@ -69,7 +67,6 @@ class UserDetailsController extends GetxController { return; } - AppUtility.printLog("Get User Profile Details Request..."); _isLoading.value = true; update(); @@ -77,9 +74,8 @@ class UserDetailsController extends GetxController { final response = await _apiProvider.getUserDetailsById(_auth.token, userId); - final decodedData = jsonDecode(utf8.decode(response.bodyBytes)); - - if (response.statusCode == 200) { + if (response.isSuccessful) { + final decodedData = response.data; setUserDetails = UserDetailsResponse.fromJson(decodedData); _isLoading.value = false; update(); @@ -98,6 +94,7 @@ class UserDetailsController extends GetxController { } } } else { + final decodedData = response.data; _isLoading.value = false; update(); AppUtility.showSnackBar( @@ -105,29 +102,11 @@ class UserDetailsController extends GetxController { StringValues.error, ); } - } on SocketException { - _isLoading.value = false; - update(); - AppUtility.printLog(StringValues.internetConnError); - AppUtility.showSnackBar( - StringValues.internetConnError, StringValues.error); - } on TimeoutException { - _isLoading.value = false; - update(); - AppUtility.printLog(StringValues.connTimedOut); - AppUtility.showSnackBar(StringValues.connTimedOut, StringValues.error); - } on FormatException catch (e) { - _isLoading.value = false; - update(); - AppUtility.printLog(StringValues.formatExcError); - AppUtility.printLog(e); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); } catch (exc) { _isLoading.value = false; update(); - AppUtility.printLog(StringValues.errorOccurred); - AppUtility.printLog(exc); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); + AppUtility.log('Error: ${exc.toString()}', tag: 'error'); + AppUtility.showSnackBar('Error: ${exc.toString()}', StringValues.error); } } @@ -142,7 +121,6 @@ class UserDetailsController extends GetxController { return; } - AppUtility.printLog("Get User Profile Details Request..."); _isLoading.value = true; update(); @@ -150,9 +128,8 @@ class UserDetailsController extends GetxController { final response = await _apiProvider.getUserDetailsByUsername(_auth.token, username); - final decodedData = jsonDecode(utf8.decode(response.bodyBytes)); - - if (response.statusCode == 200) { + if (response.isSuccessful) { + final decodedData = response.data; setUserDetails = UserDetailsResponse.fromJson(decodedData); _isLoading.value = false; update(); @@ -171,6 +148,7 @@ class UserDetailsController extends GetxController { } } } else { + final decodedData = response.data; _isLoading.value = false; update(); AppUtility.showSnackBar( @@ -178,34 +156,15 @@ class UserDetailsController extends GetxController { StringValues.error, ); } - } on SocketException { - _isLoading.value = false; - update(); - AppUtility.printLog(StringValues.internetConnError); - AppUtility.showSnackBar( - StringValues.internetConnError, StringValues.error); - } on TimeoutException { - _isLoading.value = false; - update(); - AppUtility.printLog(StringValues.connTimedOut); - AppUtility.showSnackBar(StringValues.connTimedOut, StringValues.error); - } on FormatException catch (e) { - _isLoading.value = false; - update(); - AppUtility.printLog(StringValues.formatExcError); - AppUtility.printLog(e); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); } catch (exc) { _isLoading.value = false; update(); - AppUtility.printLog(StringValues.errorOccurred); - AppUtility.printLog(exc); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); + AppUtility.log('Error: ${exc.toString()}', tag: 'error'); + AppUtility.showSnackBar('Error: ${exc.toString()}', StringValues.error); } } Future _fetchUserPosts() async { - AppUtility.printLog("Fetching Profile Posts Request"); _isPostLoading.value = true; update(); @@ -235,12 +194,12 @@ class UserDetailsController extends GetxController { } catch (exc) { _isPostLoading.value = false; update(); + AppUtility.log('Error: ${exc.toString()}', tag: 'error'); AppUtility.showSnackBar('Error: ${exc.toString()}', StringValues.error); } } Future _loadMoreUserPosts({int? page}) async { - AppUtility.printLog("Fetching More Profile Posts Request"); _isMorePostLoading.value = true; update(); @@ -270,6 +229,7 @@ class UserDetailsController extends GetxController { } catch (exc) { _isMorePostLoading.value = false; update(); + AppUtility.log('Error: ${exc.toString()}', tag: 'error'); AppUtility.showSnackBar('Error: ${exc.toString()}', StringValues.error); } } @@ -334,6 +294,7 @@ class UserDetailsController extends GetxController { } } catch (exc) { _toggleFollowUser(user); + AppUtility.log('Error: ${exc.toString()}', tag: 'error'); AppUtility.showSnackBar('Error: ${exc.toString()}', StringValues.error); } } @@ -362,6 +323,7 @@ class UserDetailsController extends GetxController { } } catch (exc) { _toggleFollowUser(user); + AppUtility.log('Error: ${exc.toString()}', tag: 'error'); AppUtility.showSnackBar('Error: ${exc.toString()}', StringValues.error); } } diff --git a/lib/modules/verify_password/verify_password_controller.dart b/lib/modules/verify_password/verify_password_controller.dart index a907c74..d3d38dc 100644 --- a/lib/modules/verify_password/verify_password_controller.dart +++ b/lib/modules/verify_password/verify_password_controller.dart @@ -1,6 +1,4 @@ import 'dart:async'; -import 'dart:convert'; -import 'dart:io'; import 'package:flutter/widgets.dart'; import 'package:get/get.dart'; @@ -46,7 +44,6 @@ class VerifyPasswordController extends GetxController { var cb = Get.arguments; - AppUtility.printLog("Verify Password Request"); AppUtility.showLoadingDialog(); _isLoading.value = true; update(); @@ -54,56 +51,28 @@ class VerifyPasswordController extends GetxController { try { final response = await _apiProvider.verifyPassword(_auth.token, password); - final decodedData = jsonDecode(utf8.decode(response.bodyBytes)); - - if (response.statusCode == 200) { + if (response.isSuccessful) { AppUtility.closeDialog(); _isLoading.value = false; update(); - AppUtility.printLog("Verify Password Success"); RouteManagement.goToBack(); cb(); } else { + final decodedData = response.data; AppUtility.closeDialog(); _isLoading.value = false; update(); - AppUtility.printLog("Verify Password Error"); AppUtility.showSnackBar( decodedData[StringValues.message], StringValues.error, ); } - } on SocketException { - AppUtility.closeDialog(); - _isLoading.value = false; - update(); - AppUtility.printLog("Verify Password Error"); - AppUtility.printLog(StringValues.internetConnError); - AppUtility.showSnackBar( - StringValues.internetConnError, StringValues.error); - } on TimeoutException { - AppUtility.closeDialog(); - _isLoading.value = false; - update(); - AppUtility.printLog("Verify Password Error"); - AppUtility.printLog(StringValues.connTimedOut); - AppUtility.showSnackBar(StringValues.connTimedOut, StringValues.error); - } on FormatException catch (e) { - AppUtility.closeDialog(); - _isLoading.value = false; - update(); - AppUtility.printLog("Verify Password Error"); - AppUtility.printLog(StringValues.formatExcError); - AppUtility.printLog(e); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); } catch (exc) { AppUtility.closeDialog(); _isLoading.value = false; update(); - AppUtility.printLog("Verify Password Error"); - AppUtility.printLog(StringValues.errorOccurred); - AppUtility.printLog(exc); - AppUtility.showSnackBar(StringValues.errorOccurred, StringValues.error); + AppUtility.log('Error: $exc', tag: 'error'); + AppUtility.showSnackBar('Error: $exc', StringValues.error); } } diff --git a/lib/utils/file_utility.dart b/lib/utils/file_utility.dart index b42b38a..76a3186 100644 --- a/lib/utils/file_utility.dart +++ b/lib/utils/file_utility.dart @@ -142,6 +142,32 @@ abstract class FileUtility { return imageFile; } + static Future selectImage({ImageSource? source}) async { + final imagePicker = ImagePicker(); + + final pickedImage = await imagePicker.pickImage( + source: source ?? ImageSource.gallery, + imageQuality: 100, + ); + + if (pickedImage == null) { + AppUtility.log('No image selected'); + return null; + } + + var imageFile = File(pickedImage.path); + var size = imageFile.lengthSync(); + + if (size > (5 * maxImageBytes)) { + AppUtility.showSnackBar( + 'Image size must be less than 5mb', + '', + ); + return null; + } + return imageFile; + } + static Future?> selectMultipleImages() async { var fileList = []; final imagePicker = ImagePicker();