diff --git a/assets/images/wrong_answer.gif b/assets/images/wrong_answer.gif new file mode 100644 index 0000000..44f1d38 Binary files /dev/null and b/assets/images/wrong_answer.gif differ diff --git a/assets/langs/ar-SA.json b/assets/langs/ar-SA.json index 1c5851a..59c0814 100644 --- a/assets/langs/ar-SA.json +++ b/assets/langs/ar-SA.json @@ -500,5 +500,9 @@ "codeExpire": "انتهت صلاحية رمز التحقق", "typeheretoreply": "اكتب هنا للرد", "favorite": "مفضلتي", - "searchfromchat": "البحث من الدردشة" + "searchfromchat": "البحث من الدردشة", + "yourAnswerCorrect": "إجابتك صحيحة", + "youMissedTheQuestion": "فاتك !! أنت خارج اللعبة. لكن يمكنك المتابعة.", + "wrongAnswer": "إجابة خاطئة! أنت خارج اللعبة. لكن يمكنك المتابعة." + } \ No newline at end of file diff --git a/assets/langs/en-US.json b/assets/langs/en-US.json index b4b06f0..b0ab50e 100644 --- a/assets/langs/en-US.json +++ b/assets/langs/en-US.json @@ -500,6 +500,9 @@ "allQuestionsCorrect": "You have answered all questions correct", "typeheretoreply": "Type here to reply", "favorite" : "My Favorites", - "searchfromchat": "Search from chat" + "searchfromchat": "Search from chat", + "yourAnswerCorrect": "Your answer is correct", + "youMissedTheQuestion": "You Missed !! You are out of the game. But you can follow up.", + "wrongAnswer": "Wrong Answer! You are out of the game. But you can follow up." } \ No newline at end of file diff --git a/ios/.gitignore b/ios/.gitignore index 151026b..d032e39 100644 --- a/ios/.gitignore +++ b/ios/.gitignore @@ -31,3 +31,8 @@ Runner/GeneratedPluginRegistrant.* !default.mode2v3 !default.pbxuser !default.perspectivev3 + +ios/Podfile +ios/Runner/Runner.entitlements + + diff --git a/ios/Runner/Runner.entitlements b/ios/Runner/Runner.entitlements new file mode 100644 index 0000000..304aa00 --- /dev/null +++ b/ios/Runner/Runner.entitlements @@ -0,0 +1,30 @@ + + + + + aps-environment + development + com.apple.developer.icloud-container-identifiers + + iCloud.com.cloudsolutions.mohemm + + com.apple.developer.icloud-services + + CloudDocuments + + com.apple.developer.networking.HotspotConfiguration + + com.apple.developer.networking.networkextension + + com.apple.developer.networking.wifi-info + + com.apple.developer.nfc.readersession.formats + + TAG + + com.apple.developer.ubiquity-container-identifiers + + iCloud.com.cloudsolutions.mohemm + + + diff --git a/lib/api/api_client.dart b/lib/api/api_client.dart index 7a6f668..1e66d45 100644 --- a/lib/api/api_client.dart +++ b/lib/api/api_client.dart @@ -18,8 +18,7 @@ class APIError { APIError(this.errorCode, this.errorMessage); - Map toJson() => - {'errorCode': errorCode, 'errorMessage': errorMessage}; + Map toJson() => {'errorCode': errorCode, 'errorMessage': errorMessage}; @override String toString() { @@ -54,8 +53,7 @@ APIException _throwAPIException(Response response) { return APIException(APIException.INTERNAL_SERVER_ERROR); case 444: var downloadUrl = response.headers["location"]; - return APIException(APIException.UPGRADE_REQUIRED, - arguments: downloadUrl); + return APIException(APIException.UPGRADE_REQUIRED, arguments: downloadUrl); default: return APIException(APIException.OTHER); } @@ -68,13 +66,8 @@ class ApiClient { factory ApiClient() => _instance; - Future postJsonForObject( - FactoryConstructor factoryConstructor, String url, T jsonObject, - {String? token, - Map? queryParameters, - Map? headers, - int retryTimes = 0, - bool isFormData = false}) async { + Future postJsonForObject(FactoryConstructor factoryConstructor, String url, T jsonObject, + {String? token, Map? queryParameters, Map? headers, int retryTimes = 0, bool isFormData = false}) async { var _headers = {'Accept': 'application/json'}; if (headers != null && headers.isNotEmpty) { _headers.addAll(headers); @@ -84,12 +77,7 @@ class ApiClient { var bodyJson = json.encode(jsonObject); print("body:$bodyJson"); } - var response = await postJsonForResponse(url, jsonObject, - token: token, - queryParameters: queryParameters, - headers: _headers, - retryTimes: retryTimes, - isFormData: isFormData); + var response = await postJsonForResponse(url, jsonObject, token: token, queryParameters: queryParameters, headers: _headers, retryTimes: retryTimes, isFormData: isFormData); // try { if (!kReleaseMode) { logger.i("res: " + response.body); @@ -102,8 +90,7 @@ class ApiClient { return factoryConstructor(jsonData); } else { APIError? apiError; - apiError = - APIError(jsonData['ErrorCode'], jsonData['ErrorEndUserMessage']); + apiError = APIError(jsonData['ErrorCode'], jsonData['ErrorEndUserMessage']); throw APIException(APIException.BAD_REQUEST, error: apiError); } // } catch (ex) { @@ -116,11 +103,7 @@ class ApiClient { } Future postJsonForResponse(String url, T jsonObject, - {String? token, - Map? queryParameters, - Map? headers, - int retryTimes = 0, - bool isFormData = false}) async { + {String? token, Map? queryParameters, Map? headers, int retryTimes = 0, bool isFormData = false}) async { String? requestBody; late Map stringObj; if (jsonObject != null) { @@ -134,22 +117,13 @@ class ApiClient { if (isFormData) { headers = {'Content-Type': 'application/x-www-form-urlencoded'}; - stringObj = ((jsonObject ?? {}) as Map) - .map((key, value) => MapEntry(key, value?.toString() ?? "")); + stringObj = ((jsonObject ?? {}) as Map).map((key, value) => MapEntry(key, value?.toString() ?? "")); } - return await _postForResponse(url, isFormData ? stringObj : requestBody, - token: token, - queryParameters: queryParameters, - headers: headers, - retryTimes: retryTimes); + return await _postForResponse(url, isFormData ? stringObj : requestBody, token: token, queryParameters: queryParameters, headers: headers, retryTimes: retryTimes); } - Future _postForResponse(String url, requestBody, - {String? token, - Map? queryParameters, - Map? headers, - int retryTimes = 0}) async { + Future _postForResponse(String url, requestBody, {String? token, Map? queryParameters, Map? headers, int retryTimes = 0}) async { try { var _headers = {}; if (token != null) { @@ -164,9 +138,7 @@ class ApiClient { var queryString = new Uri(queryParameters: queryParameters).query; url = url + '?' + queryString; } - var response = - await _post(Uri.parse(url), body: requestBody, headers: _headers) - .timeout(Duration(seconds: 120)); + var response = await _post(Uri.parse(url), body: requestBody, headers: _headers).timeout(Duration(seconds: 120)); if (response.statusCode >= 200 && response.statusCode < 300) { return response; @@ -177,11 +149,7 @@ class ApiClient { if (retryTimes > 0) { print('will retry after 3 seconds...'); await Future.delayed(Duration(seconds: 3)); - return await _postForResponse(url, requestBody, - token: token, - queryParameters: queryParameters, - headers: headers, - retryTimes: retryTimes - 1); + return await _postForResponse(url, requestBody, token: token, queryParameters: queryParameters, headers: headers, retryTimes: retryTimes - 1); } else { throw APIException(APIException.OTHER, arguments: e); } @@ -189,11 +157,7 @@ class ApiClient { if (retryTimes > 0) { print('will retry after 3 seconds...'); await Future.delayed(Duration(seconds: 3)); - return await _postForResponse(url, requestBody, - token: token, - queryParameters: queryParameters, - headers: headers, - retryTimes: retryTimes - 1); + return await _postForResponse(url, requestBody, token: token, queryParameters: queryParameters, headers: headers, retryTimes: retryTimes - 1); } else { throw APIException(APIException.OTHER, arguments: e); } @@ -203,39 +167,23 @@ class ApiClient { if (retryTimes > 0) { print('will retry after 3 seconds...'); await Future.delayed(Duration(seconds: 3)); - return await _postForResponse(url, requestBody, - token: token, - queryParameters: queryParameters, - headers: headers, - retryTimes: retryTimes - 1); + return await _postForResponse(url, requestBody, token: token, queryParameters: queryParameters, headers: headers, retryTimes: retryTimes - 1); } else { throw APIException(APIException.OTHER, arguments: e); } } } - Future getJsonForResponse(String url, - {String? token, - Map? queryParameters, - Map? headers, - int retryTimes = 0}) async { + Future getJsonForResponse(String url, {String? token, Map? queryParameters, Map? headers, int retryTimes = 0}) async { if (headers == null) { headers = {'Content-Type': 'application/json'}; } else { headers['Content-Type'] = 'application/json'; } - return await _getForResponse(url, - token: token, - queryParameters: queryParameters, - headers: headers, - retryTimes: retryTimes); + return await _getForResponse(url, token: token, queryParameters: queryParameters, headers: headers, retryTimes: retryTimes); } - Future _getForResponse(String url, - {String? token, - Map? queryParameters, - Map? headers, - int retryTimes = 0}) async { + Future _getForResponse(String url, {String? token, Map? queryParameters, Map? headers, int retryTimes = 0}) async { try { var _headers = {}; if (token != null) { @@ -250,8 +198,7 @@ class ApiClient { var queryString = new Uri(queryParameters: queryParameters).query; url = url + '?' + queryString; } - var response = await _get(Uri.parse(url), headers: _headers) - .timeout(Duration(seconds: 60)); + var response = await _get(Uri.parse(url), headers: _headers).timeout(Duration(seconds: 60)); if (response.statusCode >= 200 && response.statusCode < 300) { return response; @@ -262,11 +209,7 @@ class ApiClient { if (retryTimes > 0) { print('will retry after 3 seconds...'); await Future.delayed(Duration(seconds: 3)); - return await _getForResponse(url, - token: token, - queryParameters: queryParameters, - headers: headers, - retryTimes: retryTimes - 1); + return await _getForResponse(url, token: token, queryParameters: queryParameters, headers: headers, retryTimes: retryTimes - 1); } else { throw APIException(APIException.OTHER, arguments: e); } @@ -274,11 +217,7 @@ class ApiClient { if (retryTimes > 0) { print('will retry after 3 seconds...'); await Future.delayed(Duration(seconds: 3)); - return await _getForResponse(url, - token: token, - queryParameters: queryParameters, - headers: headers, - retryTimes: retryTimes - 1); + return await _getForResponse(url, token: token, queryParameters: queryParameters, headers: headers, retryTimes: retryTimes - 1); } else { throw APIException(APIException.OTHER, arguments: e); } @@ -288,19 +227,14 @@ class ApiClient { if (retryTimes > 0) { print('will retry after 3 seconds...'); await Future.delayed(Duration(seconds: 3)); - return await _getForResponse(url, - token: token, - queryParameters: queryParameters, - headers: headers, - retryTimes: retryTimes - 1); + return await _getForResponse(url, token: token, queryParameters: queryParameters, headers: headers, retryTimes: retryTimes - 1); } else { throw APIException(APIException.OTHER, arguments: e); } } } - Future _get(url, {Map? headers}) => - _withClient((client) => client.get(url, headers: headers)); + Future _get(url, {Map? headers}) => _withClient((client) => client.get(url, headers: headers)); bool _certificateCheck(X509Certificate cert, String host, int port) => true; @@ -314,8 +248,5 @@ class ApiClient { } } - Future _post(url, - {Map? headers, body, Encoding? encoding}) => - _withClient((client) => - client.post(url, headers: headers, body: body, encoding: encoding)); + Future _post(url, {Map? headers, body, Encoding? encoding}) => _withClient((client) => client.post(url, headers: headers, body: body, encoding: encoding)); } diff --git a/lib/api/chat/chat_api_client.dart b/lib/api/chat/chat_api_client.dart index 0d1653d..bea5b7c 100644 --- a/lib/api/chat/chat_api_client.dart +++ b/lib/api/chat/chat_api_client.dart @@ -1,10 +1,15 @@ import 'dart:convert'; import 'dart:io'; +import 'dart:typed_data'; import 'package:http/http.dart'; import 'package:mohem_flutter_app/api/api_client.dart'; import 'package:mohem_flutter_app/app_state/app_state.dart'; import 'package:mohem_flutter_app/classes/consts.dart'; +import 'package:mohem_flutter_app/classes/utils.dart'; +import 'package:mohem_flutter_app/exceptions/api_exception.dart'; +import 'package:mohem_flutter_app/main.dart'; +import 'package:mohem_flutter_app/models/chat/chat_user_image_model.dart'; import 'package:mohem_flutter_app/models/chat/get_search_user_chat_model.dart'; import 'package:mohem_flutter_app/models/chat/get_user_login_token_model.dart' as user; import 'package:mohem_flutter_app/models/chat/make_user_favotire_unfavorite_chat_model.dart' as fav; @@ -18,43 +23,55 @@ class ChatApiClient { Future getUserLoginToken() async { Response response = await ApiClient().postJsonForResponse( - "${ApiConsts.chatServerBaseApiUrl}user/externaluserlogin", + "${ApiConsts.chatLoginTokenUrl}externaluserlogin", { "employeeNumber": AppState().memberInformationList!.eMPLOYEENUMBER.toString(), "password": "FxIu26rWIKoF8n6mpbOmAjDLphzFGmpG", }, ); - user.UserAutoLoginModel userLoginResponse = user.userAutoLoginModelFromJson( - response.body, - ); + user.UserAutoLoginModel userLoginResponse = user.userAutoLoginModelFromJson(response.body); return userLoginResponse; } Future?> getChatMemberFromSearch(String sName, int cUserId) async { Response response = await ApiClient().getJsonForResponse( - "${ApiConsts.chatServerBaseApiUrl}${ApiConsts.chatSearchMember}$sName/$cUserId", + "${ApiConsts.chatLoginTokenUrl}getUserWithStatusAndFavAsync/$sName/$cUserId", token: AppState().chatDetails!.response!.token, ); return searchUserJsonModel(response.body); } - List searchUserJsonModel(String str) => List.from( - json.decode(str).map((x) => ChatUser.fromJson(x)), - ); + List searchUserJsonModel(String str) => List.from(json.decode(str).map((x) => ChatUser.fromJson(x))); Future getRecentChats() async { - Response response = await ApiClient().getJsonForResponse( - "${ApiConsts.chatServerBaseApiUrl}${ApiConsts.chatRecentUrl}", - token: AppState().chatDetails!.response!.token, - ); - return ChatUserModel.fromJson( - json.decode(response.body), - ); + try { + Response response = await ApiClient().getJsonForResponse( + "${ApiConsts.chatRecentUrl}getchathistorybyuserid", + token: AppState().chatDetails!.response!.token, + ); + return ChatUserModel.fromJson( + json.decode(response.body), + ); + } catch (e) { + e as APIException; + if (e.message == "api_common_unauthorized") { + user.UserAutoLoginModel userLoginResponse = await ChatApiClient().getUserLoginToken(); + if (userLoginResponse.response != null) { + AppState().setchatUserDetails = userLoginResponse; + getRecentChats(); + } else { + Utils.showToast( + userLoginResponse.errorResponses!.first.fieldName.toString() + " Erorr", + ); + } + } + throw e; + } } Future getFavUsers() async { Response favRes = await ApiClient().getJsonForResponse( - "${ApiConsts.chatServerBaseApiUrl}${ApiConsts.chatFavoriteUsers}${AppState().chatDetails!.response!.id}", + "${ApiConsts.chatFavUser}getFavUserById/${AppState().chatDetails!.response!.id}", token: AppState().chatDetails!.response!.token, ); return ChatUserModel.fromJson( @@ -63,41 +80,85 @@ class ChatApiClient { } Future getSingleUserChatHistory({required int senderUID, required int receiverUID, required bool loadMore, bool isNewChat = false, required int paginationVal}) async { - Response response = await ApiClient().getJsonForResponse( - "${ApiConsts.chatServerBaseApiUrl}${ApiConsts.chatSingleUserHistoryUrl}/$senderUID/$receiverUID/$paginationVal", - token: AppState().chatDetails!.response!.token, - ); - return response; + try { + Response response = await ApiClient().getJsonForResponse( + "${ApiConsts.chatSingleUserHistoryUrl}GetUserChatHistory/$senderUID/$receiverUID/$paginationVal", + token: AppState().chatDetails!.response!.token, + ); + return response; + } catch (e) { + e as APIException; + if (e.message == "api_common_unauthorized") { + user.UserAutoLoginModel userLoginResponse = await ChatApiClient().getUserLoginToken(); + if (userLoginResponse.response != null) { + AppState().setchatUserDetails = userLoginResponse; + getSingleUserChatHistory(senderUID: senderUID, receiverUID: receiverUID, loadMore: loadMore, paginationVal: paginationVal); + } else { + Utils.showToast(userLoginResponse.errorResponses!.first.fieldName.toString() + " Erorr"); + } + } + throw e; + } } Future favUser({required int userID, required int targetUserID}) async { - Response response = await ApiClient().postJsonForResponse( - "${ApiConsts.chatServerBaseApiUrl}FavUser/addFavUser", - { - "targetUserId": targetUserID, - "userId": userID, - }, - token: AppState().chatDetails!.response!.token); + Response response = await ApiClient().postJsonForResponse("${ApiConsts.chatFavUser}addFavUser", {"targetUserId": targetUserID, "userId": userID}, token: AppState().chatDetails!.response!.token); fav.FavoriteChatUser favoriteChatUser = fav.FavoriteChatUser.fromRawJson(response.body); return favoriteChatUser; } Future unFavUser({required int userID, required int targetUserID}) async { - Response response = await ApiClient().postJsonForResponse( - "${ApiConsts.chatServerBaseApiUrl}FavUser/deleteFavUser", - {"targetUserId": targetUserID, "userId": userID}, - token: AppState().chatDetails!.response!.token, - ); - fav.FavoriteChatUser favoriteChatUser = fav.FavoriteChatUser.fromRawJson(response.body); - return favoriteChatUser; + try { + Response response = await ApiClient().postJsonForResponse( + "${ApiConsts.chatFavUser}deleteFavUser", + {"targetUserId": targetUserID, "userId": userID}, + token: AppState().chatDetails!.response!.token, + ); + fav.FavoriteChatUser favoriteChatUser = fav.FavoriteChatUser.fromRawJson(response.body); + return favoriteChatUser; + } catch (e) { + e as APIException; + if (e.message == "api_common_unauthorized") { + logger.d("Token Generated On APIIIIII"); + user.UserAutoLoginModel userLoginResponse = await ChatApiClient().getUserLoginToken(); + if (userLoginResponse.response != null) { + AppState().setchatUserDetails = userLoginResponse; + unFavUser(userID: userID, targetUserID: targetUserID); + } else { + Utils.showToast(userLoginResponse.errorResponses!.first.fieldName.toString() + " Erorr"); + } + } + throw e; + } } Future uploadMedia(String userId, File file) async { - dynamic request = MultipartRequest('POST', Uri.parse('${ApiConsts.chatServerBaseApiUrl}${ApiConsts.chatMediaImageUploadUrl}')); + dynamic request = MultipartRequest('POST', Uri.parse('${ApiConsts.chatMediaImageUploadUrl}upload')); request.fields.addAll({'userId': userId, 'fileSource': '1'}); request.files.add(await MultipartFile.fromPath('files', file.path)); request.headers.addAll({'Authorization': 'Bearer ${AppState().chatDetails!.response!.token}'}); StreamedResponse response = await request.send(); return response; } + + // Download File For Chat + + Future downloadURL({required String fileName, required String fileTypeDescription}) async { + Response response = await ApiClient().postJsonForResponse( + "${ApiConsts.chatMediaImageUploadUrl}download", + {"fileType": fileTypeDescription, "fileName": fileName, "fileSource": 1}, + token: AppState().chatDetails!.response!.token, + ); + Uint8List data = Uint8List.fromList(response.bodyBytes); + return data; + } + + Future> getUsersImages({required List encryptedEmails}) async { + Response response = await ApiClient().postJsonForResponse( + "${ApiConsts.chatUserImages}images", + {"encryptedEmails": encryptedEmails, "fromClient": false}, + token: AppState().chatDetails!.response!.token, + ); + return chatUserImageModelFromJson(response.body); + } } diff --git a/lib/api/dashboard_api_client.dart b/lib/api/dashboard_api_client.dart index 69c2e82..e30af91 100644 --- a/lib/api/dashboard_api_client.dart +++ b/lib/api/dashboard_api_client.dart @@ -182,22 +182,22 @@ class DashboardApiClient { Future getChatCount() async { Response response = await ApiClient().getJsonForResponse( - "${ApiConsts.chatServerBaseApiUrl}user/unreadconversationcount/${AppState().getUserName}", + "${ApiConsts.chatLoginTokenUrl}unreadconversationcount/${AppState().getUserName}", ); return chatUnreadCovnCountModelFromJson(response.body); } - // Future setAdvertisementViewed(String masterID, int advertisementId) async { - // String url = "${ApiConsts.cocRest}Mohemm_ITG_UpdateAdvertisementAsViewed"; - // - // Map postParams = { - // "ItgNotificationMasterId": masterID, - // "ItgAdvertisement": {"advertisementId": advertisementId, "acknowledgment": true} //Mobile Id - // }; - // postParams.addAll(AppState().postParamsJson); - // return await ApiClient().postJsonForObject((json) { - // // ItgMainRes responseData = ItgMainRes.fromJson(json); - // return json; - // }, url, postParams); - // } +// Future setAdvertisementViewed(String masterID, int advertisementId) async { +// String url = "${ApiConsts.cocRest}Mohemm_ITG_UpdateAdvertisementAsViewed"; +// +// Map postParams = { +// "ItgNotificationMasterId": masterID, +// "ItgAdvertisement": {"advertisementId": advertisementId, "acknowledgment": true} //Mobile Id +// }; +// postParams.addAll(AppState().postParamsJson); +// return await ApiClient().postJsonForObject((json) { +// // ItgMainRes responseData = ItgMainRes.fromJson(json); +// return json; +// }, url, postParams); +// } } diff --git a/lib/api/items_for_sale/items_for_sale_api_client.dart b/lib/api/items_for_sale/items_for_sale_api_client.dart index 436ae6e..eae6ffb 100644 --- a/lib/api/items_for_sale/items_for_sale_api_client.dart +++ b/lib/api/items_for_sale/items_for_sale_api_client.dart @@ -66,6 +66,41 @@ class ItemsForSaleApiClient { }, url, postParams); } + Future updateItemsForSale(int itemSaleID) async { + List getItemsForSaleList = []; + + String url = "${ApiConsts.cocRest}Mohemm_ITG_UpdateItemForSale"; + + // request.fields['itemSaleID'] = itemSaleID.toString(); + // request.fields['Channel'] = "31"; + // request.fields['isActive'] = "false"; + // request.fields['LogInToken'] = loginTokenID!; + // request.fields['Token'] = tokenID!; + // request.fields['MobileNo'] = empMobNum!; + // request.fields['EmployeeNumber'] = empNum!; + // request.fields['employeeNumber'] = empNum; + + Map postParams = { + "EmployeeNumber": AppState().memberInformationList?.eMPLOYEENUMBER, + "employeeNumber": AppState().memberInformationList?.eMPLOYEENUMBER, + "MobileNo": AppState().memberInformationList?.eMPLOYEEMOBILENUMBER, + "itemSaleID": itemSaleID.toString(), + "Channel": "31", + "isActive": "false", + "Token": AppState().postParamsObject?.tokenID + }; + + postParams.addAll(AppState().postParamsJson); + return await ApiClient().postJsonForObject((response) { + var body = json.decode(response['Mohemm_ITG_ResponseItem']); + + // body['result']['data'].forEach((v) { + // getItemsForSaleList.add(new GetItemsForSaleList.fromJson(v)); + // }); + return getItemsForSaleList; + }, url, postParams); + } + Future> getEmployeePostedAds() async { List employeePostedAdsList = []; diff --git a/lib/api/marathon/marathon_api_client.dart b/lib/api/marathon/marathon_api_client.dart new file mode 100644 index 0000000..1ec117d --- /dev/null +++ b/lib/api/marathon/marathon_api_client.dart @@ -0,0 +1,178 @@ +import 'dart:convert'; + +import 'package:flutter/material.dart'; +import 'package:http/http.dart'; +import 'package:logger/logger.dart' as L; +import 'package:logging/logging.dart'; +import 'package:mohem_flutter_app/api/api_client.dart'; +import 'package:mohem_flutter_app/app_state/app_state.dart'; +import 'package:mohem_flutter_app/classes/consts.dart'; +import 'package:mohem_flutter_app/models/marathon/marathon_generic_model.dart'; +import 'package:mohem_flutter_app/models/marathon/marathon_model.dart'; +import 'package:mohem_flutter_app/models/marathon/question_model.dart'; +import 'package:mohem_flutter_app/ui/marathon/marathon_provider.dart'; +import 'package:provider/provider.dart'; +import 'package:signalr_netcore/http_connection_options.dart'; +import 'package:signalr_netcore/hub_connection.dart'; +import 'package:signalr_netcore/hub_connection_builder.dart'; + +class MarathonApiClient { + Future getMarathonToken() async { + String employeeUserName = AppState().getUserName ?? ""; + String employeeSession = AppState().postParamsObject?.pSessionId.toString() ?? ""; + + Map jsonObject = {"userName": employeeUserName, "password": employeeSession}; + Response response = await ApiClient().postJsonForResponse(ApiConsts.marathonParticipantLoginUrl, jsonObject); + + var json = jsonDecode(response.body); + + MarathonGenericModel marathonModel = MarathonGenericModel.fromJson(json); + + if (marathonModel.statusCode == 200) { + if (marathonModel.data != null && marathonModel.isSuccessful == true) { + AppState().setMarathonToken = marathonModel.data["token"] ?? ""; + print("bearer: ${AppState().getMarathonToken}"); + return marathonModel.data["token"] ?? ""; + } else { + //TODO : DO ERROR HANDLING HERE + return ""; + } + } else { + //TODO : DO ERROR HANDLING HERE + return ""; + } + } + + Future getProjectId() async { + Response response = await ApiClient().postJsonForResponse(ApiConsts.marathonProjectGetUrl, {}, token: AppState().getMarathonToken ?? await getMarathonToken()); + + var json = jsonDecode(response.body); + MarathonGenericModel marathonModel = MarathonGenericModel.fromJson(json); + + if (marathonModel.statusCode == 200) { + if (marathonModel.data != null && marathonModel.isSuccessful == true) { + logger.i("message: ${marathonModel.data[0]["id"]}"); + AppState().setMarathonProjectId = marathonModel.data[0]["id"] ?? ""; + return marathonModel.data[0]["id"] ?? ""; + } else { + //TODO : DO ERROR HANDLING HERE + return ""; + } + } else { + //TODO : DO ERROR HANDLING HERE + return ""; + } + } + + Future getMarathonDetails() async { + String payrollString = AppState().postParamsObject?.payrollCodeStr.toString() ?? "CS"; + + Response response = await ApiClient().getJsonForResponse(ApiConsts.marathonUpcomingUrl + payrollString, token: AppState().getMarathonToken ?? await getMarathonToken()); + + var json = jsonDecode(response.body); + + MarathonGenericModel marathonGenericModel = MarathonGenericModel.fromJson(json); + + MarathonDetailModel marathonDetailModel = MarathonDetailModel.fromJson(marathonGenericModel.data); + + AppState().setMarathonProjectId = marathonDetailModel.id!; + + return marathonDetailModel; + } + + late HubConnection hubConnection; + L.Logger logger = L.Logger(); + + Future buildHubConnection(BuildContext context) async { + HttpConnectionOptions httpOptions = HttpConnectionOptions(skipNegotiation: false, logMessageContent: true); + hubConnection = HubConnectionBuilder() + .withUrl( + ApiConsts.marathonHubConnectionUrl + "?employeeNumber=${AppState().memberInformationList!.eMPLOYEENUMBER ?? ""}&employeeName=${AppState().memberInformationList!.eMPLOYEENAME ?? ""}", + options: httpOptions, + ) + .withAutomaticReconnect( + retryDelays: [2000, 5000, 10000, 20000], + ) + .configureLogging( + Logger("Logging"), + ) + .build(); + hubConnection.onclose( + ({Exception? error}) { + logger.i("onclose"); + }, + ); + hubConnection.onreconnecting( + ({Exception? error}) { + logger.i("onreconnecting"); + }, + ); + hubConnection.onreconnected( + ({String? connectionId}) { + logger.i("onreconnected"); + }, + ); + if (hubConnection.state != HubConnectionState.Connected) { + await hubConnection.start(); + logger.i("Started HubConnection"); + + await hubConnection.invoke( + "AddParticipant", + args: [ + { + "employeeNumber": AppState().memberInformationList!.eMPLOYEENUMBER ?? "", + "employeeName": AppState().memberInformationList!.eMPLOYEENAME ?? "", + "marathonId": AppState().getMarathonProjectId, + } + ], + ).catchError((e) { + logger.i("Error in AddParticipant: $e"); + }); + + context.read().addItemToList(ApiConsts.dummyQuestion); + + await hubConnection.invoke( + "SendQuestionToParticipant", + args: [ + { + "marathonId": "${AppState().getMarathonProjectId}", + } + ], + ).catchError((e) { + logger.i("Error in SendQuestionToParticipant: $e"); + }); + + try { + hubConnection.on("OnSendQuestionToParticipant", (List? arguments) { + onSendQuestionToParticipant(arguments, context); + }); + } catch (e, s) { + logger.i("Error in OnSendQuestionToParticipant"); + } + + try { + hubConnection.on("OnParticipantJoin", (List? arguments) { + onParticipantJoin(arguments, context); + }); + } catch (e, s) { + logger.i("Error in OnParticipantJoin"); + } + } + } + + Future onSendQuestionToParticipant(List? arguments, BuildContext context) async { + logger.i("onSendQuestionToParticipant arguments: $arguments"); + + if (arguments != null) { + Map data = arguments.first! as Map; + var json = data["data"]; + QuestionModel newQuestion = QuestionModel.fromJson(json); + context.read().onNewQuestionReceived(newQuestion); + } + } + + Future onParticipantJoin(List? arguments, BuildContext context) async { + logger.i("OnParticipantJoin arguments: $arguments"); + context.watch().totalMarathoners++; + } +} diff --git a/lib/app_state/app_state.dart b/lib/app_state/app_state.dart index 49f4186..b0620ad 100644 --- a/lib/app_state/app_state.dart +++ b/lib/app_state/app_state.dart @@ -51,6 +51,18 @@ class AppState { String? get getMohemmWifiPassword => _mohemmWifiPassword; + String? _marathonToken ; + + set setMarathonToken(String token) => _marathonToken = token; + + String? get getMarathonToken => _marathonToken; + + String? _projectID ; + + set setMarathonProjectId(String token) => _projectID = token; + + String? get getMarathonProjectId => _projectID; + final PostParamsModel _postParamsInitConfig = PostParamsModel(channel: 31, versionID: 5.0, mobileType: Platform.isAndroid ? "android" : "ios"); void setPostParamsInitConfig() { diff --git a/lib/classes/colors.dart b/lib/classes/colors.dart index 10681be..4394279 100644 --- a/lib/classes/colors.dart +++ b/lib/classes/colors.dart @@ -62,4 +62,5 @@ class MyColors { static const Color grey9DColor = Color(0xff9D9D9D); static const Color darkDigitColor = Color(0xff2D2F39); static const Color grey71Color = Color(0xff717171); + static const Color darkGrey3BColor = Color(0xff3B3B3B); } diff --git a/lib/classes/consts.dart b/lib/classes/consts.dart index 4d6eca8..944a29b 100644 --- a/lib/classes/consts.dart +++ b/lib/classes/consts.dart @@ -1,7 +1,9 @@ +import 'package:mohem_flutter_app/ui/marathon/widgets/question_card.dart'; + class ApiConsts { //static String baseUrl = "http://10.200.204.20:2801/"; // Local server // static String baseUrl = "https://uat.hmgwebservices.com"; // UAT server - static String baseUrl = "https://hmgwebservices.com"; // Live server + static String baseUrl = "https://hmgwebservices.com"; // Live server static String baseUrlServices = baseUrl + "/Services/"; // server // static String baseUrlServices = "https://api.cssynapses.com/tangheem/"; // Live server static String utilitiesRest = baseUrlServices + "Utilities.svc/REST/"; @@ -10,17 +12,30 @@ class ApiConsts { static String user = baseUrlServices + "api/User/"; static String cocRest = baseUrlServices + "COCWS.svc/REST/"; - // todo @aamir move api end point last repo to concerned method. - //Chat static String chatServerBaseUrl = "https://apiderichat.hmg.com/"; static String chatServerBaseApiUrl = chatServerBaseUrl + "api/"; + static String chatLoginTokenUrl = chatServerBaseApiUrl + "user/"; static String chatHubConnectionUrl = chatServerBaseUrl + "ConnectionChatHub"; - static String chatSearchMember = "user/getUserWithStatusAndFavAsync/"; - static String chatRecentUrl = "UserChatHistory/getchathistorybyuserid"; //For a Mem - static String chatSingleUserHistoryUrl = "UserChatHistory/GetUserChatHistory"; - static String chatMediaImageUploadUrl = "shared/upload"; - static String chatFavoriteUsers = "FavUser/getFavUserById/"; + + // static String chatSearchMember = chatLoginTokenUrl + "user/"; + static String chatRecentUrl = chatServerBaseApiUrl + "UserChatHistory/"; //For a Mem + static String chatSingleUserHistoryUrl = chatServerBaseApiUrl + "UserChatHistory/"; + static String chatMediaImageUploadUrl = chatServerBaseApiUrl + "shared/"; + static String chatFavUser = chatServerBaseApiUrl + "FavUser/"; + static String chatUserImages = chatServerBaseUrl + "empservice/api/employee/"; + + //Brain Marathon Constants + static String marathonBaseUrl = "https://marathoon.com/service/"; + static String marathonParticipantLoginUrl = marathonBaseUrl + "api/auth/participantlogin"; + static String marathonProjectGetUrl = marathonBaseUrl + "api/Project/Project_Get"; + static String marathonUpcomingUrl = marathonBaseUrl + "api/marathon/upcoming/"; + static String marathonHubConnectionUrl = marathonBaseUrl + "MarathonBroadCast"; + + //DummyCards for the UI + + static CardContent dummyQuestion = const CardContent(); + } class SharedPrefsConsts { diff --git a/lib/classes/date_uitl.dart b/lib/classes/date_uitl.dart index f7b8192..a1e52d9 100644 --- a/lib/classes/date_uitl.dart +++ b/lib/classes/date_uitl.dart @@ -3,6 +3,26 @@ import 'package:intl/intl.dart'; class DateUtil { /// convert String To Date function /// [date] String we want to convert + /// + /// + + + static DateTime convertStringToDateMarathon(String date) { + // /Date(1585774800000+0300)/ + if (date != null) { + const start = "/Date("; + const end = "+0300)"; + int startIndex = date.indexOf(start); + int endIndex = date.indexOf(end, startIndex + start.length); + return DateTime.fromMillisecondsSinceEpoch( + int.parse( + date.substring(startIndex + start.length, endIndex), + ), + ); + } else + return DateTime.now(); + } + static DateTime convertStringToDate(String date) { // /Date(1585774800000+0300)/ if (date != null) { @@ -55,8 +75,9 @@ class DateUtil { } return DateTime.now(); - } else + } else { return DateTime.now(); + } } static String convertDateToString(DateTime date) { @@ -94,7 +115,7 @@ class DateUtil { } static String convertDateMSToJsonDate(utc) { - var dt = new DateTime.fromMicrosecondsSinceEpoch(utc); + var dt = DateTime.fromMicrosecondsSinceEpoch(utc); return "/Date(" + (dt.millisecondsSinceEpoch * 1000).toString() + '+0300' + ")/"; } @@ -416,7 +437,7 @@ class DateUtil { /// get data formatted like 10:30 according to lang static String formatDateToTimeLang(DateTime date, bool isArabic) { - return DateFormat('HH:mm', isArabic ? "ar_SA" : "en_US").format(date); + return DateFormat('HH:mm a', isArabic ? "ar_SA" : "en_US").format(date); } /// get data formatted like 26/4/2020 10:30 diff --git a/lib/classes/decorations_helper.dart b/lib/classes/decorations_helper.dart index 77ea4a4..b313673 100644 --- a/lib/classes/decorations_helper.dart +++ b/lib/classes/decorations_helper.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:mohem_flutter_app/classes/colors.dart'; +import 'package:mohem_flutter_app/models/marathon/question_model.dart'; class MyDecorations { static Decoration shadowDecoration = BoxDecoration( @@ -22,4 +23,18 @@ class MyDecorations { ); return answerContainerDecoration; } + + static Decoration getAnswersContainerColor(QuestionsOptionStatus questionsOptionStatus) { + switch (questionsOptionStatus) { + case QuestionsOptionStatus.correct: + return getContainersDecoration(MyColors.greenColor); + case QuestionsOptionStatus.wrong: + return getContainersDecoration(MyColors.redColor); + + case QuestionsOptionStatus.selected: + return getContainersDecoration(MyColors.yellowColorII); + case QuestionsOptionStatus.unSelected: + return getContainersDecoration(MyColors.greyF7Color); + } + } } diff --git a/lib/classes/encryption.dart b/lib/classes/encryption.dart new file mode 100644 index 0000000..a4ab6be --- /dev/null +++ b/lib/classes/encryption.dart @@ -0,0 +1,26 @@ +import 'dart:convert'; + +import 'package:flutter/services.dart'; + +class EmailImageEncryption { + static final EmailImageEncryption _instance = EmailImageEncryption._internal(); + static const MethodChannel _channel = MethodChannel('flutter_des'); + static const key = "PeShVmYp"; + static const iv = "j70IbWYn"; + + EmailImageEncryption._internal(); + + factory EmailImageEncryption() => _instance; + + Future encrypt({required String val}) async { + Uint8List? crypt = await _channel.invokeMethod('encrypt', [val, key, iv]); + String enc = base64Encode(crypt!.toList()); + return enc; + } + + Future decrypt({required String encodedVal}) async { + Uint8List deco = base64Decode(encodedVal); + String? decCrypt = await _channel.invokeMethod('decrypt', [deco, key, iv]); + return decCrypt!; + } +} diff --git a/lib/classes/lottie_consts.dart b/lib/classes/lottie_consts.dart index 1b714a4..24dc423 100644 --- a/lib/classes/lottie_consts.dart +++ b/lib/classes/lottie_consts.dart @@ -4,4 +4,6 @@ class MyLottieConsts { static const String celebrate2Lottie = "assets/lottie/celebrate2.json"; static const String winnerLottie = "assets/lottie/winner3.json"; static const String allQuestions = "assets/lottie/all_questions.json"; + static const String wrongAnswerGif = "assets/images/wrong_answer.gif"; + } diff --git a/lib/config/routes.dart b/lib/config/routes.dart index ab3fb9a..7cf8a35 100644 --- a/lib/config/routes.dart +++ b/lib/config/routes.dart @@ -7,6 +7,7 @@ import 'package:mohem_flutter_app/ui/chat/chat_detailed_screen.dart'; import 'package:mohem_flutter_app/ui/chat/chat_home.dart'; import 'package:mohem_flutter_app/ui/chat/favorite_users_screen.dart'; import 'package:mohem_flutter_app/ui/landing/dashboard_screen.dart'; +import 'package:mohem_flutter_app/ui/landing/itg/its_add_screen_video_image.dart'; import 'package:mohem_flutter_app/ui/landing/itg/survey_screen.dart'; import 'package:mohem_flutter_app/ui/landing/today_attendance_screen.dart'; import 'package:mohem_flutter_app/ui/landing/today_attendance_screen2.dart'; @@ -87,6 +88,7 @@ class AppRoutes { static const String addEitScreen = "/addeitScreen"; static const String initialRoute = login; static const String survey = "/survey"; + static const String advertisement = "/advertisement"; //Work List static const String workList = "/workList"; @@ -116,8 +118,7 @@ class AppRoutes { static const String addVacationRule = "/addVacationRule"; //Bottom Sheet - static const String attendanceDetailsBottomSheet = - "/attendanceDetailsBottomSheet"; + static const String attendanceDetailsBottomSheet = "/attendanceDetailsBottomSheet"; //Profile static const String profile = "/profile"; @@ -135,8 +136,7 @@ class AppRoutes { // Pending Transactions static const String pendingTransactions = "/pendingTransactions"; - static const String pendingTransactionsDetails = - "/pendingTransactionsDetails"; + static const String pendingTransactionsDetails = "/pendingTransactionsDetails"; // Announcements static const String announcements = "/announcements"; @@ -192,6 +192,7 @@ class AppRoutes { verifyLastLogin: (BuildContext context) => VerifyLastLoginScreen(), dashboard: (BuildContext context) => DashboardScreen(), survey: (BuildContext context) => SurveyScreen(), + advertisement: (BuildContext context) => ITGAdsScreen(), subMenuScreen: (BuildContext context) => SubMenuScreen(), newPassword: (BuildContext context) => NewPasswordScreen(), @@ -223,8 +224,7 @@ class AppRoutes { addVacationRule: (BuildContext context) => AddVacationRuleScreen(), //Bottom Sheet - attendanceDetailsBottomSheet: (BuildContext context) => - AttendenceDetailsBottomSheet(), + attendanceDetailsBottomSheet: (BuildContext context) => AttendenceDetailsBottomSheet(), //Profile //profile: (BuildContext context) => Profile(), @@ -235,13 +235,10 @@ class AppRoutes { familyMembers: (BuildContext context) => FamilyMembers(), dynamicScreen: (BuildContext context) => DynamicListViewScreen(), addDynamicInput: (BuildContext context) => DynamicInputScreen(), - addDynamicInputProfile: (BuildContext context) => - DynamicInputScreenProfile(), - addDynamicAddressScreen: (BuildContext context) => - DynamicInputScreenAddress(), + addDynamicInputProfile: (BuildContext context) => DynamicInputScreenProfile(), + addDynamicAddressScreen: (BuildContext context) => DynamicInputScreenAddress(), - deleteFamilyMember: (BuildContext context) => - DeleteFamilyMember(ModalRoute.of(context)!.settings.arguments as int), + deleteFamilyMember: (BuildContext context) => DeleteFamilyMember(ModalRoute.of(context)!.settings.arguments as int), requestSubmitScreen: (BuildContext context) => RequestSubmitScreen(), addUpdateFamilyMember: (BuildContext context) => AddUpdateFamilyMember(), @@ -251,8 +248,7 @@ class AppRoutes { mowadhafhiHRRequest: (BuildContext context) => MowadhafhiHRRequest(), pendingTransactions: (BuildContext context) => PendingTransactions(), - pendingTransactionsDetails: (BuildContext context) => - PendingTransactionsDetails(), + pendingTransactionsDetails: (BuildContext context) => PendingTransactionsDetails(), announcements: (BuildContext context) => Announcements(), announcementsDetails: (BuildContext context) => AnnouncementDetails(), @@ -268,8 +264,7 @@ class AppRoutes { // Offers & Discounts offersAndDiscounts: (BuildContext context) => OffersAndDiscountsHome(), - offersAndDiscountsDetails: (BuildContext context) => - OffersAndDiscountsDetails(), + offersAndDiscountsDetails: (BuildContext context) => OffersAndDiscountsDetails(), //pay slip monthlyPaySlip: (BuildContext context) => MonthlyPaySlipScreen(), @@ -296,8 +291,7 @@ class AppRoutes { // Marathon marathonIntroScreen: (BuildContext context) => MarathonIntroScreen(), marathonScreen: (BuildContext context) => MarathonScreen(), - marathonWinnerSelection: (BuildContext context) => - MarathonWinnerSelection(), + marathonWinnerSelection: (BuildContext context) => MarathonWinnerSelection(), marathonWinnerScreen: (BuildContext context) => WinnerScreen(), }; } diff --git a/lib/extensions/string_extensions.dart b/lib/extensions/string_extensions.dart index 8bc15e7..3546f6b 100644 --- a/lib/extensions/string_extensions.dart +++ b/lib/extensions/string_extensions.dart @@ -136,7 +136,7 @@ extension EmailValidator on String { Widget toText21({Color? color, bool isBold = false, FontWeight? weight, int? maxlines}) => Text( this, maxLines: maxlines, - style: TextStyle(color: color ?? MyColors.grey3AColor, fontSize: 21, letterSpacing: -0.31, fontWeight: weight ?? (isBold ? FontWeight.bold : FontWeight.w600)), + style: TextStyle(color: color ?? MyColors.grey3AColor, fontSize: 21, letterSpacing: -0.84, fontWeight: weight ?? (isBold ? FontWeight.bold : FontWeight.w600)), ); Widget toText22({Color? color, bool isBold = false}) => Text( @@ -149,6 +149,11 @@ extension EmailValidator on String { style: TextStyle(height: 23 / 24, color: color ?? MyColors.darkTextColor, fontSize: 24, letterSpacing: -1.44, fontWeight: isBold ? FontWeight.bold : FontWeight.w600), ); + Widget toText30({Color? color, bool isBold = false}) => Text( + this, + style: TextStyle(height: 20 / 32, color: color ?? MyColors.darkTextColor, fontSize: 32, letterSpacing: -1.2, fontWeight: isBold ? FontWeight.bold : FontWeight.w600), + ); + Widget toText32({Color? color, bool isBold = false}) => Text( this, style: TextStyle(height: 32 / 32, color: color ?? MyColors.darkTextColor, fontSize: 32, letterSpacing: -1.92, fontWeight: isBold ? FontWeight.bold : FontWeight.w600), diff --git a/lib/generated/locale_keys.g.dart b/lib/generated/locale_keys.g.dart index f5d4960..2f7efcc 100644 --- a/lib/generated/locale_keys.g.dart +++ b/lib/generated/locale_keys.g.dart @@ -487,5 +487,8 @@ abstract class LocaleKeys { static const typeheretoreply = 'typeheretoreply'; static const favorite = 'favorite'; static const searchfromchat = 'searchfromchat'; + static const yourAnswerCorrect = 'yourAnswerCorrect'; + static const youMissedTheQuestion = 'youMissedTheQuestion'; + static const wrongAnswer = 'wrongAnswer'; } diff --git a/lib/models/chat/chat_user_image_model.dart b/lib/models/chat/chat_user_image_model.dart new file mode 100644 index 0000000..cdee33d --- /dev/null +++ b/lib/models/chat/chat_user_image_model.dart @@ -0,0 +1,33 @@ +// To parse this JSON data, do +// +// final chatUserImageModel = chatUserImageModelFromJson(jsonString); + +import 'dart:convert'; + +List chatUserImageModelFromJson(String str) => List.from(json.decode(str).map((x) => ChatUserImageModel.fromJson(x))); + +String chatUserImageModelToJson(List data) => json.encode(List.from(data.map((x) => x.toJson()))); + +class ChatUserImageModel { + ChatUserImageModel({ + this.email, + this.profilePicture, + this.mobileNumber, + }); + + String? email; + String? profilePicture; + String? mobileNumber; + + factory ChatUserImageModel.fromJson(Map json) => ChatUserImageModel( + email: json["email"] == null ? null : json["email"], + profilePicture: json["profilePicture"] == null ? null : json["profilePicture"], + mobileNumber: json["mobileNumber"] == null ? null : json["mobileNumber"], + ); + + Map toJson() => { + "email": email == null ? null : email, + "profilePicture": profilePicture == null ? null : profilePicture, + "mobileNumber": mobileNumber == null ? null : mobileNumber, + }; +} diff --git a/lib/models/chat/get_search_user_chat_model.dart b/lib/models/chat/get_search_user_chat_model.dart index 31d1085..fe87061 100644 --- a/lib/models/chat/get_search_user_chat_model.dart +++ b/lib/models/chat/get_search_user_chat_model.dart @@ -19,21 +19,23 @@ class ChatUserModel { } class ChatUser { - ChatUser( - {this.id, - this.userName, - this.email, - this.phone, - this.title, - this.userStatus, - this.image, - this.unreadMessageCount, - this.userAction, - this.isPin, - this.isFav, - this.isAdmin, - this.isTyping, - this.isLoadingCounter}); + ChatUser({ + this.id, + this.userName, + this.email, + this.phone, + this.title, + this.userStatus, + this.image, + this.unreadMessageCount, + this.userAction, + this.isPin, + this.isFav, + this.isAdmin, + this.isTyping, + this.isImageLoaded, + this.isImageLoading, + }); int? id; String? userName; @@ -48,7 +50,8 @@ class ChatUser { bool? isFav; bool? isAdmin; bool? isTyping; - bool? isLoadingCounter; + bool? isImageLoaded; + bool? isImageLoading; factory ChatUser.fromJson(Map json) => ChatUser( id: json["id"] == null ? null : json["id"], @@ -64,7 +67,8 @@ class ChatUser { isFav: json["isFav"] == null ? null : json["isFav"], isAdmin: json["isAdmin"] == null ? null : json["isAdmin"], isTyping: false, - isLoadingCounter: true, + isImageLoaded: false, + isImageLoading: true, ); Map toJson() => { diff --git a/lib/models/chat/get_single_user_chat_list_model.dart b/lib/models/chat/get_single_user_chat_list_model.dart index 6a35f0e..07b2f51 100644 --- a/lib/models/chat/get_single_user_chat_list_model.dart +++ b/lib/models/chat/get_single_user_chat_list_model.dart @@ -1,32 +1,35 @@ import 'dart:convert'; +import 'package:flutter/foundation.dart'; + List singleUserChatModelFromJson(String str) => List.from(json.decode(str).map((x) => SingleUserChatModel.fromJson(x))); String singleUserChatModelToJson(List data) => json.encode(List.from(data.map((x) => x.toJson()))); class SingleUserChatModel { - SingleUserChatModel({ - this.userChatHistoryId, - this.userChatHistoryLineId, - this.contant, - this.contantNo, - this.currentUserId, - this.currentUserName, - this.targetUserId, - this.targetUserName, - this.encryptedTargetUserId, - this.encryptedTargetUserName, - this.chatEventId, - this.fileTypeId, - this.isSeen, - this.isDelivered, - this.createdDate, - this.chatSource, - this.conversationId, - this.fileTypeResponse, - this.userChatReplyResponse, - this.isReplied, - }); + SingleUserChatModel( + {this.userChatHistoryId, + this.userChatHistoryLineId, + this.contant, + this.contantNo, + this.currentUserId, + this.currentUserName, + this.targetUserId, + this.targetUserName, + this.encryptedTargetUserId, + this.encryptedTargetUserName, + this.chatEventId, + this.fileTypeId, + this.isSeen, + this.isDelivered, + this.createdDate, + this.chatSource, + this.conversationId, + this.fileTypeResponse, + this.userChatReplyResponse, + this.isReplied, + this.isImageLoaded, + this.image}); int? userChatHistoryId; int? userChatHistoryLineId; @@ -48,29 +51,32 @@ class SingleUserChatModel { FileTypeResponse? fileTypeResponse; UserChatReplyResponse? userChatReplyResponse; bool? isReplied; + bool? isImageLoaded; + Uint8List? image; factory SingleUserChatModel.fromJson(Map json) => SingleUserChatModel( - userChatHistoryId: json["userChatHistoryId"] == null ? null : json["userChatHistoryId"], - userChatHistoryLineId: json["userChatHistoryLineId"] == null ? null : json["userChatHistoryLineId"], - contant: json["contant"] == null ? null : json["contant"], - contantNo: json["contantNo"] == null ? null : json["contantNo"], - currentUserId: json["currentUserId"] == null ? null : json["currentUserId"], - currentUserName: json["currentUserName"] == null ? null : json["currentUserName"], - targetUserId: json["targetUserId"] == null ? null : json["targetUserId"], - targetUserName: json["targetUserName"] == null ? null : json["targetUserName"], - encryptedTargetUserId: json["encryptedTargetUserId"] == null ? null : json["encryptedTargetUserId"], - encryptedTargetUserName: json["encryptedTargetUserName"] == null ? null : json["encryptedTargetUserName"], - chatEventId: json["chatEventId"] == null ? null : json["chatEventId"], - fileTypeId: json["fileTypeId"], - isSeen: json["isSeen"] == null ? null : json["isSeen"], - isDelivered: json["isDelivered"] == null ? null : json["isDelivered"], - createdDate: json["createdDate"] == null ? null : DateTime.parse(json["createdDate"]), - chatSource: json["chatSource"] == null ? null : json["chatSource"], - conversationId: json["conversationId"] == null ? null : json["conversationId"], - fileTypeResponse: json["fileTypeResponse"] == null ? null : FileTypeResponse.fromJson(json["fileTypeResponse"]), - userChatReplyResponse: json["userChatReplyResponse"] == null ? null : UserChatReplyResponse.fromJson(json["userChatReplyResponse"]), - isReplied: false, - ); + userChatHistoryId: json["userChatHistoryId"] == null ? null : json["userChatHistoryId"], + userChatHistoryLineId: json["userChatHistoryLineId"] == null ? null : json["userChatHistoryLineId"], + contant: json["contant"] == null ? null : json["contant"], + contantNo: json["contantNo"] == null ? null : json["contantNo"], + currentUserId: json["currentUserId"] == null ? null : json["currentUserId"], + currentUserName: json["currentUserName"] == null ? null : json["currentUserName"], + targetUserId: json["targetUserId"] == null ? null : json["targetUserId"], + targetUserName: json["targetUserName"] == null ? null : json["targetUserName"], + encryptedTargetUserId: json["encryptedTargetUserId"] == null ? null : json["encryptedTargetUserId"], + encryptedTargetUserName: json["encryptedTargetUserName"] == null ? null : json["encryptedTargetUserName"], + chatEventId: json["chatEventId"] == null ? null : json["chatEventId"], + fileTypeId: json["fileTypeId"], + isSeen: json["isSeen"] == null ? null : json["isSeen"], + isDelivered: json["isDelivered"] == null ? null : json["isDelivered"], + createdDate: json["createdDate"] == null ? null : DateTime.parse(json["createdDate"]), + chatSource: json["chatSource"] == null ? null : json["chatSource"], + conversationId: json["conversationId"] == null ? null : json["conversationId"], + fileTypeResponse: json["fileTypeResponse"] == null ? null : FileTypeResponse.fromJson(json["fileTypeResponse"]), + userChatReplyResponse: json["userChatReplyResponse"] == null ? null : UserChatReplyResponse.fromJson(json["userChatReplyResponse"]), + isReplied: false, + isImageLoaded: false, + image: null); Map toJson() => { "userChatHistoryId": userChatHistoryId == null ? null : userChatHistoryId, @@ -138,6 +144,8 @@ class UserChatReplyResponse { this.targetUserId, this.targetUserName, this.fileTypeResponse, + this.isImageLoaded, + this.image, }); int? userChatHistoryId; @@ -149,18 +157,21 @@ class UserChatReplyResponse { int? targetUserId; String? targetUserName; FileTypeResponse? fileTypeResponse; + bool? isImageLoaded; + Uint8List? image; factory UserChatReplyResponse.fromJson(Map json) => UserChatReplyResponse( - userChatHistoryId: json["userChatHistoryId"] == null ? null : json["userChatHistoryId"], - chatEventId: json["chatEventId"] == null ? null : json["chatEventId"], - contant: json["contant"] == null ? null : json["contant"], - contantNo: json["contantNo"] == null ? null : json["contantNo"], - fileTypeId: json["fileTypeId"], - createdDate: json["createdDate"] == null ? null : DateTime.parse(json["createdDate"]), - targetUserId: json["targetUserId"] == null ? null : json["targetUserId"], - targetUserName: json["targetUserName"] == null ? null : json["targetUserName"], - fileTypeResponse: json["fileTypeResponse"] == null ? null : FileTypeResponse.fromJson(json["fileTypeResponse"]), - ); + userChatHistoryId: json["userChatHistoryId"] == null ? null : json["userChatHistoryId"], + chatEventId: json["chatEventId"] == null ? null : json["chatEventId"], + contant: json["contant"] == null ? null : json["contant"], + contantNo: json["contantNo"] == null ? null : json["contantNo"], + fileTypeId: json["fileTypeId"], + createdDate: json["createdDate"] == null ? null : DateTime.parse(json["createdDate"]), + targetUserId: json["targetUserId"] == null ? null : json["targetUserId"], + targetUserName: json["targetUserName"] == null ? null : json["targetUserName"], + fileTypeResponse: json["fileTypeResponse"] == null ? null : FileTypeResponse.fromJson(json["fileTypeResponse"]), + isImageLoaded: false, + image: null); Map toJson() => { "userChatHistoryId": userChatHistoryId == null ? null : userChatHistoryId, diff --git a/lib/models/marathon/marathon_generic_model.dart b/lib/models/marathon/marathon_generic_model.dart new file mode 100644 index 0000000..d0a0d52 --- /dev/null +++ b/lib/models/marathon/marathon_generic_model.dart @@ -0,0 +1,31 @@ +class MarathonGenericModel { + MarathonGenericModel({ + this.data, + this.isSuccessful, + this.message, + this.statusCode, + this.errors, + }); + + dynamic data; + bool? isSuccessful; + String? message; + int? statusCode; + dynamic errors; + + factory MarathonGenericModel.fromJson(Map json) => MarathonGenericModel( + data: json["data"], + isSuccessful: json["isSuccessful"], + message: json["message"], + statusCode: json["statusCode"], + errors: json["errors"], + ); + + Map toJson() => { + "data": data, + "isSuccessful": isSuccessful, + "message": message, + "statusCode": statusCode, + "errors": errors, + }; +} diff --git a/lib/models/marathon/marathon_model.dart b/lib/models/marathon/marathon_model.dart new file mode 100644 index 0000000..b32530c --- /dev/null +++ b/lib/models/marathon/marathon_model.dart @@ -0,0 +1,256 @@ +class MarathonDetailModel { + String? id; + String? titleEn; + String? titleAr; + String? descEn; + String? descAr; + int? winDeciderTime; + int? winnersCount; + int? questGapTime; + String? startTime; + String? endTime; + int? marathoneStatusId; + String? scheduleTime; + int? selectedLanguage; + Projects? projects; + List? sponsors; + List? questions; + int? totalQuestions; + + MarathonDetailModel( + {id, + titleEn, + titleAr, + descEn, + descAr, + winDeciderTime, + winnersCount, + questGapTime, + startTime, + endTime, + marathoneStatusId, + scheduleTime, + selectedLanguage, + projects, + sponsors, + questions, + totalQuestions}); + + MarathonDetailModel.fromJson(Map json) { + id = json['id']; + titleEn = json['titleEn']; + titleAr = json['titleAr']; + descEn = json['descEn']; + descAr = json['descAr']; + winDeciderTime = json['winDeciderTime']; + winnersCount = json['winnersCount']; + questGapTime = json['questGapTime']; + startTime = json['startTime']; + endTime = json['endTime']; + marathoneStatusId = json['marathoneStatusId']; + scheduleTime = json['scheduleTime']; + selectedLanguage = json['selectedLanguage']; + projects = json['projects'] != null + ? Projects.fromJson(json['projects']) + : null; + if (json['sponsors'] != null) { + sponsors = []; + json['sponsors'].forEach((v) { + sponsors!.add( Sponsors.fromJson(v)); + }); + } + if (json['questions'] != null) { + questions = []; + json['questions'].forEach((v) { + questions!.add( Questions.fromJson(v)); + }); + } + totalQuestions = json["totalQuestions"]; + } + + Map toJson() { + Map data = {}; + data['id'] = id; + data['titleEn'] = titleEn; + data['titleAr'] = titleAr; + data['descEn'] = descEn; + data['descAr'] = descAr; + data['winDeciderTime'] = winDeciderTime; + data['winnersCount'] = winnersCount; + data['questGapTime'] = questGapTime; + data['startTime'] = startTime; + data['endTime'] = endTime; + data['marathoneStatusId'] = marathoneStatusId; + data['scheduleTime'] = scheduleTime; + data['selectedLanguage'] = selectedLanguage; + if (projects != null) { + data['projects'] = projects!.toJson(); + } + if (sponsors != null) { + data['sponsors'] = sponsors!.map((v) => v.toJson()).toList(); + } + if (questions != null) { + data['questions'] = questions!.map((v) => v.toJson()).toList(); + } + data['totalQuestions'] = totalQuestions; + + return data; + } +} + +class Projects { + String? id; + String? nameEn; + String? nameAr; + String? projectCode; + + Projects({id, nameEn, nameAr, projectCode}); + + Projects.fromJson(Map json) { + id = json['id']; + nameEn = json['nameEn']; + nameAr = json['nameAr']; + projectCode = json['projectCode']; + } + + Map toJson() { + Map data = {}; + data['id'] = id; + data['nameEn'] = nameEn; + data['nameAr'] = nameAr; + data['projectCode'] = projectCode; + return data; + } +} + +class Sponsors { + String? id; + String? nameEn; + Null? nameAr; + String? image; + Null? video; + Null? logo; + List? sponsorPrizes; + + Sponsors( + {id, + nameEn, + nameAr, + image, + video, + logo, + sponsorPrizes}); + + Sponsors.fromJson(Map json) { + id = json['id']; + nameEn = json['nameEn']; + nameAr = json['nameAr']; + image = json['image']; + video = json['video']; + logo = json['logo']; + if (json['sponsorPrizes'] != null) { + sponsorPrizes = []; + json['sponsorPrizes'].forEach((v) { + sponsorPrizes!.add( SponsorPrizes.fromJson(v)); + }); + } + } + + Map toJson() { + Map data = {}; + data['id'] = id; + data['nameEn'] = nameEn; + data['nameAr'] = nameAr; + data['image'] = image; + data['video'] = video; + data['logo'] = logo; + if (sponsorPrizes != null) { + data['sponsorPrizes'] = + sponsorPrizes!.map((v) => v.toJson()).toList(); + } + return data; + } +} + +class SponsorPrizes { + String? id; + String? marathonPrizeEn; + String? marathonPrizeAr; + + SponsorPrizes({id, marathonPrizeEn, marathonPrizeAr}); + + SponsorPrizes.fromJson(Map json) { + id = json['id']; + marathonPrizeEn = json['marathonPrizeEn']; + marathonPrizeAr = json['marathonPrizeAr']; + } + + Map toJson() { + Map data = new Map(); + data['id'] = id; + data['marathonPrizeEn'] = marathonPrizeEn; + data['marathonPrizeAr'] = marathonPrizeAr; + return data; + } +} + +class Questions { + String? id; + String? titleEn; + String? titleAr; + String? marathonId; + int? questionTypeId; + int? questionTime; + int? nextQuestGap; + int? gapType; + String? gapValue; + String? gapImage; + int? questOptionsLimit; + List? questionOptions; + + Questions( + {id, + titleEn, + titleAr, + marathonId, + questionTypeId, + questionTime, + nextQuestGap, + gapType, + gapValue, + gapImage, + questOptionsLimit, + questionOptions}); + + Questions.fromJson(Map json) { + id = json['id']; + titleEn = json['titleEn']; + titleAr = json['titleAr']; + marathonId = json['marathonId']; + questionTypeId = json['questionTypeId']; + questionTime = json['questionTime']; + nextQuestGap = json['nextQuestGap']; + gapType = json['gapType']; + gapValue = json['gapValue']; + gapImage = json['gapImage']; + questOptionsLimit = json['questOptionsLimit']; + questionOptions = json['questionOptions']; + } + + Map toJson() { + Map data = {}; + data['id'] = id; + data['titleEn'] = titleEn; + data['titleAr'] = titleAr; + data['marathonId'] = marathonId; + data['questionTypeId'] = questionTypeId; + data['questionTime'] = questionTime; + data['nextQuestGap'] = nextQuestGap; + data['gapType'] = gapType; + data['gapValue'] = gapValue; + data['gapImage'] = gapImage; + data['questOptionsLimit'] = questOptionsLimit; + data['questionOptions'] = questionOptions; + return data; + } +} diff --git a/lib/models/marathon/question_model.dart b/lib/models/marathon/question_model.dart new file mode 100644 index 0000000..0bb42cd --- /dev/null +++ b/lib/models/marathon/question_model.dart @@ -0,0 +1,117 @@ +enum QuestionsOptionStatus { correct, wrong, selected, unSelected } + +enum QuestionCardStatus { question, wrongAnswer, correctAnswer, skippedAnswer, completed, findingWinner, winnerFound } + +class QuestionModel { + String? id; + String? titleEn; + String? titleAr; + String? marathonId; + int? questionTypeId; + int? questionTime; + int? nextQuestGap; + int? gapType; + String? gapText; + String? gapImage; + int? questOptionsLimit; + List? questionOptions; + + QuestionModel({ + String? id, + String? titleEn, + String? titleAr, + String? marathonId, + int? questionTypeId, + int? questionTime, + int? nextQuestGap, + int? gapType, + String? gapText, + String? gapImage, + int? questOptionsLimit, + List? questionOptions, + }); + + QuestionModel.fromJson(Map json) { + id = json['id']; + titleEn = json['titleEn']; + titleAr = json['titleAr']; + marathonId = json['marathonId']; + questionTypeId = json['questionTypeId']; + questionTime = json['questionTime']; + nextQuestGap = json['nextQuestGap']; + gapType = json['gapType']; + gapText = json['gapText']; + gapImage = json['gapImage']; + questOptionsLimit = json['questOptionsLimit']; + if (json['questionOptions'] != null) { + questionOptions = []; + json['questionOptions'].forEach((v) { + questionOptions!.add(QuestionOptions.fromJson(v)); + }); + } + } + + Map toJson() { + Map data = {}; + data['id'] = id; + data['titleEn'] = titleEn; + data['titleAr'] = titleAr; + data['marathonId'] = marathonId; + data['questionTypeId'] = questionTypeId; + data['questionTime'] = questionTime; + data['nextQuestGap'] = nextQuestGap; + data['gapType'] = gapType; + data['gapText'] = gapText; + data['gapImage'] = gapImage; + data['questOptionsLimit'] = questOptionsLimit; + if (questionOptions != null) { + data['questionOptions'] = questionOptions!.map((v) => v.toJson()).toList(); + } + return data; + } +} + +class QuestionOptions { + String? id; + String? titleEn; + String? titleAr; + String? questionId; + int? sequence; + String? image; + bool? isCorrectOption; + QuestionsOptionStatus? optionStatus; + + QuestionOptions({ + String? id, + String? titleEn, + String? titleAr, + String? questionId, + int? sequence, + String? image, + bool? isCorrectOption, + QuestionsOptionStatus? optionStatus, + }); + + QuestionOptions.fromJson(Map json) { + id = json['id']; + titleEn = json['titleEn']; + titleAr = json['titleAr']; + questionId = json['questionId']; + sequence = json['sequence']; + image = json['image']; + isCorrectOption = json['isCorrectOption']; + optionStatus = QuestionsOptionStatus.unSelected; + } + + Map toJson() { + Map data = {}; + data['id'] = id; + data['titleEn'] = titleEn; + data['titleAr'] = titleAr; + data['questionId'] = questionId; + data['sequence'] = sequence; + data['image'] = image; + data['isCorrectOption'] = isCorrectOption; + return data; + } +} diff --git a/lib/provider/chat_provider_model.dart b/lib/provider/chat_provider_model.dart index 81cb8b5..0b522db 100644 --- a/lib/provider/chat_provider_model.dart +++ b/lib/provider/chat_provider_model.dart @@ -5,18 +5,20 @@ import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/foundation.dart'; import 'package:http/http.dart'; -import 'package:logging/logging.dart'; import 'package:mohem_flutter_app/api/chat/chat_api_client.dart'; import 'package:mohem_flutter_app/app_state/app_state.dart'; import 'package:mohem_flutter_app/classes/consts.dart'; +import 'package:mohem_flutter_app/classes/encryption.dart'; import 'package:mohem_flutter_app/classes/utils.dart'; import 'package:mohem_flutter_app/main.dart'; +import 'package:mohem_flutter_app/models/chat/chat_user_image_model.dart'; import 'package:mohem_flutter_app/models/chat/get_search_user_chat_model.dart'; import 'package:mohem_flutter_app/models/chat/get_single_user_chat_list_model.dart'; -import 'package:mohem_flutter_app/models/chat/get_user_login_token_model.dart' as login; +import 'package:mohem_flutter_app/models/chat/get_user_login_token_model.dart' as userLoginToken; import 'package:mohem_flutter_app/models/chat/make_user_favotire_unfavorite_chat_model.dart' as fav; import 'package:mohem_flutter_app/ui/landing/dashboard_screen.dart'; import 'package:mohem_flutter_app/widgets/image_picker.dart'; +import 'package:signalr_netcore/hub_connection.dart'; import 'package:signalr_netcore/signalr_client.dart'; import 'package:uuid/uuid.dart'; @@ -37,18 +39,58 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { List favUsersList = []; int paginationVal = 0; + Future getUserAutoLoginToken() async { + userLoginToken.UserAutoLoginModel userLoginResponse = await ChatApiClient().getUserLoginToken(); + if (userLoginResponse.response != null) { + AppState().setchatUserDetails = userLoginResponse; + } else { + Utils.showToast( + userLoginResponse.errorResponses!.first.fieldName.toString() + " Erorr", + ); + } + } + + Future buildHubConnection() async { + chatHubConnection = await getHubConnection(); + await chatHubConnection.start(); + } + + Future getHubConnection() async { + HubConnection hub; + // try { + HttpConnectionOptions httpOp = HttpConnectionOptions(skipNegotiation: false, logMessageContent: true); + hub = HubConnectionBuilder() + .withUrl(ApiConsts.chatHubConnectionUrl + "?UserId=${AppState().chatDetails!.response!.id}&source=Web&access_token=${AppState().chatDetails!.response!.token}", options: httpOp) + .withAutomaticReconnect(retryDelays: [2000, 5000, 10000, 20000]).build(); + // isChatHubLoding = false; + return hub; + // } catch (e) { + // getUserAutoLoginToken().whenComplete(() { + // getHubConnection(); + // }); + // throw e; + // } + } + void registerEvents() { - hubConnection.on("OnUpdateUserStatusAsync", changeStatus); - hubConnection.on("OnDeliveredChatUserAsync", onMsgReceived); - // hubConnection.on("OnSeenChatUserAsync", onChatSeen); + chatHubConnection.on("OnUpdateUserStatusAsync", changeStatus); + chatHubConnection.on("OnDeliveredChatUserAsync", onMsgReceived); + // hubConnection.on("OnSeenChatUserAsync", onChatSeen); //hubConnection.on("OnUserTypingAsync", onUserTyping); - hubConnection.on("OnUserCountAsync", userCountAsync); - hubConnection.on("OnUpdateUserChatHistoryWindowsAsync", updateChatHistoryWindow); - hubConnection.on("OnGetUserChatHistoryNotDeliveredAsync", chatNotDelivered); - hubConnection.on("OnUpdateUserChatHistoryStatusAsync", updateUserChatStatus); + chatHubConnection.on("OnUserCountAsync", userCountAsync); + // hubConnection.on("OnUpdateUserChatHistoryWindowsAsync", updateChatHistoryWindow); + chatHubConnection.on("OnGetUserChatHistoryNotDeliveredAsync", chatNotDelivered); + chatHubConnection.on("OnUpdateUserChatHistoryStatusAsync", updateUserChatStatus); } void getUserRecentChats() async { + if (chatHubConnection.state != HubConnectionState.Connected) { + getUserAutoLoginToken().whenComplete(() async { + await buildHubConnection(); + getUserRecentChats(); + }); + return; + } ChatUserModel recentChat = await ChatApiClient().getRecentChats(); ChatUserModel favUList = await ChatApiClient().getFavUsers(); @@ -79,10 +121,11 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { ), ); notifyListeners(); + getUserImages(); } Future invokeUserChatHistoryNotDeliveredAsync({required int userId}) async { - await hubConnection.invoke("GetUserChatHistoryNotDeliveredAsync", args: [userId]); + await chatHubConnection.invoke("GetUserChatHistoryNotDeliveredAsync", args: [userId]); return ""; } @@ -91,12 +134,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { if (isNewChat) userChatHistory = []; if (!loadMore) paginationVal = 0; isChatScreenActive = true; - Response response = await ChatApiClient().getSingleUserChatHistory( - senderUID: senderUID, - receiverUID: receiverUID, - loadMore: loadMore, - paginationVal: paginationVal, - ); + Response response = await ChatApiClient().getSingleUserChatHistory(senderUID: senderUID, receiverUID: receiverUID, loadMore: loadMore, paginationVal: paginationVal); if (response.statusCode == 204) { if (isNewChat) { userChatHistory = []; @@ -106,24 +144,15 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { } } else { if (loadMore) { - List temp = getSingleUserChatModel( - response.body, - ).reversed.toList(); - userChatHistory.addAll( - temp, - ); + List temp = getSingleUserChatModel(response.body).reversed.toList(); + userChatHistory.addAll(temp); } else { - userChatHistory = getSingleUserChatModel( - response.body, - ).reversed.toList(); + userChatHistory = getSingleUserChatModel(response.body).reversed.toList(); } } isLoading = false; notifyListeners(); - markRead( - userChatHistory, - receiverUID, - ); + markRead(userChatHistory, receiverUID); generateConvId(); } @@ -137,75 +166,79 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { for (SingleUserChatModel element in data!) { if (element.isSeen != null) { if (!element.isSeen!) { + element.isSeen = true; dynamic data = [ { "userChatHistoryId": element.userChatHistoryId, - "TargetUserId": element.targetUserId, + "TargetUserId": element.currentUserId == receiverID ? element.currentUserId : element.targetUserId, "isDelivered": true, "isSeen": true, } ]; updateUserChatHistoryStatusAsync(data); + notifyListeners(); } } } for (ChatUser element in searchedChats!) { if (element.id == receiverID) { element.unreadMessageCount = 0; - notifyListeners(); + // notifyListeners(); } } + notifyListeners(); } } void updateUserChatHistoryStatusAsync(List data) { - hubConnection.invoke( - "UpdateUserChatHistoryStatusAsync", - args: [data], - ); + try { + chatHubConnection.invoke("UpdateUserChatHistoryStatusAsync", args: [data]); + } catch (e) { + throw e; + } } - List getSingleUserChatModel(String str) => List.from( - json.decode(str).map( - (x) => SingleUserChatModel.fromJson(x), - ), - ); + void updateUserChatHistoryOnMsg(List data) { + try { + chatHubConnection.invoke("UpdateUserChatHistoryStatusAsync", args: [data]); + } catch (e) { + throw e; + } + } + + List getSingleUserChatModel(String str) => List.from(json.decode(str).map((x) => SingleUserChatModel.fromJson(x))); Future uploadAttachments(String userId, File file) async { dynamic result; try { StreamedResponse response = await ChatApiClient().uploadMedia(userId, file); if (response.statusCode == 200) { - result = jsonDecode( - await response.stream.bytesToString(), - ); + result = jsonDecode(await response.stream.bytesToString()); } else { result = []; } } catch (e) { - print(e); + throw e; } - ; + return result; } void updateUserChatStatus(List? args) { dynamic items = args!.toList(); - for (dynamic cItem in items[0]) { + for (var cItem in items[0]) { for (SingleUserChatModel chat in userChatHistory) { - if (chat.userChatHistoryId.toString() == cItem["userChatHistoryId"].toString()) { + if (cItem["contantNo"].toString() == chat.contantNo.toString()) { chat.isSeen = cItem["isSeen"]; chat.isDelivered = cItem["isDelivered"]; - notifyListeners(); } } } + notifyListeners(); } void onChatSeen(List? args) { dynamic items = args!.toList(); - logger.d("---------------------------------Chat Seen -------------------------------------"); - logger.d(items); // for (var user in searchedChats!) { // if (user.id == items.first["id"]) { // user.userStatus = items.first["userStatus"]; @@ -241,7 +274,6 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { void chatNotDelivered(List? args) { dynamic items = args!.toList(); - logger.d(items); for (dynamic item in items[0]) { searchedChats!.forEach( (ChatUser element) { @@ -249,7 +281,6 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { int? val = element.unreadMessageCount ?? 0; element.unreadMessageCount = val! + 1; } - element.isLoadingCounter = false; }, ); } @@ -291,18 +322,35 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { data.first.targetUserName = temp.first.currentUserName; data.first.currentUserId = temp.first.targetUserId; data.first.currentUserName = temp.first.targetUserName; + if (data.first.fileTypeId == 12 || data.first.fileTypeId == 4 || data.first.fileTypeId == 3) { + data.first.image = await ChatApiClient().downloadURL(fileName: data.first.contant!, fileTypeDescription: data.first.fileTypeResponse!.fileTypeDescription ?? "image/jpg"); + } + if (data.first.userChatReplyResponse != null) { + if (data.first.fileTypeResponse != null) { + if (data.first.userChatReplyResponse!.fileTypeId == 12 || data.first.userChatReplyResponse!.fileTypeId == 4 || data.first.userChatReplyResponse!.fileTypeId == 3) { + data.first.userChatReplyResponse!.image = + await ChatApiClient().downloadURL(fileName: data.first.userChatReplyResponse!.contant!, fileTypeDescription: data.first.fileTypeResponse!.fileTypeDescription ?? "image/jpg"); + data.first.userChatReplyResponse!.isImageLoaded = true; + } + } + } } - logger.d(jsonEncode(data)); + userChatHistory.insert(0, data.first); - var list = [ - { - "userChatHistoryId": data.first.userChatHistoryId, - "TargetUserId": data.first.targetUserId, - "isDelivered": true, - "isSeen": isChatScreenActive ? true : false, + + if (searchedChats != null && !isChatScreenActive) { + for (ChatUser user in searchedChats!) { + if (user.id == data.first.currentUserId) { + var tempCount = user.unreadMessageCount ?? 0; + user.unreadMessageCount = tempCount + 1; + } } + } + + List list = [ + {"userChatHistoryId": data.first.userChatHistoryId, "TargetUserId": temp.first.targetUserId, "isDelivered": true, "isSeen": isChatScreenActive ? true : false} ]; - updateUserChatHistoryStatusAsync(list); + updateUserChatHistoryOnMsg(list); notifyListeners(); } @@ -389,34 +437,44 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { } Future sendChatToServer( - {required int chatEventId, required fileTypeId, required int targetUserId, required String targetUserName, required chatReplyId, required bool isAttachment, required bool isReply}) async { + {required int chatEventId, + required fileTypeId, + required int targetUserId, + required String targetUserName, + required chatReplyId, + required bool isAttachment, + required bool isReply, + Uint8List? image, + required bool isImageLoaded}) async { Uuid uuid = const Uuid(); + var contentNo = uuid.v4(); var msg = message.text; SingleUserChatModel data = SingleUserChatModel( - chatEventId: chatEventId, - chatSource: 1, - contant: msg, - contantNo: uuid.v4(), - conversationId: chatCID, - createdDate: DateTime.now(), - currentUserId: AppState().chatDetails!.response!.id, - currentUserName: AppState().chatDetails!.response!.userName, - targetUserId: targetUserId, - targetUserName: targetUserName, - isReplied: false, - fileTypeId: fileTypeId, - userChatReplyResponse: isReply ? UserChatReplyResponse.fromJson(repliedMsg.first.toJson()) : null, - fileTypeResponse: isAttachment - ? FileTypeResponse( - fileTypeId: fileTypeId, - fileTypeName: getFileType(getFileExtension(selectedFile.path).toString()), - fileKind: getFileExtension(selectedFile.path), - fileName: selectedFile.path.split("/").last, - fileTypeDescription: getFileTypeDescription(getFileExtension(selectedFile.path).toString()), - ) - : null, - ); + chatEventId: chatEventId, + chatSource: 1, + contant: msg, + contantNo: contentNo, + conversationId: chatCID, + createdDate: DateTime.now(), + currentUserId: AppState().chatDetails!.response!.id, + currentUserName: AppState().chatDetails!.response!.userName, + targetUserId: targetUserId, + targetUserName: targetUserName, + isReplied: false, + fileTypeId: fileTypeId, + userChatReplyResponse: isReply ? UserChatReplyResponse.fromJson(repliedMsg.first.toJson()) : null, + fileTypeResponse: isAttachment + ? FileTypeResponse( + fileTypeId: fileTypeId, + fileTypeName: getFileType(getFileExtension(selectedFile.path).toString()), + fileKind: getFileExtension(selectedFile.path), + fileName: selectedFile.path.split("/").last, + fileTypeDescription: getFileTypeDescription(getFileExtension(selectedFile.path).toString()), + ) + : null, + image: image, + isImageLoaded: isImageLoaded); userChatHistory.insert(0, data); isFileSelected = false; isMsgReply = false; @@ -425,55 +483,75 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { notifyListeners(); String chatData = - '{"contant":"$msg","contantNo":"${uuid.v4()}","chatEventId":$chatEventId,"fileTypeId": $fileTypeId,"currentUserId":${AppState().chatDetails!.response!.id},"chatSource":1,"userChatHistoryLineRequestList":[{"isSeen":false,"isDelivered":false,"targetUserId":$targetUserId,"targetUserStatus":1}],"chatReplyId":$chatReplyId,"conversationId":"$chatCID"}'; - await hubConnection.invoke("AddChatUserAsync", args: [json.decode(chatData)]); + '{"contant":"$msg","contantNo":"$contentNo","chatEventId":$chatEventId,"fileTypeId": $fileTypeId,"currentUserId":${AppState().chatDetails!.response!.id},"chatSource":1,"userChatHistoryLineRequestList":[{"isSeen":false,"isDelivered":false,"targetUserId":$targetUserId,"targetUserStatus":1}],"chatReplyId":$chatReplyId,"conversationId":"$chatCID"}'; + await chatHubConnection.invoke("AddChatUserAsync", args: [json.decode(chatData)]); } void sendChatMessage(int targetUserId, String targetUserName, BuildContext context) async { dynamic contain = searchedChats!.where((ChatUser element) => element.id == targetUserId); if (contain.isEmpty) { searchedChats!.add( - ChatUser( - id: targetUserId, - userName: targetUserName, - ), + ChatUser(id: targetUserId, userName: targetUserName, unreadMessageCount: 0), ); notifyListeners(); } if (!isFileSelected && !isMsgReply) { + print("Normal Text Msg"); if (message.text == null || message.text.isEmpty) { return; } - sendChatToServer(chatEventId: 1, fileTypeId: null, targetUserId: targetUserId, targetUserName: targetUserName, isAttachment: false, chatReplyId: null, isReply: false); - } + sendChatToServer( + chatEventId: 1, fileTypeId: null, targetUserId: targetUserId, targetUserName: targetUserName, isAttachment: false, chatReplyId: null, isReply: false, isImageLoaded: false, image: null); + } // normal Text msg if (isFileSelected && !isMsgReply) { + print("Normal Attachment Msg"); Utils.showLoading(context); dynamic value = await uploadAttachments(AppState().chatDetails!.response!.id.toString(), selectedFile); String? ext = getFileExtension(selectedFile.path); Utils.hideLoading(context); - sendChatToServer(chatEventId: 2, fileTypeId: getFileType(ext.toString()), targetUserId: targetUserId, targetUserName: targetUserName, isAttachment: true, chatReplyId: null, isReply: false); - } + sendChatToServer( + chatEventId: 2, + fileTypeId: getFileType(ext.toString()), + targetUserId: targetUserId, + targetUserName: targetUserName, + isAttachment: true, + chatReplyId: null, + isReply: false, + isImageLoaded: true, + image: selectedFile.readAsBytesSync()); + } // normal attachemnt msg if (!isFileSelected && isMsgReply) { + print("Normal Text To Text Reply"); if (message.text == null || message.text.isEmpty) { return; } sendChatToServer( - chatEventId: 1, fileTypeId: null, targetUserId: targetUserId, targetUserName: targetUserName, chatReplyId: repliedMsg.first.userChatHistoryId, isAttachment: false, isReply: true); - } + chatEventId: 1, + fileTypeId: null, + targetUserId: targetUserId, + targetUserName: targetUserName, + chatReplyId: repliedMsg.first.userChatHistoryId, + isAttachment: false, + isReply: true, + isImageLoaded: repliedMsg.first.isImageLoaded!, + image: repliedMsg.first.image); + } // reply msg over image && normal if (isFileSelected && isMsgReply) { + print("Reply With File"); Utils.showLoading(context); dynamic value = await uploadAttachments(AppState().chatDetails!.response!.id.toString(), selectedFile); String? ext = getFileExtension(selectedFile.path); Utils.hideLoading(context); sendChatToServer( - chatEventId: 2, - fileTypeId: getFileType(ext.toString()), - targetUserId: targetUserId, - targetUserName: targetUserName, - isAttachment: true, - chatReplyId: repliedMsg.first.userChatHistoryId, - isReply: true, - ); + chatEventId: 2, + fileTypeId: getFileType(ext.toString()), + targetUserId: targetUserId, + targetUserName: targetUserName, + isAttachment: true, + chatReplyId: repliedMsg.first.userChatHistoryId, + isReply: true, + isImageLoaded: true, + image: selectedFile.readAsBytesSync()); } } @@ -587,6 +665,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { Future unFavoriteUser({required int userID, required int targetUserID}) async { fav.FavoriteChatUser favoriteChatUser = await ChatApiClient().unFavUser(userID: userID, targetUserID: targetUserID); + if (favoriteChatUser.response != null) { for (ChatUser user in searchedChats!) { if (user.id == favoriteChatUser.response!.targetUserId!) { @@ -597,6 +676,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { (ChatUser element) => element.id == targetUserID, ); } + notifyListeners(); } @@ -609,6 +689,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { isFileSelected = false; repliedMsg = []; sFileType = ""; + isMsgReply = false; notifyListeners(); } @@ -623,36 +704,35 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { sFileType = ""; } - // void scrollListener() { - // _firstAutoscrollExecuted = true; - // if (scrollController.hasClients && scrollController.position.pixels == scrollController.position.maxScrollExtent) { - // _shouldAutoscroll = true; - // } else { - // _shouldAutoscroll = false; - // } - // } - // - // void scrollToBottom() { - // scrollController.animateTo( - // scrollController.position.maxScrollExtent + 100, - // duration: const Duration(milliseconds: 500), - // curve: Curves.easeIn, - // ); - // } - - void msgScroll() { - scrollController.animateTo( - scrollController.position.minScrollExtent - 100, - duration: const Duration(milliseconds: 500), - curve: Curves.easeIn, - ); + void getUserImages() async { + List emails = []; + for (ChatUser element in searchedChats!) { + emails.add(await EmailImageEncryption().encrypt(val: element.email!)); + } + List chatImages = await ChatApiClient().getUsersImages(encryptedEmails: emails); + for (ChatUser user in searchedChats!) { + for (ChatUserImageModel uImage in chatImages) { + if (user.email == uImage.email) { + user.image = uImage.profilePicture ?? ""; + user.isImageLoading = false; + user.isImageLoaded = true; + } + } + } + for (ChatUser favUser in favUsersList) { + for (ChatUserImageModel uImage in chatImages) { + if (favUser.email == uImage.email) { + favUser.image = uImage.profilePicture ?? ""; + favUser.isImageLoading = false; + favUser.isImageLoaded = true; + } + } + } + notifyListeners(); } -// void getUserChatHistoryNotDeliveredAsync({required int userId}) async { -// try { -// await hubConnection.invoke("GetUserChatHistoryNotDeliveredAsync", args: [userId]); -// } finally { -// hubConnection.off("GetUserChatHistoryNotDeliveredAsync", method: chatNotDelivered); -// } -// } + ///getUserAutoLoginToken().whenComplete(() { +// buildHubConnection(); +// print("After Reconnect State: " + hubConnection.state.toString()); +// }); } diff --git a/lib/provider/dashboard_provider_model.dart b/lib/provider/dashboard_provider_model.dart index b785293..48531b7 100644 --- a/lib/provider/dashboard_provider_model.dart +++ b/lib/provider/dashboard_provider_model.dart @@ -1,17 +1,13 @@ import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; -import 'package:mohem_flutter_app/api/chat/chat_api_client.dart'; import 'package:mohem_flutter_app/api/dashboard_api_client.dart'; import 'package:mohem_flutter_app/api/offers_and_discounts_api_client.dart'; -import 'package:mohem_flutter_app/app_state/app_state.dart'; -import 'package:mohem_flutter_app/classes/consts.dart'; import 'package:mohem_flutter_app/classes/utils.dart'; import 'package:mohem_flutter_app/config/routes.dart'; import 'package:mohem_flutter_app/generated/locale_keys.g.dart'; import 'package:mohem_flutter_app/main.dart'; import 'package:mohem_flutter_app/models/chat/chat_count_conversation_model.dart'; -import 'package:mohem_flutter_app/models/chat/get_user_login_token_model.dart'; import 'package:mohem_flutter_app/models/dashboard/drawer_menu_item_model.dart'; import 'package:mohem_flutter_app/models/dashboard/get_accrual_balances_list_model.dart'; import 'package:mohem_flutter_app/models/dashboard/get_attendance_tracking_list_model.dart'; @@ -25,7 +21,6 @@ import 'package:mohem_flutter_app/models/generic_response_model.dart'; import 'package:mohem_flutter_app/models/itg/itg_response_model.dart'; import 'package:mohem_flutter_app/models/offers_and_discounts/get_offers_list.dart'; import 'package:mohem_flutter_app/widgets/dialogs/confirm_dialog.dart'; -import 'package:signalr_netcore/signalr_client.dart'; /// Mix-in [DiagnosticableTreeMixin] to have access to [debugFillProperties] for the devtool // ignore: prefer_mixin @@ -42,7 +37,6 @@ class DashboardProviderModel with ChangeNotifier, DiagnosticableTreeMixin { //Chat bool isChatCounterLoding = true; - bool isChatHubLoding = true; int chatUConvCounter = 0; //Misssing Swipe @@ -103,7 +97,6 @@ class DashboardProviderModel with ChangeNotifier, DiagnosticableTreeMixin { leaveBalanceAccrual = null; isChatCounterLoding = true; - isChatHubLoding = true; chatUConvCounter = 0; ticketBalance = 0; @@ -294,27 +287,6 @@ class DashboardProviderModel with ChangeNotifier, DiagnosticableTreeMixin { } } - Future getUserAutoLoginToken() async { - logger.d("Token Generated On Home"); - UserAutoLoginModel userLoginResponse = await ChatApiClient().getUserLoginToken(); - if (userLoginResponse.response != null) { - AppState().setchatUserDetails = userLoginResponse; - } else { - Utils.showToast( - userLoginResponse.errorResponses!.first.fieldName.toString() + " Erorr", - ); - } - } - - Future getHubConnection() async { - HubConnection hub; - HttpConnectionOptions httpOp = HttpConnectionOptions(skipNegotiation: false, logMessageContent: true); - hub = HubConnectionBuilder() - .withUrl(ApiConsts.chatHubConnectionUrl + "?UserId=${AppState().chatDetails!.response!.id}&source=Web&access_token=${AppState().chatDetails!.response!.token}", options: httpOp) - .withAutomaticReconnect(retryDelays: [2000, 5000, 10000, 20000]).build(); - isChatHubLoding = false; - return hub; - } void notify() { notifyListeners(); diff --git a/lib/ui/attendance/add_vacation_rule_screen.dart b/lib/ui/attendance/add_vacation_rule_screen.dart index caa1ee3..5d4bf75 100644 --- a/lib/ui/attendance/add_vacation_rule_screen.dart +++ b/lib/ui/attendance/add_vacation_rule_screen.dart @@ -316,7 +316,7 @@ class _AddVacationRuleScreenState extends State { 12.height, PopupMenuButton( child: DynamicTextFieldWidget( - "Notification", + LocaleKeys.notification.tr(), selectedItemTypeNotification == null ? LocaleKeys.selectNotification.tr() : selectedItemTypeNotification!.nOTIFICATIONDISPLAYNAME!, isEnable: false, isPopup: true, diff --git a/lib/ui/chat/chat_bubble.dart b/lib/ui/chat/chat_bubble.dart index 38c47ae..ec772f6 100644 --- a/lib/ui/chat/chat_bubble.dart +++ b/lib/ui/chat/chat_bubble.dart @@ -1,173 +1,133 @@ +import 'dart:typed_data'; + import 'package:flutter/material.dart'; +import 'package:mohem_flutter_app/api/api_client.dart'; +import 'package:mohem_flutter_app/api/chat/chat_api_client.dart'; +import 'package:mohem_flutter_app/app_state/app_state.dart'; import 'package:mohem_flutter_app/classes/colors.dart'; import 'package:mohem_flutter_app/extensions/int_extensions.dart'; import 'package:mohem_flutter_app/extensions/string_extensions.dart'; import 'package:mohem_flutter_app/extensions/widget_extensions.dart'; +import 'package:mohem_flutter_app/main.dart'; +import 'package:mohem_flutter_app/models/chat/get_single_user_chat_list_model.dart'; +import 'package:mohem_flutter_app/ui/chat/chat_full_image_preview.dart'; +import 'package:mohem_flutter_app/widgets/bottom_sheet.dart'; // todo: @aamir use extension methods, and use correct widgets. class ChatBubble extends StatelessWidget { - const ChatBubble( - {Key? key, - required this.text, - required this.replyText, - required this.isCurrentUser, - required this.isSeen, - required this.isDelivered, - required this.dateTime, - required this.isReplied, - required this.userName}) - : super(key: key); - final String text; - final String replyText; - final bool isCurrentUser; - final bool isSeen; - final bool isDelivered; + ChatBubble({Key? key, required this.dateTime, required this.cItem}) : super(key: key); final String dateTime; - final bool isReplied; - final String userName; + final SingleUserChatModel cItem; + + bool isCurrentUser = false; + bool isSeen = false; + bool isReplied = false; + int? fileTypeID; + + String? fileTypeDescription; + bool isDelivered = false; + String userName = ''; + late Offset screenOffset; + + void makeAssign() { + isCurrentUser = cItem.currentUserId == AppState().chatDetails!.response!.id ? true : false; + isSeen = cItem.isSeen == true ? true : false; + isReplied = cItem.userChatReplyResponse != null ? true : false; + fileTypeID = cItem.fileTypeId; + fileTypeDescription = cItem.fileTypeResponse != null ? cItem.fileTypeResponse!.fileTypeDescription : ""; + isDelivered = cItem.currentUserId == AppState().chatDetails!.response!.id && cItem.isDelivered == true ? true : false; + userName = AppState().chatDetails!.response!.userName == cItem.currentUserName.toString() ? "You" : cItem.currentUserName.toString(); + } @override Widget build(BuildContext context) { + Size windowSize = MediaQuery.of(context).size; + screenOffset = Offset(windowSize.width / 2, windowSize.height / 2); + makeAssign(); return isCurrentUser ? currentUser(context) : receiptUser(context); - - return Padding( - // padding: EdgeInsets.zero, - padding: EdgeInsets.only( - left: isCurrentUser ? 110 : 20, - right: isCurrentUser ? 20 : 110, - bottom: 9, - ), - - child: Align( - alignment: isCurrentUser ? Alignment.centerRight : Alignment.centerLeft, - child: DecoratedBox( - decoration: BoxDecoration( - color: MyColors.white, - gradient: isCurrentUser - ? null - : const LinearGradient( - transform: GradientRotation( - .46, - ), - begin: Alignment.topRight, - end: Alignment.bottomLeft, - colors: [ - MyColors.gradiantEndColor, - MyColors.gradiantStartColor, - ], - ), - borderRadius: BorderRadius.circular( - 10, - ), - ), - child: Padding( - padding: EdgeInsets.only( - top: isReplied ? 8 : 5, - right: 8, - left: 8, - bottom: 5, - ), - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisAlignment: MainAxisAlignment.start, - children: [ - if (isReplied) - ClipRRect( - borderRadius: BorderRadius.circular( - 5.0, - ), - child: Container( - decoration: BoxDecoration( - border: Border( - left: BorderSide( - width: 6, - color: isCurrentUser ? MyColors.gradiantStartColor : MyColors.white, - ), - ), - color: isCurrentUser ? MyColors.black.withOpacity(0.10) : MyColors.black.withOpacity(0.30), - ), - child: Row( - children: [ - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - (userName) - .toText12( - color: MyColors.gradiantStartColor, - isBold: false, - ) - .paddingOnly( - right: 5, - top: 5, - bottom: 0, - left: 5, - ), - replyText - .toText10( - color: isCurrentUser ? MyColors.grey71Color : MyColors.white.withOpacity(0.5), - isBold: false, - maxlines: 4, - ) - .paddingOnly( - right: 5, - top: 5, - bottom: 8, - left: 5, - ), - ], - ), - ), - ], - ), - ), - ), - if (isReplied) 8.height, - text.toText12( - color: isCurrentUser ? MyColors.grey57Color : MyColors.white, - ), - Row( - crossAxisAlignment: CrossAxisAlignment.end, - mainAxisAlignment: MainAxisAlignment.end, - children: [ - dateTime.toText12( - color: isCurrentUser ? MyColors.grey41Color.withOpacity(.5) : MyColors.white.withOpacity(0.7), - ), - if (isCurrentUser) 5.width, - if (isCurrentUser) - Icon( - isDelivered ? Icons.done_all : Icons.done_all, - color: isSeen ? MyColors.textMixColor : MyColors.grey9DColor, - size: 14, - ), - ], - ), - ], - ), - ), - ), - ), - ); } Widget currentUser(context) { return Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - (text).toText12(), + if (isReplied) + ClipRRect( + borderRadius: BorderRadius.circular(5.0), + child: Container( + width: double.infinity, + decoration: BoxDecoration( + border: Border( + left: BorderSide(width: 6, color: isCurrentUser ? MyColors.gradiantStartColor : MyColors.white), + ), + color: isCurrentUser ? MyColors.black.withOpacity(0.10) : MyColors.black.withOpacity(0.30), + ), + child: Row( + children: [ + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + (userName).toText12(color: MyColors.gradiantStartColor, isBold: false).paddingOnly(right: 5, top: 5, bottom: 0, left: 5), + (cItem.userChatReplyResponse != null ? cItem.userChatReplyResponse!.contant.toString() : "") + .toText10(color: isCurrentUser ? MyColors.grey71Color : MyColors.white.withOpacity(0.5), isBold: false, maxlines: 4) + .paddingOnly(right: 5, top: 5, bottom: 8, left: 5), + ], + ).expanded, + if (cItem.userChatReplyResponse != null && cItem.userChatReplyResponse!.fileTypeId == 12 || + cItem.userChatReplyResponse!.fileTypeId == 3 || + cItem.userChatReplyResponse!.fileTypeId == 4) + // Container( + // padding: EdgeInsets.all(0), // Border width + // decoration: BoxDecoration(color: Colors.red, borderRadius: const BorderRadius.all(Radius.circular(8))), + // child: ClipRRect( + // borderRadius: const BorderRadius.all( + // Radius.circular(8), + // ), + // child: SizedBox.fromSize( + // size: Size.fromRadius(8), // Image radius + // child: showImage( + // isReplyPreview: true, + // fileName: cItem.userChatReplyResponse!.contant!, + // fileTypeDescription: cItem.userChatReplyResponse!.fileTypeResponse!.fileTypeDescription ?? "image/jpg"), + // ), + // ), + // ), + ClipRRect( + borderRadius: BorderRadius.circular(8.0), + child: SizedBox( + height: 32, + width: 32, + child: showImage( + isReplyPreview: true, + fileName: cItem.userChatReplyResponse!.contant!, + fileTypeDescription: cItem.userChatReplyResponse!.fileTypeResponse!.fileTypeDescription ?? "image/jpg") + .paddingOnly(left: 10, right: 10, bottom: 16, top: 16), + ), + ), + ], + ), + ), + ).paddingOnly(right: 5, bottom: 7), + if (fileTypeID == 12 || fileTypeID == 4 || fileTypeID == 3) + showImage(isReplyPreview: false, fileName: cItem.contant!, fileTypeDescription: cItem.fileTypeResponse!.fileTypeDescription).paddingOnly(right: 5).onPress(() { + showDialog( + context: context, + anchorPoint: screenOffset, + builder: (BuildContext context) => ChatImagePreviewScreen(imgTitle: cItem.contant!, img: cItem.image!), + ); + }), + cItem.contant!.toText12(), Align( alignment: Alignment.centerRight, child: Row( mainAxisSize: MainAxisSize.min, children: [ - dateTime.toText10(color: MyColors.grey41Color.withOpacity(.5)), - 7.width, - Icon( - isDelivered ? Icons.done_all : Icons.done_all, - color: isSeen ? MyColors.textMixColor : MyColors.grey9DColor, - size: 14, + dateTime.toText10( + color: MyColors.grey41Color.withOpacity(.5), ), + 7.width, + Icon(isDelivered ? Icons.done_all : Icons.done_all, color: isSeen ? MyColors.textMixColor : MyColors.grey9DColor, size: 14), ], ), ), @@ -175,7 +135,7 @@ class ChatBubble extends StatelessWidget { ).paddingOnly(top: 11, left: 13, right: 7, bottom: 5).objectContainerView(disablePadding: true).paddingOnly(left: MediaQuery.of(context).size.width * 0.3); } - Widget receiptUser(context) { + Widget receiptUser(BuildContext context) { return Container( padding: const EdgeInsets.only(top: 11, left: 13, right: 7, bottom: 5), decoration: BoxDecoration( @@ -193,15 +153,97 @@ class ChatBubble extends StatelessWidget { child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - (text).toText12(color: Colors.white), + if (isReplied) + ClipRRect( + borderRadius: BorderRadius.circular(5.0), + child: Container( + width: double.infinity, + decoration: BoxDecoration( + border: Border(left: BorderSide(width: 6, color: isCurrentUser ? MyColors.gradiantStartColor : MyColors.white)), + color: isCurrentUser ? MyColors.black.withOpacity(0.10) : MyColors.black.withOpacity(0.30), + ), + child: Row( + children: [ + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + (userName).toText12(color: MyColors.gradiantStartColor, isBold: false).paddingOnly(right: 5, top: 5, bottom: 0, left: 5), + (cItem.userChatReplyResponse != null ? cItem.userChatReplyResponse!.contant.toString() : "") + .toText10(color: isCurrentUser ? MyColors.grey71Color : MyColors.white.withOpacity(0.5), isBold: false, maxlines: 4) + .paddingOnly(right: 5, top: 5, bottom: 8, left: 5), + ], + ).expanded, + if (cItem.userChatReplyResponse != null && cItem.userChatReplyResponse!.fileTypeId == 12 || + cItem.userChatReplyResponse!.fileTypeId == 3 || + cItem.userChatReplyResponse!.fileTypeId == 4) + ClipRRect( + borderRadius: BorderRadius.circular(8.0), + child: SizedBox( + height: 32, + width: 32, + child: showImage( + isReplyPreview: true, + fileName: cItem.userChatReplyResponse!.contant!, + fileTypeDescription: cItem.userChatReplyResponse!.fileTypeResponse!.fileTypeDescription ?? "image/jpg"), + ), + ).paddingOnly(left: 10, right: 10, bottom: 16, top: 16) + ], + ), + ), + ).paddingOnly(right: 5, bottom: 7), + if (fileTypeID == 12 || fileTypeID == 4 || fileTypeID == 3) + showImage(isReplyPreview: false, fileName: cItem.contant ?? "", fileTypeDescription: cItem.fileTypeResponse!.fileTypeDescription ?? "image/jpg").paddingOnly(right: 5).onPress(() { + showDialog( + context: context, + anchorPoint: screenOffset, + builder: (BuildContext context) => ChatImagePreviewScreen(imgTitle: cItem.contant ?? "", img: cItem.image!), + ); + }) + else + (cItem.contant ?? "").toText12(color: Colors.white), Align( alignment: Alignment.centerRight, - child: dateTime.toText10( - color: Colors.white.withOpacity(.71), - ), + child: dateTime.toText10(color: Colors.white.withOpacity(.71)), ), ], ), ).paddingOnly(right: MediaQuery.of(context).size.width * 0.3); } + + Widget showImage({required bool isReplyPreview, required String fileName, required String fileTypeDescription}) { + if (cItem.isImageLoaded! && cItem.image != null) { + return Image.memory( + cItem.image!, + height: isReplyPreview ? 32 : 140, + width: isReplyPreview ? 32 : 227, + fit: BoxFit.cover, + ); + } else { + return FutureBuilder( + future: ChatApiClient().downloadURL(fileName: fileName, fileTypeDescription: fileTypeDescription), + builder: (BuildContext context, AsyncSnapshot snapshot) { + if (snapshot.connectionState != ConnectionState.waiting) { + if (snapshot.data == null) { + return SizedBox(); + } else { + cItem.image = snapshot.data; + cItem.isImageLoaded = true; + return Image.memory( + snapshot.data, + height: isReplyPreview ? 32 : 140, + width: isReplyPreview ? 32 : 227, + fit: BoxFit.cover, + ); + } + } else { + return SizedBox( + height: isReplyPreview ? 32 : 140, + width: isReplyPreview ? 32 : 227, + child: const Center(child: CircularProgressIndicator()), + ); + } + }, + ); + } + } } diff --git a/lib/ui/chat/chat_detailed_screen.dart b/lib/ui/chat/chat_detailed_screen.dart index 00bb43b..f027915 100644 --- a/lib/ui/chat/chat_detailed_screen.dart +++ b/lib/ui/chat/chat_detailed_screen.dart @@ -1,4 +1,5 @@ import 'dart:async'; +import 'dart:convert'; import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; @@ -9,7 +10,9 @@ import 'package:mohem_flutter_app/extensions/int_extensions.dart'; import 'package:mohem_flutter_app/extensions/string_extensions.dart'; import 'package:mohem_flutter_app/extensions/widget_extensions.dart'; import 'package:mohem_flutter_app/generated/locale_keys.g.dart'; +import 'package:mohem_flutter_app/main.dart'; import 'package:mohem_flutter_app/models/chat/call.dart'; +import 'package:mohem_flutter_app/models/chat/get_single_user_chat_list_model.dart'; import 'package:mohem_flutter_app/provider/chat_provider_model.dart'; import 'package:mohem_flutter_app/ui/chat/call/chat_outgoing_call_screen.dart'; import 'package:mohem_flutter_app/ui/chat/chat_bubble.dart'; @@ -19,6 +22,7 @@ import 'package:mohem_flutter_app/widgets/shimmer/dashboard_shimmer_widget.dart' import 'package:provider/provider.dart'; import 'package:pull_to_refresh/pull_to_refresh.dart'; import 'package:signalr_netcore/signalr_client.dart'; +import 'package:sizer/sizer.dart'; import 'package:swipe_to/swipe_to.dart'; class ChatDetailScreen extends StatefulWidget { @@ -71,27 +75,24 @@ class _ChatDetailScreenState extends State { context, title: userDetails["targetUser"].userName.toString().replaceAll(".", " ").capitalizeFirstofEach, showHomeButton: false, - image: userDetails["targetUser"].image, + image: userDetails["targetUser"].image == null || userDetails["targetUser"].image.isEmpty ? null : userDetails["targetUser"].image, actions: [ - IconButton( - onPressed: () { - makeCall(callType: "AUDIO", con: hubConnection); - }, - icon: SvgPicture.asset("assets/icons/chat/call.svg", width: 22, height: 22), - ), - IconButton( - onPressed: () { - makeCall(callType: "VIDEO", con: hubConnection); - }, - icon: SvgPicture.asset("assets/icons/chat/video_call.svg", width: 20, height: 20), - ), - 10.width, + SvgPicture.asset("assets/icons/chat/call.svg", width: 21, height: 23).onPress(() { + // makeCall(callType: "AUDIO", con: hubConnection); + }), + 24.width, + SvgPicture.asset("assets/icons/chat/video_call.svg", width: 21, height: 18).onPress(() { + // makeCall(callType: "VIDEO", con: hubConnection); + }), + 21.width, ], ), body: Consumer( builder: (BuildContext context, ChatProviderModel m, Widget? child) { return (m.isLoading - ? ChatHomeShimmer() + ? ChatHomeShimmer( + isDetailedScreen: true, + ) : Column( children: [ SmartRefresher( @@ -117,21 +118,17 @@ class _ChatDetailScreenState extends State { return SwipeTo( iconColor: MyColors.lightGreenColor, child: ChatBubble( - text: m.userChatHistory[i].contant.toString(), - replyText: m.userChatHistory[i].userChatReplyResponse != null ? m.userChatHistory[i].userChatReplyResponse!.contant.toString() : "", - isSeen: m.userChatHistory[i].isSeen == true ? true : false, - isCurrentUser: m.userChatHistory[i].currentUserId == AppState().chatDetails!.response!.id ? true : false, - isDelivered: m.userChatHistory[i].currentUserId == AppState().chatDetails!.response!.id && m.userChatHistory[i].isDelivered == true ? true : false, dateTime: m.dateFormte(m.userChatHistory[i].createdDate!), - isReplied: m.userChatHistory[i].userChatReplyResponse != null ? true : false, - userName: AppState().chatDetails!.response!.userName == m.userChatHistory[i].currentUserName.toString() ? "You" : m.userChatHistory[i].currentUserName.toString(), + cItem: m.userChatHistory[i], ), onRightSwipe: () { m.chatReply( m.userChatHistory[i], ); }, - ); + ).onPress(() { + logger.d(jsonEncode(m.userChatHistory[i])); + }); }, ), ).expanded, @@ -157,6 +154,8 @@ class _ChatDetailScreenState extends State { ], ).expanded, 12.width, + if (m.isMsgReply && m.repliedMsg.isNotEmpty) showReplyImage(m.repliedMsg), + 12.width, const Icon(Icons.cancel, size: 23, color: MyColors.grey7BColor).onPress(m.closeMe), ], ), @@ -176,63 +175,43 @@ class _ChatDetailScreenState extends State { enabledBorder: InputBorder.none, errorBorder: InputBorder.none, disabledBorder: InputBorder.none, - contentPadding: EdgeInsets.only(left: m.sFileType.isNotEmpty ? 10 : 20, right: m.sFileType.isNotEmpty ? 0 : 5, top: 20, bottom: 20), - prefixIconConstraints: BoxConstraints(), - prefixIcon: m.sFileType.isNotEmpty ? SvgPicture.asset(m.getType(m.sFileType), height: 30, width: 22, alignment: Alignment.center, fit: BoxFit.cover) : null, + filled: true, + fillColor: MyColors.white, + contentPadding: const EdgeInsets.only( + left: 21, + top: 20, + bottom: 20, + ), + prefixIconConstraints: const BoxConstraints(), + prefixIcon: m.sFileType.isNotEmpty + ? SvgPicture.asset(m.getType(m.sFileType), height: 30, width: 22, alignment: Alignment.center, fit: BoxFit.cover).paddingOnly(left: 21, right: 15) + : null, suffixIcon: SizedBox( - width: 96, + width: 100, child: Row( mainAxisAlignment: MainAxisAlignment.end, crossAxisAlignment: CrossAxisAlignment.center, // added line children: [ if (m.sFileType.isNotEmpty) - IconButton( - padding: EdgeInsets.zero, - alignment: Alignment.centerRight, - icon: Row( - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisAlignment: MainAxisAlignment.end, - mainAxisSize: MainAxisSize.max, - children: [ - Container( - decoration: const BoxDecoration( - color: MyColors.redA3Color, - borderRadius: BorderRadius.all( - Radius.circular(20), - ), - ), - child: const Icon(Icons.close, size: 15, color: MyColors.white), - ), - ("Clear").toText11(color: MyColors.redA3Color).paddingOnly(left: 4), - ], - ), - onPressed: () async { - m.removeAttachment(); - }, - ), + Row( + children: [ + const Icon(Icons.cancel, size: 15, color: MyColors.redA3Color).paddingOnly(right: 5), + ("Clear").toText11(color: MyColors.redA3Color, isUnderLine: true).paddingOnly(left: 0), + ], + ).onPress(() => m.removeAttachment()).paddingOnly(right: 25), if (m.sFileType.isEmpty) RotationTransition( turns: const AlwaysStoppedAnimation(45 / 360), - child: IconButton( - padding: EdgeInsets.zero, - alignment: Alignment.topRight, - icon: const Icon(Icons.attach_file_rounded, size: 26, color: MyColors.grey3AColor), - onPressed: () async { - m.selectImageToUpload(context); - }, + child: const Icon(Icons.attach_file_rounded, size: 26, color: MyColors.grey3AColor).onPress( + () => m.selectImageToUpload(context), ), - ), - IconButton( - alignment: Alignment.centerRight, - padding: EdgeInsets.zero, - icon: SvgPicture.asset("assets/icons/chat/chat_send_icon.svg", height: 26, width: 26), - onPressed: () { - m.sendChatMessage(userDetails["targetUser"].id, userDetails["targetUser"].userName, context); - }, - ) + ).paddingOnly(right: 25), + SvgPicture.asset("assets/icons/chat/chat_send_icon.svg", height: 26, width: 26).onPress( + () => m.sendChatMessage(userDetails["targetUser"].id, userDetails["targetUser"].userName, context), + ), ], ), - ).paddingOnly(right: 20), + ).paddingOnly(right: 21), ), ), ], @@ -242,6 +221,19 @@ class _ChatDetailScreenState extends State { ); } + Widget showReplyImage(List data) { + if (data.first.isImageLoaded! && data.first.image != null) { + return Container( + width: 43, + height: 43, + decoration: BoxDecoration( + border: Border.all(color: MyColors.darkGrey3BColor, width: 1), borderRadius: BorderRadius.circular(10.0), image: DecorationImage(image: MemoryImage(data.first.image!), fit: BoxFit.cover)), + ); + } else { + return const SizedBox(); + } + } + void makeCall({required String callType, required HubConnection con}) async { print("================== Make call Triggered ============================"); Map json = { diff --git a/lib/ui/chat/chat_full_image_preview.dart b/lib/ui/chat/chat_full_image_preview.dart new file mode 100644 index 0000000..32e2760 --- /dev/null +++ b/lib/ui/chat/chat_full_image_preview.dart @@ -0,0 +1,50 @@ +import 'dart:typed_data'; + +import 'package:flutter/material.dart'; +import 'package:mohem_flutter_app/classes/colors.dart'; +import 'package:mohem_flutter_app/extensions/widget_extensions.dart'; + +class ChatImagePreviewScreen extends StatelessWidget { + const ChatImagePreviewScreen({Key? key, required this.imgTitle, required this.img}) : super(key: key); + + final String imgTitle; + final Uint8List img; + + @override + Widget build(BuildContext context) { + return Dialog( + backgroundColor: Colors.transparent, + insetPadding: const EdgeInsets.all(10), + child: Stack( + alignment: Alignment.center, + fit: StackFit.loose, + children: [ + Image.memory( + img, + fit: BoxFit.fill, + ).paddingAll(15), + Positioned( + right: 0, + top: 0, + child: Container( + width: 30, + height: 30, + alignment: Alignment.center, + padding: EdgeInsets.zero, + margin: EdgeInsets.zero, + constraints: const BoxConstraints(), + color: MyColors.white, + child: const Icon( + Icons.cancel, + color: MyColors.redA3Color, + size: 30, + ), + ).onPress(() { + Navigator.of(context).pop(); + }).circle(35), + ) + ], + ), + ); + } +} diff --git a/lib/ui/chat/chat_home.dart b/lib/ui/chat/chat_home.dart index 3bf8cda..4e218e3 100644 --- a/lib/ui/chat/chat_home.dart +++ b/lib/ui/chat/chat_home.dart @@ -8,8 +8,10 @@ import 'package:mohem_flutter_app/generated/locale_keys.g.dart'; import 'package:mohem_flutter_app/provider/chat_provider_model.dart'; import 'package:mohem_flutter_app/ui/chat/chat_home_screen.dart'; import 'package:mohem_flutter_app/ui/chat/favorite_users_screen.dart'; +import 'package:mohem_flutter_app/ui/landing/dashboard_screen.dart'; import 'package:mohem_flutter_app/widgets/app_bar_widget.dart'; import 'package:provider/provider.dart'; +import 'package:signalr_netcore/signalr_client.dart'; class ChatHome extends StatefulWidget { const ChatHome({Key? key}) : super(key: key); @@ -27,6 +29,17 @@ class _ChatHomeState extends State { void initState() { super.initState(); data = Provider.of(context, listen: false); + data.registerEvents(); + if (chatHubConnection.state != HubConnectionState.Connected) { + data.getUserAutoLoginToken().whenComplete(() async { + await data.buildHubConnection(); + data.getUserRecentChats(); + }); + return; + } + if (data.searchedChats == null || data.searchedChats!.isEmpty) { + data.getUserRecentChats(); + } } @override diff --git a/lib/ui/chat/chat_home_screen.dart b/lib/ui/chat/chat_home_screen.dart index 56c17d8..641c13d 100644 --- a/lib/ui/chat/chat_home_screen.dart +++ b/lib/ui/chat/chat_home_screen.dart @@ -1,9 +1,14 @@ +import 'dart:convert'; +import 'dart:typed_data'; import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; +import 'package:flutter_des/flutter_des.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'package:mohem_flutter_app/app_state/app_state.dart'; import 'package:mohem_flutter_app/classes/colors.dart'; +import 'package:mohem_flutter_app/classes/encryption.dart'; import 'package:mohem_flutter_app/config/routes.dart'; import 'package:mohem_flutter_app/extensions/string_extensions.dart'; import 'package:mohem_flutter_app/extensions/widget_extensions.dart'; @@ -11,10 +16,13 @@ import 'package:mohem_flutter_app/generated/locale_keys.g.dart'; import 'package:mohem_flutter_app/provider/chat_provider_model.dart'; import 'package:mohem_flutter_app/widgets/bottom_sheet.dart'; import 'package:mohem_flutter_app/widgets/bottom_sheets/search_employee_bottom_sheet.dart'; +import 'package:mohem_flutter_app/widgets/circular_avatar.dart'; import 'package:mohem_flutter_app/widgets/shimmer/dashboard_shimmer_widget.dart'; import 'package:provider/provider.dart'; class ChatHomeScreen extends StatefulWidget { + const ChatHomeScreen({Key? key}) : super(key: key); + @override State createState() => _ChatHomeScreenState(); } @@ -25,11 +33,8 @@ class _ChatHomeScreenState extends State { @override void initState() { - // TODO: implement initState super.initState(); data = Provider.of(context, listen: false); - data.registerEvents(); - data.getUserRecentChats(); } @override @@ -45,106 +50,99 @@ class _ChatHomeScreenState extends State { body: Consumer( builder: (BuildContext context, ChatProviderModel m, Widget? child) { return m.isLoading - ? ChatHomeShimmer() - : ListView( - shrinkWrap: true, - physics: const AlwaysScrollableScrollPhysics(), + ? ChatHomeShimmer(isDetailedScreen: false,) + : Column( children: [ - Padding( - padding: const EdgeInsets.symmetric(vertical: 20, horizontal: 20), - child: TextField( - controller: m.search, - style: const TextStyle(color: MyColors.darkTextColor, fontWeight: FontWeight.w500, fontSize: 12), - onChanged: (String val) { - m.filter(val); - }, - decoration: InputDecoration( - border: fieldBorder(radius: 5, color: 0xFFE5E5E5), - focusedBorder: fieldBorder(radius: 5, color: 0xFFE5E5E5), - enabledBorder: fieldBorder(radius: 5, color: 0xFFE5E5E5), - contentPadding: const EdgeInsets.all(11), - hintText: LocaleKeys.searchfromchat.tr(), - hintStyle: const TextStyle(color: MyColors.lightTextColor, fontStyle: FontStyle.italic, fontWeight: FontWeight.w500, fontSize: 12), - filled: true, - fillColor: const Color(0xFFF7F7F7), - suffixIconConstraints: const BoxConstraints(), - suffixIcon: m.search.text.isNotEmpty - ? IconButton( - constraints: const BoxConstraints(), - onPressed: () { - m.clearSelections(); - }, - icon: const Icon(Icons.clear, size: 22), - color: MyColors.redA3Color, - ) - : null, - ), + TextField( + controller: m.search, + style: const TextStyle(color: MyColors.darkTextColor, fontWeight: FontWeight.w500, fontSize: 12), + onChanged: (String val) { + m.filter(val); + }, + decoration: InputDecoration( + border: fieldBorder(radius: 5, color: 0xFFE5E5E5), + focusedBorder: fieldBorder(radius: 5, color: 0xFFE5E5E5), + enabledBorder: fieldBorder(radius: 5, color: 0xFFE5E5E5), + contentPadding: const EdgeInsets.all(11), + hintText: LocaleKeys.searchfromchat.tr(), + hintStyle: const TextStyle(color: MyColors.lightTextColor, fontStyle: FontStyle.italic, fontWeight: FontWeight.w500, fontSize: 12), + filled: true, + fillColor: MyColors.greyF7Color, + suffixIconConstraints: const BoxConstraints(), + suffixIcon: m.search.text.isNotEmpty + ? IconButton( + constraints: const BoxConstraints(), + onPressed: () { + m.clearSelections(); + }, + icon: const Icon(Icons.clear, size: 22), + color: MyColors.redA3Color, + ) + : null, ), - ), + ).paddingOnly(top: 20, bottom: 14), if (m.searchedChats != null) ListView.separated( itemCount: m.searchedChats!.length, - padding: const EdgeInsets.only(bottom: 80), shrinkWrap: true, - physics: const NeverScrollableScrollPhysics(), + physics: const ClampingScrollPhysics(), + padding: const EdgeInsets.only(bottom: 80.0), itemBuilder: (BuildContext context, int index) { return SizedBox( height: 55, - // todo @aamir, remove list tile, make a custom ui instead - child: ListTile( - leading: Stack( - children: [ - SvgPicture.asset( - "assets/images/user.svg", - height: 48, - width: 48, - ), - Positioned( - right: 5, - bottom: 1, - child: Container( - width: 10, - height: 10, - decoration: BoxDecoration( - color: m.searchedChats![index].userStatus == 1 ? MyColors.green2DColor : Colors.red, - borderRadius: const BorderRadius.all( - Radius.circular(10), - ), - ), - ), - ) - ], - ), - title: (m.searchedChats![index].userName!.replaceFirst(".", " ").capitalizeFirstofEach ?? "").toText14(color: MyColors.darkTextColor), - // subtitle: (m.searchedChats![index].isTyping == true ? "Typing ..." : "").toText11(color: MyColors.normalTextColor), - trailing: SizedBox( - width: 60, - child: Row( - crossAxisAlignment: CrossAxisAlignment.center, - mainAxisAlignment: MainAxisAlignment.end, - mainAxisSize: MainAxisSize.max, + child: Row( + children: [ + Stack( children: [ - // if (m.searchedChats![index].isLoadingCounter!) - // Flexible( - // child: Container( - // padding: EdgeInsets.zero, - // alignment: Alignment.centerRight, - // width: 18, - // height: 18, - // decoration: const BoxDecoration( - // // color: MyColors.redColor, - // borderRadius: BorderRadius.all( - // Radius.circular(20), - // ), - // ), - // child: CircularProgressIndicator(), - // ), - // ), - if (m.searchedChats![index].unreadMessageCount! > 0) - Flexible( - child: Container( - padding: EdgeInsets.zero, - alignment: Alignment.centerRight, + if (m.searchedChats![index].isImageLoading!) + const SizedBox( + height: 48, + width: 48, + ).toShimmer().circle(30), + if (m.searchedChats![index].isImageLoaded! && m.searchedChats![index].image != null && m.searchedChats![index].image.isNotEmpty) + CircularAvatar( + radius: 20, + height: 48, + width: 48, + url: m.searchedChats![index].image, + isImageBase64: true, + ), + if (!m.searchedChats![index].isImageLoading! && m.searchedChats![index].isImageLoaded! && m.searchedChats![index].image.isEmpty) + SvgPicture.asset( + "assets/images/user.svg", + height: 48, + width: 48, + ), + Positioned( + right: 5, + bottom: 1, + child: Container( + width: 10, + height: 10, + decoration: BoxDecoration( + color: m.searchedChats![index].userStatus == 1 ? MyColors.green2DColor : Colors.red, + ), + ).circle(10), + ) + ], + ), + Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + (m.searchedChats![index].userName!.replaceFirst(".", " ").capitalizeFirstofEach ?? "").toText14(color: MyColors.darkTextColor).paddingOnly(left: 11, top: 13), + ], + ).expanded, + SizedBox( + width: 60, + child: Row( + crossAxisAlignment: CrossAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.end, + mainAxisSize: MainAxisSize.max, + children: [ + if (m.searchedChats![index].unreadMessageCount! > 0) + Container( + alignment: Alignment.center, width: 18, height: 18, decoration: const BoxDecoration( @@ -158,17 +156,12 @@ class _ChatHomeScreenState extends State { color: MyColors.white, ) .center, - ), - ), - Flexible( - child: IconButton( - alignment: Alignment.centerRight, - padding: EdgeInsets.zero, - icon: Icon( - m.searchedChats![index].isFav != null && m.searchedChats![index].isFav == false ? Icons.star_sharp : Icons.star_sharp, - ), + ).paddingOnly(right: 10).center, + Icon( + m.searchedChats![index].isFav != null && m.searchedChats![index].isFav == false ? Icons.star_sharp : Icons.star_sharp, color: m.searchedChats![index].isFav != null && m.searchedChats![index].isFav == true ? MyColors.yellowColor : MyColors.grey35Color, - onPressed: () { + ).onPress( + () { if (m.searchedChats![index].isFav == null || m.searchedChats![index].isFav == false) { m.favoriteUser( userID: AppState().chatDetails!.response!.id!, @@ -186,40 +179,27 @@ class _ChatHomeScreenState extends State { ); } }, - ), - ) - ], + ).center + ], + ), ), - ), - minVerticalPadding: 0, - onTap: () { - Navigator.pushNamed( - context, - AppRoutes.chatDetailed, - arguments: {"targetUser": m.searchedChats![index], "isNewChat": false}, - ).then((Object? value) { - // m.GetUserChatHistoryNotDeliveredAsync(userId: int.parse(AppState().chatDetails!.response!.id.toString())); - m.clearSelections(); - m.notifyListeners(); - }); - }, + ], ), - ); + ).onPress(() { + Navigator.pushNamed( + context, + AppRoutes.chatDetailed, + arguments: {"targetUser": m.searchedChats![index], "isNewChat": false}, + ).then((Object? value) { + m.clearSelections(); + m.notifyListeners(); + }); + }); }, - separatorBuilder: (BuildContext context, int index) => const Padding( - padding: EdgeInsets.only( - right: 10, - left: 70, - ), - child: Divider( - color: Color( - 0xFFE5E5E5, - ), - ), - ), - ), + separatorBuilder: (BuildContext context, int index) => const Divider(color: MyColors.lightGreyE5Color).paddingOnly(left: 59), + ).expanded, ], - ); + ).paddingOnly(left: 21, right: 21); }, ), floatingActionButton: FloatingActionButton( @@ -262,13 +242,9 @@ class _ChatHomeScreenState extends State { OutlineInputBorder fieldBorder({required double radius, required int color}) { return OutlineInputBorder( - borderRadius: BorderRadius.circular( - radius, - ), + borderRadius: BorderRadius.circular(radius), borderSide: BorderSide( - color: Color( - color, - ), + color: Color(color), ), ); } diff --git a/lib/ui/chat/favorite_users_screen.dart b/lib/ui/chat/favorite_users_screen.dart index 8f303cd..6034151 100644 --- a/lib/ui/chat/favorite_users_screen.dart +++ b/lib/ui/chat/favorite_users_screen.dart @@ -1,6 +1,7 @@ import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter_svg/flutter_svg.dart'; +import 'package:mohem_flutter_app/main.dart'; import 'package:mohem_flutter_app/provider/chat_provider_model.dart'; import 'package:mohem_flutter_app/app_state/app_state.dart'; import 'package:mohem_flutter_app/classes/colors.dart'; @@ -8,6 +9,7 @@ import 'package:mohem_flutter_app/classes/utils.dart'; import 'package:mohem_flutter_app/config/routes.dart'; import 'package:mohem_flutter_app/extensions/string_extensions.dart'; import 'package:mohem_flutter_app/extensions/widget_extensions.dart'; +import 'package:mohem_flutter_app/widgets/circular_avatar.dart'; import 'package:mohem_flutter_app/widgets/shimmer/dashboard_shimmer_widget.dart'; import 'package:provider/provider.dart'; @@ -21,86 +23,96 @@ class ChatFavoriteUsersScreen extends StatelessWidget { body: Consumer( builder: (BuildContext context, ChatProviderModel m, Widget? child) { if (m.isLoading) { - return ChatHomeShimmer(); + return ChatHomeShimmer(isDetailedScreen: false,); } else { return m.favUsersList != null && m.favUsersList.isNotEmpty ? ListView.separated( itemCount: m.favUsersList!.length, - padding: const EdgeInsets.only(top: 20), shrinkWrap: true, physics: const NeverScrollableScrollPhysics(), itemBuilder: (BuildContext context, int index) { return SizedBox( height: 55, - child: ListTile( - leading: Stack( - children: [ - SvgPicture.asset( - "assets/images/user.svg", - height: 48, - width: 48, - ), - Positioned( - right: 5, - bottom: 1, - child: Container( - width: 10, - height: 10, - decoration: BoxDecoration( - color: m.favUsersList![index].userStatus == 1 ? MyColors.green2DColor : Colors.red, - borderRadius: const BorderRadius.all( - Radius.circular(10), - ), + child: Row( + children: [ + Stack( + children: [ + if (m.favUsersList![index].isImageLoading!) + const SizedBox( + height: 48, + width: 48, + ).toShimmer().circle(30), + if (m.favUsersList![index].isImageLoaded! && m.favUsersList![index].image != null && m.favUsersList![index].image.isNotEmpty) + CircularAvatar( + radius: 20, + height: 48, + width: 48, + url: m.favUsersList![index].image, + isImageBase64: true, + ), + if (!m.favUsersList![index].isImageLoading! && m.favUsersList![index].isImageLoaded! && m.favUsersList![index].image.isEmpty) + SvgPicture.asset( + "assets/images/user.svg", + height: 48, + width: 48, ), - ), - ) - ], - ), - title: (m.favUsersList![index].userName!.replaceFirst(".", " ").capitalizeFirstofEach ?? "").toText14( - color: MyColors.darkTextColor, - ), - trailing: IconButton( - alignment: Alignment.centerRight, - padding: EdgeInsets.zero, - icon: Icon( - m.favUsersList![index].isFav! ? Icons.star : Icons.star_border, + Positioned( + right: 5, + bottom: 1, + child: Container( + width: 10, + height: 10, + decoration: BoxDecoration( + color: m.favUsersList![index].userStatus == 1 ? MyColors.green2DColor : Colors.red, + ), + ).circle(10), + ) + ], ), - color: m.favUsersList![index].isFav! ? MyColors.yellowColor : MyColors.grey35Color, - onPressed: () { - if (m.favUsersList![index].isFav!) - m.unFavoriteUser( - userID: AppState().chatDetails!.response!.id!, - targetUserID: m.favUsersList![index].id!, - ); - }, - ), - minVerticalPadding: 0, - onTap: () { - Navigator.pushNamed( - context, - AppRoutes.chatDetailed, - arguments: {"targetUser": m.favUsersList![index], "isNewChat": false}, - ).then( - (Object? value) { - m.clearSelections(); - }, - ); - }, + Column( + mainAxisAlignment: MainAxisAlignment.start, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + (m.favUsersList![index].userName!.replaceFirst(".", " ").capitalizeFirstofEach ?? "").toText14(color: MyColors.darkTextColor).paddingOnly(left: 11, top: 13), + ], + ).expanded, + SizedBox( + width: 60, + child: Row( + crossAxisAlignment: CrossAxisAlignment.center, + mainAxisAlignment: MainAxisAlignment.end, + mainAxisSize: MainAxisSize.max, + children: [ + Icon( + m.favUsersList![index].isFav! ? Icons.star : Icons.star_border, + color: m.favUsersList![index].isFav! ? MyColors.yellowColor : MyColors.grey35Color, + ).onPress(() { + if (m.favUsersList![index].isFav!) { + m.unFavoriteUser( + userID: AppState().chatDetails!.response!.id!, + targetUserID: m.favUsersList![index].id!, + ); + } + }).center, + ], + ), + ), + ], ), - ); + ).onPress(() { + Navigator.pushNamed( + context, + AppRoutes.chatDetailed, + arguments: {"targetUser": m.favUsersList![index], "isNewChat": false}, + ).then( + (Object? value) { + m.clearSelections(); + }, + ); + }); }, - separatorBuilder: (BuildContext context, int index) => const Padding( - padding: EdgeInsets.only( - right: 10, - left: 70, - ), - child: Divider( - color: Color( - 0xFFE5E5E5, - ), - ), - ), - ) + separatorBuilder: (BuildContext context, int index) => const Divider(color: MyColors.lightGreyE5Color).paddingOnly(left: 70), + ).paddingAll(21) : Column( children: [ Utils.getNoDataWidget(context).expanded, diff --git a/lib/ui/landing/dashboard_screen.dart b/lib/ui/landing/dashboard_screen.dart index c8cdcef..f06a405 100644 --- a/lib/ui/landing/dashboard_screen.dart +++ b/lib/ui/landing/dashboard_screen.dart @@ -1,7 +1,7 @@ import 'dart:async'; -import 'dart:convert'; import 'dart:io'; +import 'dart:ui' as ui; import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:flutter_countdown_timer/flutter_countdown_timer.dart'; @@ -9,20 +9,19 @@ import 'package:flutter_svg/flutter_svg.dart'; import 'package:mohem_flutter_app/api/dashboard_api_client.dart'; import 'package:mohem_flutter_app/app_state/app_state.dart'; import 'package:mohem_flutter_app/classes/colors.dart'; -import 'package:mohem_flutter_app/classes/consts.dart'; import 'package:mohem_flutter_app/classes/utils.dart'; import 'package:mohem_flutter_app/config/routes.dart'; import 'package:mohem_flutter_app/extensions/int_extensions.dart'; import 'package:mohem_flutter_app/extensions/string_extensions.dart'; import 'package:mohem_flutter_app/extensions/widget_extensions.dart'; import 'package:mohem_flutter_app/generated/locale_keys.g.dart'; -import 'package:mohem_flutter_app/main.dart'; import 'package:mohem_flutter_app/models/offers_and_discounts/get_offers_list.dart'; +import 'package:mohem_flutter_app/provider/chat_provider_model.dart'; import 'package:mohem_flutter_app/provider/dashboard_provider_model.dart'; -import 'package:mohem_flutter_app/ui/landing/itg/its_add_screen_video_image.dart'; import 'package:mohem_flutter_app/ui/landing/widget/app_drawer.dart'; import 'package:mohem_flutter_app/ui/landing/widget/menus_widget.dart'; import 'package:mohem_flutter_app/ui/landing/widget/services_widget.dart'; +import 'package:mohem_flutter_app/ui/marathon/marathon_provider.dart'; import 'package:mohem_flutter_app/ui/marathon/widgets/marathon_banner.dart'; import 'package:mohem_flutter_app/widgets/bottom_sheet.dart'; import 'package:mohem_flutter_app/widgets/mark_attendance_widget.dart'; @@ -32,7 +31,7 @@ import 'package:provider/provider.dart'; import 'package:pull_to_refresh/pull_to_refresh.dart'; import 'package:signalr_netcore/signalr_client.dart'; -late HubConnection hubConnection; +late HubConnection chatHubConnection; class DashboardScreen extends StatefulWidget { DashboardScreen({Key? key}) : super(key: key); @@ -45,6 +44,8 @@ class DashboardScreen extends StatefulWidget { class _DashboardScreenState extends State { late DashboardProviderModel data; + late MarathonProvider marathonProvider; + late ChatProviderModel cProvider; final GlobalKey _scaffoldState = GlobalKey(); final RefreshController _refreshController = RefreshController(initialRefresh: false); @@ -56,25 +57,22 @@ class _DashboardScreenState extends State { super.initState(); scheduleMicrotask(() { data = Provider.of(context, listen: false); + marathonProvider = Provider.of(context, listen: false); + cProvider = Provider.of(context, listen: false); _bHubCon(); _onRefresh(); }); } - void buildHubConnection() async { - hubConnection = await data.getHubConnection(); - await hubConnection.start(); - } - @override void dispose() { super.dispose(); - hubConnection.stop(); + chatHubConnection.stop(); } void _bHubCon() { - data.getUserAutoLoginToken().whenComplete(() { - buildHubConnection(); + cProvider.getUserAutoLoginToken().whenComplete(() { + cProvider.buildHubConnection(); }); } @@ -92,6 +90,7 @@ class _DashboardScreenState extends State { data.fetchLeaveTicketBalance(context, DateTime.now()); data.fetchMenuEntries(); data.getCategoryOffersListAPI(context); + marathonProvider.getMarathonDetailsFromApi(); data.fetchChatCounts(); _refreshController.refreshCompleted(); } @@ -106,22 +105,29 @@ class _DashboardScreenState extends State { // onPressed: () { // data.getITGNotification().then((val) { // if (val!.result!.data != null) { + // print("-------------------- Survey ----------------------------"); // if (val.result!.data!.notificationType == "Survey") { // Navigator.pushNamed(context, AppRoutes.survey, arguments: val.result!.data); // } else { + // print("------------------------------------------- Ads --------------------"); // DashboardApiClient().getAdvertisementDetail(val.result!.data!.notificationMasterId ?? "").then( // (value) { // if (value!.mohemmItgResponseItem!.statusCode == 200) { // if (value.mohemmItgResponseItem!.result!.data != null) { - // Navigator.push( - // context, - // MaterialPageRoute( - // builder: (BuildContext context) => ITGAdsScreen( - // addMasterId: val.result!.data!.notificationMasterId!, - // advertisement: value.mohemmItgResponseItem!.result!.data!.advertisement!, - // ), - // ), - // ); + // Navigator.pushNamed(context, AppRoutes.advertisement, arguments: { + // "masterId": val.result!.data!.notificationMasterId, + // "advertisement": value.mohemmItgResponseItem!.result!.data!.advertisement, + // }); + // + // // Navigator.push( + // // context, + // // MaterialPageRoute( + // // builder: (BuildContext context) => ITGAdsScreen( + // // addMasterId: val.result!.data!.notificationMasterId!, + // // advertisement: value.mohemmItgResponseItem!.result!.data!.advertisement!, + // // ), + // // ), + // // ); // } // } // }, @@ -232,11 +238,14 @@ class _DashboardScreenState extends State { crossAxisAlignment: CrossAxisAlignment.start, children: [ 9.height, - CountdownTimer( - endTime: model.endTime, - onEnd: null, - endWidget: "00:00:00".toText14(color: Colors.white, isBold: true), - textStyle: const TextStyle(color: Colors.white, fontSize: 14, letterSpacing: -0.48, fontWeight: FontWeight.bold), + Directionality( + textDirection: ui.TextDirection.ltr, + child: CountdownTimer( + endTime: model.endTime, + onEnd: null, + endWidget: "00:00:00".toText14(color: Colors.white, isBold: true), + textStyle: const TextStyle(color: Colors.white, fontSize: 14, letterSpacing: -0.48, fontWeight: FontWeight.bold), + ), ), LocaleKeys.timeLeftToday.tr().toText12(color: Colors.white), 9.height, @@ -313,7 +322,7 @@ class _DashboardScreenState extends State { ), ], ).paddingOnly(left: 21, right: 21, top: 7), - const MarathonBanner().paddingAll(20), + context.watch().isLoading ? MarathonBannerShimmer().paddingAll(20) : MarathonBanner().paddingAll(20), ServicesWidget(), // 8.height, Container( @@ -359,7 +368,7 @@ class _DashboardScreenState extends State { ], ).paddingOnly(left: 21, right: 21), Consumer( - builder: (context, model, child) { + builder: (BuildContext context, DashboardProviderModel model, Widget? child) { return SizedBox( height: 103 + 33, child: ListView.separated( diff --git a/lib/ui/landing/itg/its_add_screen_video_image.dart b/lib/ui/landing/itg/its_add_screen_video_image.dart index 4b2e358..bcb9ed4 100644 --- a/lib/ui/landing/itg/its_add_screen_video_image.dart +++ b/lib/ui/landing/itg/its_add_screen_video_image.dart @@ -12,10 +12,7 @@ import 'package:path_provider/path_provider.dart'; import 'package:video_player/video_player.dart'; class ITGAdsScreen extends StatefulWidget { - final String addMasterId; - final ads.Advertisement advertisement; - - const ITGAdsScreen({required this.addMasterId, required this.advertisement}); + const ITGAdsScreen({Key? key}) : super(key: key); @override _ITGAdsScreenState createState() => _ITGAdsScreenState(); @@ -29,10 +26,13 @@ class _ITGAdsScreenState extends State { bool isImage = false; String ext = ''; late File imageFile; + ads.Advertisement? advertisementData; + dynamic data; + String? masterID; void checkFileType() async { - String? rFile = widget.advertisement!.viewAttachFileColl!.first.base64String; - String? rFileExt = widget.advertisement!.viewAttachFileColl!.first.fileName; + String? rFile = advertisementData!.viewAttachFileColl!.first.base64String; + String? rFileExt = advertisementData!.viewAttachFileColl!.first.fileName; ext = "." + rFileExt!.split(".").last.toLowerCase(); if (ext == ".png" || ext == ".jpg" || ext == ".jpeg" || ext == ".gif") { await processImage(rFile!); @@ -42,6 +42,7 @@ class _ITGAdsScreenState extends State { _futureController = createVideoPlayer(rFile!); } setState(() {}); + initTimer(); } Future processImage(String encodedBytes) async { @@ -68,22 +69,14 @@ class _ITGAdsScreenState extends State { await controller.setLooping(false); return controller; } catch (e) { - return new VideoPlayerController.asset("dataSource"); + return VideoPlayerController.asset("dataSource"); } } - @override - void initState() { - checkFileType(); - initTimer(); - super.initState(); - } - void initTimer() { Future.delayed(const Duration(seconds: 5), () { - setState(() { - skip = true; - }); + skip = true; + setState(() {}); }); } @@ -95,29 +88,34 @@ class _ITGAdsScreenState extends State { @override Widget build(BuildContext context) { - double height = MediaQuery.of(context).size.height * .25; + data = ModalRoute.of(context)!.settings.arguments; + if (advertisementData == null) advertisementData = data["advertisement"] as ads.Advertisement; + if (masterID == null) masterID = data["masterId"]; + if (advertisementData != null) { + checkFileType(); + } + // double height = MediaQuery.of(context).size.height * .25; return Scaffold( - body: Column( + body: Stack( children: [ if (isVideo) - SizedBox( - height: MediaQuery.of(context).size.height * .3, - child: FutureBuilder( - future: _futureController, - builder: (BuildContext context, AsyncSnapshot snapshot) { - if (snapshot.connectionState == ConnectionState.done && snapshot.data != null) { - _controller = snapshot.data as VideoPlayerController; - return AspectRatio( + FutureBuilder( + future: _futureController, + builder: (BuildContext context, AsyncSnapshot snapshot) { + if (snapshot.connectionState == ConnectionState.done && snapshot.data != null) { + _controller = snapshot.data as VideoPlayerController; + return Positioned.fill( + child: AspectRatio( aspectRatio: _controller.value.aspectRatio, child: VideoPlayer(_controller), - ); - } else { - return const Center( - child: CircularProgressIndicator(), - ); - } - }, - ), + ), + ); + } else { + return const Center( + child: CircularProgressIndicator(), + ); + } + }, ), if (isImage) Image.file(imageFile), if (skip) diff --git a/lib/ui/landing/today_attendance_screen2.dart b/lib/ui/landing/today_attendance_screen2.dart index ada652c..f0228eb 100644 --- a/lib/ui/landing/today_attendance_screen2.dart +++ b/lib/ui/landing/today_attendance_screen2.dart @@ -99,10 +99,13 @@ class _TodayAttendanceScreenState extends State { child: CountdownTimer( endTime: model.endTime, widgetBuilder: (context, v) { - return AutoSizeText( - getValue(v?.hours) + " : " + getValue(v?.min) + " : " + getValue(v?.sec), - maxLines: 1, - style: const TextStyle(color: Colors.white, fontSize: 42, letterSpacing: -1.92, fontWeight: FontWeight.bold, height: 1), + return Directionality( + textDirection: TextDirection.ltr, + child: AutoSizeText( + getValue(v?.hours) + " : " + getValue(v?.min) + " : " + getValue(v?.sec), + maxLines: 1, + style: const TextStyle(color: Colors.white, fontSize: 42, letterSpacing: -1.92, fontWeight: FontWeight.bold, height: 1), + ), ); }, onEnd: null, @@ -116,7 +119,7 @@ class _TodayAttendanceScreenState extends State { mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, children: [ - LocaleKeys.shiftTime.tr().tr().toTextAuto(color: MyColors.greyACColor, fontSize: 18, maxLine: 1).paddingOnly(left: 21,right: 21), + LocaleKeys.shiftTime.tr().tr().toTextAuto(color: MyColors.greyACColor, fontSize: 18, maxLine: 1).paddingOnly(left: 21, right: 21), (model.attendanceTracking!.pShtName ?? "00:00:00").toString().toTextAuto(color: Colors.white, isBold: true, fontSize: 26, maxLine: 1), ], ), diff --git a/lib/ui/landing/widget/app_drawer.dart b/lib/ui/landing/widget/app_drawer.dart index ac70035..4160fde 100644 --- a/lib/ui/landing/widget/app_drawer.dart +++ b/lib/ui/landing/widget/app_drawer.dart @@ -69,28 +69,28 @@ class _AppDrawerState extends State { ).expanded ], ).paddingOnly(left: 14, right: 14, top: 21, bottom: 21), - Row( - children: [ - Row( - children: [ - LocaleKeys.english.tr().toText14(color: AppState().isArabic(context) ? null : MyColors.textMixColor).onPress(() { - context.setLocale(const Locale("en", "US")); - postLanguageChange(context); - }), - Container( - width: 1, - color: MyColors.darkWhiteColor, - height: 16, - margin: const EdgeInsets.only(left: 10, right: 10), - ), - LocaleKeys.arabic.tr().toText14(color: !AppState().isArabic(context) ? null : MyColors.textMixColor).onPress(() { - context.setLocale(const Locale("ar", "SA")); - postLanguageChange(context); - }), - ], - ), - ], - ).paddingOnly(left: 14, right: 14, bottom: 14), + // Row( + // children: [ + // Row( + // children: [ + // LocaleKeys.english.tr().toText14(color: AppState().isArabic(context) ? null : MyColors.textMixColor).onPress(() { + // context.setLocale(const Locale("en", "US")); + // postLanguageChange(context); + // }), + // Container( + // width: 1, + // color: MyColors.darkWhiteColor, + // height: 16, + // margin: const EdgeInsets.only(left: 10, right: 10), + // ), + // LocaleKeys.arabic.tr().toText14(color: !AppState().isArabic(context) ? null : MyColors.textMixColor).onPress(() { + // context.setLocale(const Locale("ar", "SA")); + // postLanguageChange(context); + // }), + // ], + // ), + // ], + // ).paddingOnly(left: 14, right: 14, bottom: 14), const Divider( height: 1, thickness: 1, diff --git a/lib/ui/leave_balance/add_leave_balance_screen.dart b/lib/ui/leave_balance/add_leave_balance_screen.dart index 85337aa..d1b7d77 100644 --- a/lib/ui/leave_balance/add_leave_balance_screen.dart +++ b/lib/ui/leave_balance/add_leave_balance_screen.dart @@ -109,17 +109,16 @@ class _AddLeaveBalanceScreenState extends State { } } } - await LeaveBalanceApiClient() - .validateAbsenceTransaction( - selectedAbsenceType!.dESCFLEXCONTEXTCODE!, - "HR_LOA_SS", - selectedAbsenceType!.aBSENCEATTENDANCETYPEID!, - selectedReplacementEmployee != null ? selectedReplacementEmployee!.userName! : "", - DateUtil.getFormattedDate(startDateTime!, "MM/dd/yyyy"), - DateUtil.getFormattedDate(endDateTime!, "MM/dd/yyyy"), - -999, - dffDataMap, - comments: comment); + await LeaveBalanceApiClient().validateAbsenceTransaction( + selectedAbsenceType!.dESCFLEXCONTEXTCODE!, + "HR_LOA_SS", + selectedAbsenceType!.aBSENCEATTENDANCETYPEID!, + selectedReplacementEmployee != null ? selectedReplacementEmployee!.userName! : "", + DateUtil.getFormattedDate(startDateTime!, "MM/dd/yyyy"), + DateUtil.getFormattedDate(endDateTime!, "MM/dd/yyyy"), + -999, + dffDataMap, + comments: comment); SumbitAbsenceTransactionList submit = await LeaveBalanceApiClient().submitAbsenceTransaction( selectedAbsenceType!.dESCFLEXCONTEXTCODE!, @@ -134,8 +133,10 @@ class _AddLeaveBalanceScreenState extends State { Utils.hideLoading(context); - await Navigator.pushNamed(context, AppRoutes.requestSubmitScreen, arguments: RequestSubmitScreenParams(LocaleKeys.submit.tr(), submit.pTRANSACTIONID!, "", "add_leave_balance")); - Utils.showLoading(context); + var res = await Navigator.pushNamed(context, AppRoutes.requestSubmitScreen, arguments: RequestSubmitScreenParams(LocaleKeys.submit.tr(), submit.pTRANSACTIONID!, "", "add_leave_balance")); + if (res != null && res == true) { + Utils.showLoading(context); + } await LeaveBalanceApiClient().cancelHrTransaction(submit.pTRANSACTIONID!); Utils.hideLoading(context); } catch (ex) { diff --git a/lib/ui/login/login_screen.dart b/lib/ui/login/login_screen.dart index 20fa8bc..e225459 100644 --- a/lib/ui/login/login_screen.dart +++ b/lib/ui/login/login_screen.dart @@ -128,6 +128,7 @@ class _LoginScreenState extends State { Navigator.pushNamed(context, AppRoutes.verifyLogin, arguments: "$firebaseToken"); } + Utils.saveStringFromPrefs(SharedPrefsConsts.password, password.text); } catch (ex) { Utils.hideLoading(context); Utils.handleException(ex, context, (msg) { @@ -143,7 +144,7 @@ class _LoginScreenState extends State { if (!kReleaseMode) { // username.text = "15444"; // Maha User // username.text = "15153"; // Tamer User - // password.text = "Abcd@12345"; + // password.text = "Abcd@1234"; // username.text = "206535"; // Hashim User // password.text = "Namira786"; diff --git a/lib/ui/marathon/marathon_intro_screen.dart b/lib/ui/marathon/marathon_intro_screen.dart index f836229..d85a82f 100644 --- a/lib/ui/marathon/marathon_intro_screen.dart +++ b/lib/ui/marathon/marathon_intro_screen.dart @@ -1,9 +1,12 @@ import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:lottie/lottie.dart'; +import 'package:mohem_flutter_app/app_state/app_state.dart'; import 'package:mohem_flutter_app/classes/colors.dart'; +import 'package:mohem_flutter_app/classes/date_uitl.dart'; import 'package:mohem_flutter_app/classes/decorations_helper.dart'; import 'package:mohem_flutter_app/classes/lottie_consts.dart'; +import 'package:mohem_flutter_app/classes/utils.dart'; import 'package:mohem_flutter_app/config/routes.dart'; import 'package:mohem_flutter_app/extensions/int_extensions.dart'; import 'package:mohem_flutter_app/extensions/string_extensions.dart'; @@ -15,8 +18,6 @@ import 'package:mohem_flutter_app/widgets/app_bar_widget.dart'; import 'package:mohem_flutter_app/widgets/button/default_button.dart'; import 'package:provider/provider.dart'; -final int dummyEndTime = DateTime.now().millisecondsSinceEpoch + 1000 * 30; - class MarathonIntroScreen extends StatelessWidget { const MarathonIntroScreen({Key? key}) : super(key: key); @@ -25,26 +26,18 @@ class MarathonIntroScreen extends StatelessWidget { MarathonProvider provider = context.watch(); return Scaffold( appBar: AppBarWidget(context, title: LocaleKeys.brainMarathon.tr()), - body: Stack( + body: Column( children: [ - SingleChildScrollView( - child: Column( - children: [ - MarathonDetailsCard(provider: provider).paddingAll(15), - MarathonTimerCard( - provider: provider, - timeToMarathon: dummyEndTime, - ).paddingOnly(left: 15, right: 15, bottom: 15), - const SizedBox( - height: 100, - ), - ], - ), - ), - Align( - alignment: Alignment.bottomCenter, - child: MarathonFooter(provider: provider), - ), + ListView( + padding: const EdgeInsets.all(21), + children: [ + MarathonDetailsCard(provider: provider), + 10.height, + MarathonTimerCard(provider: provider, timeToMarathon: DateTime.parse(provider.marathonDetailModel.startTime!).millisecondsSinceEpoch,), + ], + ).expanded, + 1.divider, + MarathonFooter(provider: provider), ], ), ); @@ -61,7 +54,7 @@ class MarathonDetailsCard extends StatelessWidget { return Container( width: double.infinity, decoration: MyDecorations.shadowDecoration, - padding: const EdgeInsets.symmetric(vertical: 20, horizontal: 20), + padding: const EdgeInsets.symmetric(vertical: 18, horizontal: 14), child: Column( mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start, @@ -70,37 +63,44 @@ class MarathonDetailsCard extends StatelessWidget { crossAxisAlignment: CrossAxisAlignment.start, children: [ LocaleKeys.contestTopicAbout.tr().toText16(color: MyColors.grey77Color), - "Saudi Arabia".toText20(color: MyColors.textMixColor, isBold: true), + "${AppState().isArabic(context) ? provider.marathonDetailModel.titleAr : provider.marathonDetailModel.titleEn}".toText20(color: MyColors.textMixColor, isBold: true), Row( children: [ Flexible( - child: "Nam suscipit turpis in pharetra euismsdef. Duis rutrum at nulla id aliquam".toText14(color: MyColors.grey77Color), + child: "${AppState().isArabic(context) ? provider.marathonDetailModel.descAr : provider.marathonDetailModel.descEn}".toText14(color: MyColors.grey77Color), ) ], ), - if (provider.itsMarathonTime) ...[ + if (provider.itsMarathonTime && provider.marathonDetailModel.sponsors != null) ...[ 5.height, + provider.marathonDetailModel.sponsors?.first.sponsorPrizes != null + ? Row( + children: [ + "${LocaleKeys.prize.tr()} ".toText16(color: MyColors.grey77Color, isBold: true), + "${AppState().isArabic(context) ? provider.marathonDetailModel.sponsors?.first.sponsorPrizes?.first.marathonPrizeAr : provider.marathonDetailModel.sponsors?.first.sponsorPrizes?.first.marathonPrizeAr}" + .toText16(color: MyColors.greenColor, isBold: true), + ], + ) + : const SizedBox(), Row( children: [ - LocaleKeys.prize.tr().toText16(color: MyColors.grey77Color, isBold: true), - " LED 55\" Android TV".toText16(color: MyColors.greenColor, isBold: true), - ], - ), - Row( - children: [ - LocaleKeys.sponsoredBy.tr().toText16(color: MyColors.grey77Color), - " Extra".toText16(color: MyColors.darkTextColor, isBold: true), + "${LocaleKeys.sponsoredBy.tr()} ".toText16(color: MyColors.grey77Color), + "${AppState().isArabic(context) ? provider.marathonDetailModel.sponsors?.first.nameAr : provider.marathonDetailModel.sponsors?.first.nameEn}" + .toText16(color: MyColors.darkTextColor, isBold: true), ], ), 10.height, Row( mainAxisAlignment: MainAxisAlignment.center, children: [ - Image.asset( - "assets/images/logos/main_mohemm_logo.png", + Image.network( + provider.marathonDetailModel.sponsors!.first.image!, height: 40, - fit: BoxFit.fill, width: 150, + fit: BoxFit.fill, + errorBuilder: (BuildContext context, Object exception, StackTrace? stackTrace) { + return const Center(); + }, ) ], ), @@ -128,30 +128,23 @@ class MarathonTimerCard extends StatelessWidget { return Container( width: double.infinity, decoration: MyDecorations.shadowDecoration, - padding: const EdgeInsets.symmetric(vertical: 20, horizontal: 20), + padding: const EdgeInsets.symmetric(vertical: 18, horizontal: 14), child: Column( children: [ Row( children: [ - LocaleKeys.gameDate.tr().toText16(color: MyColors.grey77Color), - " 10 Oct, 2022".toText16(color: MyColors.darkTextColor, isBold: true), + "${LocaleKeys.gameDate.tr()} ".toText16(color: MyColors.grey77Color), + DateUtil.getMonthDayYearDateFormatted(DateTime.parse(provider.marathonDetailModel.startTime!)).toText16(color: MyColors.darkTextColor, isBold: true), ], ), Row( children: [ - LocaleKeys.gameTime.tr().toText16(color: MyColors.grey77Color), - " 3:00pm".toText16(color: MyColors.darkTextColor, isBold: true), + "${LocaleKeys.gameTime.tr()} ".toText16(color: MyColors.grey77Color), + DateUtil.formatDateToTimeLang(DateTime.parse(provider.marathonDetailModel.startTime!), AppState().isArabic(context)).toText16(color: MyColors.darkTextColor, isBold: true), ], ), - Lottie.asset( - MyLottieConsts.hourGlassLottie, - height: 200, - ), - BuildCountdownTimer( - timeToMarathon: timeToMarathon, - provider: provider, - screenFlag: 1, - ), + Lottie.asset(MyLottieConsts.hourGlassLottie, height: 200), + BuildCountdownTimer(timeToMarathon: timeToMarathon, provider: provider, screenFlag: 1), ], ), ); @@ -172,38 +165,19 @@ class MarathonFooter extends StatelessWidget { children: [ TextSpan( text: LocaleKeys.note.tr(), - style: const TextStyle( - color: MyColors.darkTextColor, - fontSize: 17, - letterSpacing: -0.64, - fontWeight: FontWeight.bold, - ), + style: const TextStyle(color: MyColors.darkTextColor, fontSize: 17, letterSpacing: -0.64, fontWeight: FontWeight.bold), ), TextSpan( text: " " + LocaleKeys.demoMarathonNoteP1.tr(), - style: const TextStyle( - color: MyColors.grey77Color, - fontSize: 17, - letterSpacing: -0.64, - fontWeight: FontWeight.w500, - ), + style: const TextStyle(color: MyColors.grey77Color, fontSize: 17, letterSpacing: -0.64, fontWeight: FontWeight.w500), ), TextSpan( text: " " + LocaleKeys.demoMarathonNoteP2.tr(), - style: const TextStyle( - color: MyColors.darkTextColor, - fontSize: 17, - fontWeight: FontWeight.bold, - ), + style: const TextStyle(color: MyColors.darkTextColor, fontSize: 17, fontWeight: FontWeight.bold), ), TextSpan( text: " " + LocaleKeys.demoMarathonNoteP3.tr(), - style: const TextStyle( - color: MyColors.grey77Color, - fontSize: 17, - letterSpacing: -0.64, - fontWeight: FontWeight.w500, - ), + style: const TextStyle(color: MyColors.grey77Color, fontSize: 17, letterSpacing: -0.64, fontWeight: FontWeight.w500), ) ], ), @@ -212,10 +186,21 @@ class MarathonFooter extends StatelessWidget { @override Widget build(BuildContext context) { - return provider.itsMarathonTime + return !provider.itsMarathonTime ? DefaultButton( LocaleKeys.joinMarathon.tr(), - () => Navigator.pushNamed(context, AppRoutes.marathonScreen), + () async { + Utils.showLoading(context); + try { + provider.resetValues(); + await provider.connectSignalrAndJoinMarathon(context); + } catch (e, s) { + Utils.confirmDialog(context, e.toString()); + print(s); + } + Utils.hideLoading(context); + Navigator.pushNamed(context, AppRoutes.marathonScreen); + }, ).insideContainer : Container( color: Colors.white, @@ -225,7 +210,9 @@ class MarathonFooter extends StatelessWidget { buildNoteForDemo(), DefaultButton( LocaleKeys.joinDemoMarathon.tr(), - () {}, + () { + provider.connectSignalrAndJoinMarathon(context); + }, color: MyColors.yellowColorII, ).insideContainer, ], diff --git a/lib/ui/marathon/marathon_provider.dart b/lib/ui/marathon/marathon_provider.dart index 5a03b74..b629b36 100644 --- a/lib/ui/marathon/marathon_provider.dart +++ b/lib/ui/marathon/marathon_provider.dart @@ -3,12 +3,64 @@ import 'dart:async'; import 'package:appinio_swiper/appinio_swiper.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; -import 'package:mohem_flutter_app/config/routes.dart'; +import 'package:mohem_flutter_app/api/marathon/marathon_api_client.dart'; +import 'package:mohem_flutter_app/models/marathon/marathon_model.dart'; +import 'package:mohem_flutter_app/models/marathon/question_model.dart'; import 'package:mohem_flutter_app/ui/marathon/widgets/question_card.dart'; class MarathonProvider extends ChangeNotifier { final AppinioSwiperController swiperController = AppinioSwiperController(); + MarathonDetailModel marathonDetailModel = MarathonDetailModel(); + List cardContentList = []; + QuestionModel currentQuestion = QuestionModel(); + + QuestionCardStatus questionCardStatus = QuestionCardStatus.question; + + int? selectedOptionIndex; + int currentQuestionTime = 0; + + void onNewQuestionReceived(QuestionModel newQuestion) { + if (currentQuestionNumber > 0) { + swipeCardLeft(); + } + selectedOptionIndex = null; + currentQuestionNumber++; + currentQuestion = newQuestion; + cardContentList.add(const CardContent()); + currentQuestionTime = newQuestion.questionTime!; + questionCardStatus = QuestionCardStatus.question; + notifyListeners(); + } + + void addItemToList(CardContent value) { + cardContentList.add(value); + notifyListeners(); + } + + void updateCurrentQuestionOptionStatus(QuestionsOptionStatus status, int index) { + for (int i = 0; i < currentQuestion.questionOptions!.length; i++) { + currentQuestion.questionOptions![i].optionStatus = QuestionsOptionStatus.unSelected; + } + currentQuestion.questionOptions![index].optionStatus = status; + selectedOptionIndex = index; + notifyListeners(); + } + + void updateQuestionCardStatus(QuestionCardStatus status) { + questionCardStatus = status; + notifyListeners(); + } + + bool _isLoading = false; + + bool get isLoading => _isLoading; + + set isLoading(bool value) { + _isLoading = value; + notifyListeners(); + } + bool _itsMarathonTime = false; bool get itsMarathonTime => _itsMarathonTime; @@ -27,14 +79,7 @@ class MarathonProvider extends ChangeNotifier { notifyListeners(); } - void swipeCardLeft() { - currentQuestionNumber = currentQuestionNumber + 1; - swiperController.swipeLeft(); - notifyListeners(); - } - - int _currentQuestionNumber = 1; - final int totalQuestions = 10; + int _currentQuestionNumber = 0; int get currentQuestionNumber => _currentQuestionNumber; @@ -43,44 +88,73 @@ class MarathonProvider extends ChangeNotifier { notifyListeners(); } - void resetAll() { - isSelectedOptions[0] = false; - isSelectedOptions[1] = false; - isSelectedOptions[2] = false; - isSelectedOptions[3] = false; + int _totalMarathoners = 23; + + int get totalMarathoners => _totalMarathoners; + + set totalMarathoners(int value) { + _totalMarathoners = value; + notifyListeners(); + } + + void swipeCardLeft() { + swiperController.swipeLeft(); + notifyListeners(); + } + + void getCorrectAnswerAndUpdateAnswerColor() { + if (selectedOptionIndex != null) { + if (currentQuestion.questionOptions![selectedOptionIndex!].isCorrectOption!) { + updateCurrentQuestionOptionStatus(QuestionsOptionStatus.correct, selectedOptionIndex!); + } else { + updateCurrentQuestionOptionStatus(QuestionsOptionStatus.wrong, selectedOptionIndex!); + } + } + } + + void updateCardStatusToAnswer() { + if (currentQuestionNumber == 0) { + return; + } + + if (selectedOptionIndex != null) { + if (currentQuestion.questionOptions![selectedOptionIndex!].isCorrectOption!) { + updateQuestionCardStatus(QuestionCardStatus.correctAnswer); + } else { + updateQuestionCardStatus(QuestionCardStatus.wrongAnswer); + } + } else { + updateQuestionCardStatus(QuestionCardStatus.skippedAnswer); + } } Timer timerU = Timer.periodic(const Duration(seconds: 1), (Timer timer) {}); - int start = 8; void startTimer(BuildContext context) { - start = 8; const Duration oneSec = Duration(seconds: 1); timerU = Timer.periodic( oneSec, (Timer timer) async { - if (start == 0) { - if (currentQuestionNumber == 9) { - timer.cancel(); - cancelTimer(); - isMarathonCompleted = true; - await Future.delayed(const Duration(seconds: 3)).whenComplete( - () => Navigator.pushReplacementNamed( - context, - AppRoutes.marathonWinnerSelection, - ), - ); - - resetValues(); - - return; - } - resetAll(); - timer.cancel(); - cancelTimer(); - swipeCardLeft(); + if (currentQuestionTime == 2) { + getCorrectAnswerAndUpdateAnswerColor(); + } + if (currentQuestionTime == 0) { + updateCardStatusToAnswer(); + // if (currentQuestionNumber == 9) { + // timer.cancel(); + // cancelTimer(); + // isMarathonCompleted = true; + // await Future.delayed(const Duration(seconds: 2)).whenComplete( + // () => Navigator.pushReplacementNamed(context, AppRoutes.marathonWinnerSelection), + // ); + // + // resetValues(); + // + // return; + // } + // timer.cancel(); } else { - start--; + currentQuestionTime--; } notifyListeners(); }, @@ -88,9 +162,12 @@ class MarathonProvider extends ChangeNotifier { } void resetValues() { + _currentQuestionNumber = 0; + cardContentList.clear(); timerU.cancel(); _isMarathonCompleted = false; - _currentQuestionNumber = 1; + currentQuestionTime = 0; + currentQuestion = QuestionModel(); notifyListeners(); } @@ -98,4 +175,18 @@ class MarathonProvider extends ChangeNotifier { timerU.cancel(); notifyListeners(); } + + Future getMarathonDetailsFromApi() async { + isLoading = true; + notifyListeners(); + await MarathonApiClient().getMarathonToken().whenComplete(() async { + marathonDetailModel = await MarathonApiClient().getMarathonDetails(); + isLoading = false; + notifyListeners(); + }); + } + + Future connectSignalrAndJoinMarathon(BuildContext context) async { + await MarathonApiClient().buildHubConnection(context); + } } diff --git a/lib/ui/marathon/marathon_screen.dart b/lib/ui/marathon/marathon_screen.dart index a02733f..79d61fe 100644 --- a/lib/ui/marathon/marathon_screen.dart +++ b/lib/ui/marathon/marathon_screen.dart @@ -6,7 +6,6 @@ import 'package:lottie/lottie.dart'; import 'package:mohem_flutter_app/classes/colors.dart'; import 'package:mohem_flutter_app/classes/decorations_helper.dart'; import 'package:mohem_flutter_app/classes/lottie_consts.dart'; -import 'package:mohem_flutter_app/config/routes.dart'; import 'package:mohem_flutter_app/extensions/int_extensions.dart'; import 'package:mohem_flutter_app/extensions/string_extensions.dart'; import 'package:mohem_flutter_app/extensions/widget_extensions.dart'; @@ -14,10 +13,9 @@ import 'package:mohem_flutter_app/generated/locale_keys.g.dart'; import 'package:mohem_flutter_app/ui/marathon/marathon_provider.dart'; import 'package:mohem_flutter_app/ui/marathon/widgets/custom_status_widget.dart'; import 'package:mohem_flutter_app/ui/marathon/widgets/question_card.dart'; +import 'package:mohem_flutter_app/ui/marathon/widgets/question_card_builder.dart'; import 'package:mohem_flutter_app/widgets/app_bar_widget.dart'; import 'package:provider/provider.dart'; -import 'package:sizer/sizer.dart'; -import 'package:steps_indicator/steps_indicator.dart'; class MarathonScreen extends StatelessWidget { const MarathonScreen({Key? key}) : super(key: key); @@ -25,48 +23,52 @@ class MarathonScreen extends StatelessWidget { @override Widget build(BuildContext context) { MarathonProvider provider = context.watch(); - return Scaffold( - appBar: AppBarWidget(context, title: LocaleKeys.brainMarathon.tr()), - body: SingleChildScrollView( - child: Column( - children: [ - 20.height, - MarathonProgressContainer(provider: provider).paddingOnly(left: 21, right: 21), - if (provider.isMarathonCompleted) - InkWell( - onTap: () { - Navigator.pushReplacementNamed( - context, - AppRoutes.marathonWinnerSelection, - ); - }, - child: CustomStatusWidget( - asset: Lottie.asset( - MyLottieConsts.allQuestions, - height: 200, - ), - title: Text( - LocaleKeys.congrats.tr(), - style: const TextStyle( - height: 23 / 24, - color: MyColors.greenColor, - fontSize: 27, - letterSpacing: -1, - fontWeight: FontWeight.w600, - ), - ), - subTitle: Text( - LocaleKeys.allQuestionsCorrect.tr(), - textAlign: TextAlign.center, - style: const TextStyle(fontSize: 18, fontWeight: FontWeight.w600, color: MyColors.darkTextColor, letterSpacing: -1.08), - ), - ).paddingOnly(top: 12, left: 21, right: 21), - ) - else - QuestionCard(provider: provider).paddingOnly(top: 12, left: 21, right: 21), - ], + return WillPopScope( + child: Scaffold( + appBar: AppBarWidget(context, title: LocaleKeys.brainMarathon.tr()), + body: SingleChildScrollView( + child: Column( + children: [ + 20.height, + MarathonProgressContainer(provider: provider).paddingOnly(left: 21, right: 21), + QuestionCardBuilder( + onQuestion: (BuildContext context) => QuestionCard(provider: provider), + onCompleted: (BuildContext context) => CustomStatusWidget( + asset: Lottie.asset(MyLottieConsts.allQuestions, height: 200), + title: LocaleKeys.congrats.tr().toText22(color: MyColors.greenColor), + subTitle: LocaleKeys.allQuestionsCorrect.toText18(color: MyColors.darkTextColor), + ), + onCorrectAnswer: (BuildContext context) => CustomStatusWidget( + asset: Lottie.asset(MyLottieConsts.allQuestions, height: 200), + title: LocaleKeys.congrats.tr().toText22(color: MyColors.greenColor), + subTitle: LocaleKeys.yourAnswerCorrect.toText18(color: MyColors.darkTextColor), + ), + onWinner: (BuildContext context) => QuestionCard(provider: provider), + onWrongAnswer: (BuildContext context) => CustomStatusWidget( + asset: Image.asset(MyLottieConsts.wrongAnswerGif, height: 200), + title: const Text(""), + subTitle: LocaleKeys.wrongAnswer.tr().toText18(color: MyColors.darkTextColor), + ), + onSkippedAnswer: (BuildContext context) => CustomStatusWidget( + asset: Image.asset(MyLottieConsts.wrongAnswerGif, height: 200), + title: const Text(""), + subTitle: LocaleKeys.youMissedTheQuestion.tr().toText18(color: MyColors.darkTextColor), + ), + questionCardStatus: provider.questionCardStatus, + onFindingWinner: (BuildContext context) => CustomStatusWidget( + asset: Lottie.asset(MyLottieConsts.winnerLottie, height: 168), + title: LocaleKeys.fingersCrossed.tr().toText22(color: MyColors.greenColor), + subTitle: LocaleKeys.winnerSelectedRandomly.tr().toText18(color: MyColors.darkTextColor), + ), + ).paddingOnly(top: 12, left: 21, right: 21), + ], + ), ), ), + onWillPop: () { + provider.resetValues(); + return Future.value(true); + }, ); } } @@ -91,7 +93,6 @@ class _MarathonProgressContainerState extends State { @override void dispose() { - widget.provider.cancelTimer(); super.dispose(); } @@ -100,7 +101,7 @@ class _MarathonProgressContainerState extends State { return Container( width: double.infinity, decoration: MyDecorations.shadowDecoration, - padding: const EdgeInsets.all(21), + padding: const EdgeInsets.symmetric(vertical: 18, horizontal: 13), child: Column( mainAxisSize: MainAxisSize.min, children: [ @@ -108,47 +109,90 @@ class _MarathonProgressContainerState extends State { mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Container( - decoration: BoxDecoration( - color: MyColors.greenColor, - borderRadius: BorderRadius.circular(5), - ), + decoration: BoxDecoration(color: MyColors.greenColor, borderRadius: BorderRadius.circular(5)), padding: const EdgeInsets.symmetric(vertical: 5, horizontal: 8), - child: "${widget.provider.currentQuestionNumber.toString()} / ${widget.provider.totalQuestions.toString()} ${LocaleKeys.question.tr()}".toText12(color: MyColors.white), + child: "${widget.provider.currentQuestionNumber.toString()} / ${widget.provider.marathonDetailModel.totalQuestions.toString()} ${LocaleKeys.question.tr()}" + .toText12(color: MyColors.white), ), - "23 ${LocaleKeys.marathoners.tr()}".toText14(), - "00:${widget.provider.start < 10 ? "0${widget.provider.start}" : widget.provider.start}".toText18(), + "${widget.provider.totalMarathoners} ${LocaleKeys.marathoners.tr()}".toText14(), + "00:${widget.provider.currentQuestionTime < 10 ? "0${widget.provider.currentQuestionTime}" : widget.provider.currentQuestionTime}" + .toText18(color: widget.provider.currentQuestionTime < 5 ? MyColors.redColor : MyColors.black), ], ), - 15.height, - StepsIndicator( - lineLength: SizerUtil.deviceType == DeviceType.tablet ? MediaQuery.of(context).size.width * 0.077 : MediaQuery.of(context).size.width * 0.054, - nbSteps: 10, - selectedStep: widget.provider.currentQuestionNumber, - doneLineColor: MyColors.greenColor, - doneStepColor: MyColors.greenColor, - doneLineThickness: 6, - undoneLineThickness: 6, - selectedStepSize: 10, - unselectedStepSize: 10, - doneStepSize: 10, - selectedStepBorderSize: 0, - unselectedStepBorderSize: 0, - selectedStepColorIn: MyColors.greenColor, - selectedStepColorOut: MyColors.greenColor, - unselectedStepColorIn: MyColors.lightGreyDeColor, - unselectedStepColorOut: MyColors.lightGreyDeColor, - undoneLineColor: MyColors.lightGreyDeColor, - enableLineAnimation: false, - enableStepAnimation: false, - ), 12.height, + stepper(widget.provider.currentQuestionNumber), + 8.height, Row( children: [ - "${widget.provider.currentQuestionNumber * 10}% ${LocaleKeys.completed.tr()}".toText14(isBold: true), + "${((widget.provider.currentQuestionNumber / widget.provider.marathonDetailModel.totalQuestions!) * 100).toInt()}% ${LocaleKeys.completed.tr()}".toText14(), ], ), ], ), ); } + + Widget stepper(int value) { + return SizedBox( + width: double.infinity, + child: Row( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + children: [ + for (int i = 0; i < 10; i++) + if (value <= i) roundContainer(MyColors.lightGreyDeColor, i != 0) else roundContainer(MyColors.greenColor, i != 0) + ], + ), + ); + } + + Widget roundContainer(Color color, bool isNeedLeftBorder) { + if (isNeedLeftBorder) { + return Row( + children: [ + Divider(thickness: 6, color: color).expanded, + Container( + width: 10, + height: 10, + decoration: BoxDecoration(shape: BoxShape.circle, color: color), + ), + ], + ).expanded; + } + + return Container( + width: 10, + height: 10, + decoration: BoxDecoration(shape: BoxShape.circle, color: color), + ); + } } + +// InkWell( +// onTap: () { +// Navigator.pushReplacementNamed( +// context, +// AppRoutes.marathonWinnerSelection, +// ); +// }, +// child: CustomStatusWidget( +// asset: Lottie.asset( +// MyLottieConsts.allQuestions, +// height: 200, +// ), +// title: Text( +// LocaleKeys.congrats.tr(), +// style: const TextStyle( +// height: 23 / 24, +// color: MyColors.greenColor, +// fontSize: 27, +// letterSpacing: -1, +// fontWeight: FontWeight.w600, +// ), +// ), +// subTitle: Text( +// LocaleKeys.allQuestionsCorrect.tr(), +// textAlign: TextAlign.center, +// style: const TextStyle(fontSize: 18, fontWeight: FontWeight.w600, color: MyColors.darkTextColor, letterSpacing: -1.08), +// ), +// ).paddingOnly(top: 12, left: 21, right: 21), +// ) diff --git a/lib/ui/marathon/marathon_winner_selection.dart b/lib/ui/marathon/marathon_winner_selection.dart index 8462ab4..1f56801 100644 --- a/lib/ui/marathon/marathon_winner_selection.dart +++ b/lib/ui/marathon/marathon_winner_selection.dart @@ -29,7 +29,7 @@ class MarathonWinnerSelection extends StatelessWidget { children: [ 20.height, QualifiersContainer(provider: provider).paddingOnly(left: 21, right: 21), - 20.height, + 12.height, InkWell( onTap: () { Navigator.pushNamed(context, AppRoutes.marathonWinnerScreen); @@ -52,8 +52,8 @@ class MarathonWinnerSelection extends StatelessWidget { child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - "Muhammad Shrouff".toText18(isBold: true, color: MyColors.white), - "837436".toText18(isBold: true, color: MyColors.white), + "Muhammad Shrouff".toText17(isBold: true, color: MyColors.white), + "837436".toText17(isBold: true, color: MyColors.white), ], ), ), @@ -67,10 +67,10 @@ class MarathonWinnerSelection extends StatelessWidget { title: Text( LocaleKeys.fingersCrossed.tr(), style: const TextStyle( - height: 23 / 24, + height: 27 / 27, color: MyColors.greenColor, fontSize: 27, - letterSpacing: -1, + letterSpacing: -1.08, fontWeight: FontWeight.w600, ), ), @@ -78,9 +78,9 @@ class MarathonWinnerSelection extends StatelessWidget { LocaleKeys.winnerSelectedRandomly.tr(), textAlign: TextAlign.center, style: const TextStyle( - color: MyColors.grey77Color, - fontSize: 16, - letterSpacing: -0.64, + color: MyColors.darkTextColor, + fontSize: 18, + letterSpacing: -0.72, fontWeight: FontWeight.w600, ), )).paddingOnly(left: 21, right: 21, top: 20, bottom: 20), @@ -108,14 +108,14 @@ class _QualifiersContainerState extends State { @override void initState() { scheduleMicrotask(() { - widget.provider.startTimer(context); + // widget.provider.startTimer(context); }); super.initState(); } @override void dispose() { - widget.provider.cancelTimer(); + // widget.provider.cancelTimer(); super.dispose(); } @@ -124,22 +124,22 @@ class _QualifiersContainerState extends State { return Container( width: double.infinity, decoration: MyDecorations.shadowDecoration, - padding: const EdgeInsets.symmetric(vertical: 15, horizontal: 20), + padding: const EdgeInsets.only(top: 14,left: 18,right: 14,bottom: 18), child: Column( mainAxisSize: MainAxisSize.min, children: [ Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ - LocaleKeys.winnerSelection.tr().toText18(isBold: true, color: MyColors.grey3AColor), - "00:${widget.provider.start < 10 ? "0${widget.provider.start}" : widget.provider.start}".toText18(isBold: true, color: MyColors.redColor), + LocaleKeys.winnerSelection.tr().toText21(color: MyColors.grey3AColor), + // "00:${widget.provider.start < 10 ? "0${widget.provider.start}" : widget.provider.start}".toText18(color: MyColors.redColor), ], ), 10.height, Row( children: [ - "18 ".toText32(color: MyColors.greenColor), - LocaleKeys.qualifiers.tr().toText20(color: MyColors.greenColor), + "18".toText30(color: MyColors.greenColor, isBold: true),2.width, + LocaleKeys.qualifiers.tr().toText16(color: MyColors.greenColor), ], ), ], diff --git a/lib/ui/marathon/widgets/countdown_timer.dart b/lib/ui/marathon/widgets/countdown_timer.dart index 6ab8dba..cfa3b1b 100644 --- a/lib/ui/marathon/widgets/countdown_timer.dart +++ b/lib/ui/marathon/widgets/countdown_timer.dart @@ -1,4 +1,5 @@ import 'dart:async'; +import 'dart:ui' as ui; import 'package:auto_size_text/auto_size_text.dart'; import 'package:easy_localization/easy_localization.dart'; @@ -29,7 +30,7 @@ class BuildCountdownTimer extends StatelessWidget { ); final TextStyle styleDigitHome = const TextStyle( - height: 23 / 27, + height: 22 / 27, color: MyColors.white, fontStyle: FontStyle.italic, letterSpacing: -1.44, @@ -53,79 +54,83 @@ class BuildCountdownTimer extends StatelessWidget { ); Widget buildEmptyWidget() { - return Row( - mainAxisSize: MainAxisSize.min, - mainAxisAlignment: MainAxisAlignment.spaceEvenly, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Column( - children: [ - AutoSizeText( - "00", - maxFontSize: 24, - minFontSize: 20, - style: screenFlag == 0 ? styleDigitHome : styleDigitMarathon, - ), - AutoSizeText( - LocaleKeys.days.tr(), - minFontSize: 7, - maxFontSize: 8, - style: screenFlag == 0 ? styleTextHome : styleTextMarathon, - ), - ], - ), - buildSeparator(), - Column( - children: [ - AutoSizeText( - "00", - maxFontSize: 24, - minFontSize: 20, - style: screenFlag == 0 ? styleDigitHome : styleDigitMarathon, - ), - AutoSizeText( - LocaleKeys.hours.tr(), - minFontSize: 7, - maxFontSize: 8, - style: screenFlag == 0 ? styleTextHome : styleTextMarathon, - ), - ], - ), - buildSeparator(), - Column( - children: [ - AutoSizeText( - "00", - maxFontSize: 24, - minFontSize: 20, - style: screenFlag == 0 ? styleDigitHome : styleDigitMarathon, - ), - AutoSizeText( - LocaleKeys.minutes.tr(), - minFontSize: 7, - maxFontSize: 8, - style: screenFlag == 0 ? styleTextHome : styleTextMarathon, - ), - ], - ), - buildSeparator(), - Column( - children: [ - AutoSizeText( - "00", - maxFontSize: 24, - minFontSize: 20, - style: screenFlag == 0 ? styleDigitHome : styleDigitMarathon, - ), - AutoSizeText( - LocaleKeys.seconds.tr(), - minFontSize: 7, - maxFontSize: 8, - style: screenFlag == 0 ? styleTextHome : styleTextMarathon, - ), - ], - ), - ], + return Directionality( + textDirection: ui.TextDirection.ltr, + child: Row( + mainAxisSize: MainAxisSize.min, + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Column( + children: [ + // todo @faiz: Make a separate method and pass string , so we can minimize code replication + AutoSizeText( + "00", + maxFontSize: 24, + minFontSize: 20, + style: screenFlag == 0 ? styleDigitHome : styleDigitMarathon, + ), + AutoSizeText( + LocaleKeys.days.tr(), + minFontSize: 7, + maxFontSize: 8, + style: screenFlag == 0 ? styleTextHome : styleTextMarathon, + ), + ], + ), + buildSeparator(), + Column( + children: [ + AutoSizeText( + "00", + maxFontSize: 24, + minFontSize: 20, + style: screenFlag == 0 ? styleDigitHome : styleDigitMarathon, + ), + AutoSizeText( + LocaleKeys.hours.tr(), + minFontSize: 7, + maxFontSize: 8, + style: screenFlag == 0 ? styleTextHome : styleTextMarathon, + ), + ], + ), + buildSeparator(), + Column( + children: [ + AutoSizeText( + "00", + maxFontSize: 24, + minFontSize: 20, + style: screenFlag == 0 ? styleDigitHome : styleDigitMarathon, + ), + AutoSizeText( + LocaleKeys.minutes.tr(), + minFontSize: 7, + maxFontSize: 8, + style: screenFlag == 0 ? styleTextHome : styleTextMarathon, + ), + ], + ), + buildSeparator(), + Column( + children: [ + AutoSizeText( + "00", + maxFontSize: 24, + minFontSize: 20, + style: screenFlag == 0 ? styleDigitHome : styleDigitMarathon, + ), + AutoSizeText( + LocaleKeys.seconds.tr(), + minFontSize: 7, + maxFontSize: 8, + style: screenFlag == 0 ? styleTextHome : styleTextMarathon, + ), + ], + ), + ], + ), ); } @@ -148,107 +153,111 @@ class BuildCountdownTimer extends StatelessWidget { return buildEmptyWidget(); } - return Row( - mainAxisSize: MainAxisSize.min, - mainAxisAlignment: MainAxisAlignment.spaceEvenly, - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Column( - children: [ - time.days == null - ? AutoSizeText( - "00", - maxFontSize: 24, - minFontSize: 20, - style: screenFlag == 0 ? styleDigitHome : styleDigitMarathon, - ) - : AutoSizeText( - time.days! < 10 ? "0${time.days.toString()}" : time.days.toString(), - maxFontSize: 24, - minFontSize: 20, - style: screenFlag == 0 ? styleDigitHome : styleDigitMarathon, - ), - AutoSizeText( - LocaleKeys.days.tr(), - minFontSize: 7, - maxFontSize: 8, - style: screenFlag == 0 ? styleTextHome : styleTextMarathon, - ), - ], - ), - buildSeparator(), - Column( - children: [ - time.hours == null - ? AutoSizeText( - "00", - maxFontSize: 24, - minFontSize: 20, - style: screenFlag == 0 ? styleDigitHome : styleDigitMarathon, - ) - : AutoSizeText( - time.hours! < 10 ? "0${time.hours.toString()}" : time.hours.toString(), - maxFontSize: 24, - minFontSize: 20, - style: screenFlag == 0 ? styleDigitHome : styleDigitMarathon, - ), - AutoSizeText( - LocaleKeys.hours.tr(), - minFontSize: 7, - maxFontSize: 8, - style: screenFlag == 0 ? styleTextHome : styleTextMarathon, - ), - ], - ), - buildSeparator(), - Column( - children: [ - time.min == null - ? AutoSizeText( - "00", - maxFontSize: 24, - minFontSize: 20, - style: screenFlag == 0 ? styleDigitHome : styleDigitMarathon, - ) - : AutoSizeText( - time.min! < 10 ? "0${time.min.toString()}" : time.min.toString(), - maxFontSize: 24, - minFontSize: 20, - style: screenFlag == 0 ? styleDigitHome : styleDigitMarathon, - ), - AutoSizeText( - LocaleKeys.minutes.tr(), - minFontSize: 7, - maxFontSize: 8, - style: screenFlag == 0 ? styleTextHome : styleTextMarathon, - ), - ], - ), - buildSeparator(), - Column( - children: [ - time.sec == null - ? AutoSizeText( - "00", - maxFontSize: 24, - minFontSize: 20, - style: screenFlag == 0 ? styleDigitHome : styleDigitMarathon, - ) - : AutoSizeText( - time.sec! < 10 ? "0${time.sec.toString()}" : time.sec.toString(), - maxFontSize: 24, - minFontSize: 20, - style: screenFlag == 0 ? styleDigitHome : styleDigitMarathon, - ), - AutoSizeText( - LocaleKeys.seconds.tr(), - minFontSize: 7, - maxFontSize: 8, - style: screenFlag == 0 ? styleTextHome : styleTextMarathon, - ), - ], - ), - ], + return Directionality( + textDirection: ui.TextDirection.ltr, + child: Row( + mainAxisSize: MainAxisSize.min, + mainAxisAlignment: MainAxisAlignment.spaceEvenly, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Column( + children: [ + // todo @faiz: Make a separate method and pass value and string , so we can minimize code replication + time.days == null + ? AutoSizeText( + "00", + maxFontSize: 24, + minFontSize: 20, + style: screenFlag == 0 ? styleDigitHome : styleDigitMarathon, + ) + : AutoSizeText( + time.days! < 10 ? "0${time.days.toString()}" : time.days.toString(), + maxFontSize: 24, + minFontSize: 20, + style: screenFlag == 0 ? styleDigitHome : styleDigitMarathon, + ), + AutoSizeText( + LocaleKeys.days.tr(), + minFontSize: 7, + maxFontSize: 8, + style: screenFlag == 0 ? styleTextHome : styleTextMarathon, + ), + ], + ), + buildSeparator(), + Column( + children: [ + time.hours == null + ? AutoSizeText( + "00", + maxFontSize: 24, + minFontSize: 20, + style: screenFlag == 0 ? styleDigitHome : styleDigitMarathon, + ) + : AutoSizeText( + time.hours! < 10 ? "0${time.hours.toString()}" : time.hours.toString(), + maxFontSize: 24, + minFontSize: 20, + style: screenFlag == 0 ? styleDigitHome : styleDigitMarathon, + ), + AutoSizeText( + LocaleKeys.hours.tr(), + minFontSize: 7, + maxFontSize: 8, + style: screenFlag == 0 ? styleTextHome : styleTextMarathon, + ), + ], + ), + buildSeparator(), + Column( + children: [ + time.min == null + ? AutoSizeText( + "00", + maxFontSize: 24, + minFontSize: 20, + style: screenFlag == 0 ? styleDigitHome : styleDigitMarathon, + ) + : AutoSizeText( + time.min! < 10 ? "0${time.min.toString()}" : time.min.toString(), + maxFontSize: 24, + minFontSize: 20, + style: screenFlag == 0 ? styleDigitHome : styleDigitMarathon, + ), + AutoSizeText( + LocaleKeys.minutes.tr(), + minFontSize: 7, + maxFontSize: 8, + style: screenFlag == 0 ? styleTextHome : styleTextMarathon, + ), + ], + ), + buildSeparator(), + Column( + children: [ + time.sec == null + ? AutoSizeText( + "00", + maxFontSize: 24, + minFontSize: 20, + style: screenFlag == 0 ? styleDigitHome : styleDigitMarathon, + ) + : AutoSizeText( + time.sec! < 10 ? "0${time.sec.toString()}" : time.sec.toString(), + maxFontSize: 24, + minFontSize: 20, + style: screenFlag == 0 ? styleDigitHome : styleDigitMarathon, + ), + AutoSizeText( + LocaleKeys.seconds.tr(), + minFontSize: 7, + maxFontSize: 8, + style: screenFlag == 0 ? styleTextHome : styleTextMarathon, + ), + ], + ), + ], + ), ); } diff --git a/lib/ui/marathon/widgets/custom_status_widget.dart b/lib/ui/marathon/widgets/custom_status_widget.dart index 4fde6cc..8287bb4 100644 --- a/lib/ui/marathon/widgets/custom_status_widget.dart +++ b/lib/ui/marathon/widgets/custom_status_widget.dart @@ -18,6 +18,7 @@ class CustomStatusWidget extends StatelessWidget { Widget build(BuildContext context) { return Container( width: double.infinity, + height: 440, decoration: MyDecorations.shadowDecoration, padding: const EdgeInsets.symmetric(vertical: 20, horizontal: 20), child: Column( diff --git a/lib/ui/marathon/widgets/marathon_banner.dart b/lib/ui/marathon/widgets/marathon_banner.dart index 55ff715..e711319 100644 --- a/lib/ui/marathon/widgets/marathon_banner.dart +++ b/lib/ui/marathon/widgets/marathon_banner.dart @@ -1,3 +1,5 @@ +import 'dart:math' as math; + import 'package:auto_size_text/auto_size_text.dart'; import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; @@ -9,11 +11,9 @@ import 'package:mohem_flutter_app/config/routes.dart'; import 'package:mohem_flutter_app/extensions/int_extensions.dart'; import 'package:mohem_flutter_app/extensions/widget_extensions.dart'; import 'package:mohem_flutter_app/generated/locale_keys.g.dart'; -import 'package:mohem_flutter_app/ui/marathon/marathon_intro_screen.dart'; import 'package:mohem_flutter_app/ui/marathon/marathon_provider.dart'; import 'package:mohem_flutter_app/ui/marathon/widgets/countdown_timer.dart'; import 'package:provider/provider.dart'; -import 'dart:math' as math; class MarathonBanner extends StatelessWidget { const MarathonBanner({Key? key}) : super(key: key); @@ -21,142 +21,179 @@ class MarathonBanner extends StatelessWidget { @override Widget build(BuildContext context) { MarathonProvider provider = context.read(); - return Container( - decoration: MyDecorations.shadowDecoration, - height: MediaQuery.of(context).size.height * 0.11, - clipBehavior: Clip.antiAlias, - child: Stack( - children: [ - Transform( - alignment: Alignment.center, - transform: Matrix4.rotationY( - AppState().isArabic(context) ? math.pi : 0, - ), - child: SvgPicture.asset( - "assets/images/marathon_banner_bg.svg", - fit: BoxFit.fill, - width: double.infinity, - ), - ), - Positioned( - left: -20, - top: -10, - child: Transform.rotate( - angle: 15, - child: Container( - width: 65, - height: 32, - color: MyColors.darkDigitColor, - ), - ), - ), - SizedBox( - width: double.infinity, - height: double.infinity, - child: Row( + return provider.marathonDetailModel.startTime != null + ? Container( + decoration: MyDecorations.shadowDecoration, + height: MediaQuery.of(context).size.height * 0.11, + clipBehavior: Clip.antiAlias, + child: Stack( children: [ - const Expanded( - flex: 3, - child: SizedBox( + Transform( + alignment: Alignment.center, + transform: Matrix4.rotationY( + AppState().isArabic(context) ? math.pi : 0, + ), + child: SvgPicture.asset( + "assets/images/marathon_banner_bg.svg", + fit: BoxFit.fill, width: double.infinity, - height: double.infinity, ), ), - Expanded( - flex: 5, - child: SizedBox( - width: double.infinity, - height: double.infinity, - child: Row( - mainAxisAlignment: MainAxisAlignment.start, - children: [ - Column( - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.start, - mainAxisSize: MainAxisSize.min, - children: [ - AppState().isArabic(context) ? 0.height : 5.height, - AutoSizeText( - LocaleKeys.getReadyForContest.tr(), - minFontSize: 08, - maxFontSize: 11, - style: TextStyle( - fontStyle: FontStyle.italic, - fontWeight: FontWeight.w600, - color: MyColors.white.withOpacity(0.83), - letterSpacing: -0.4, + AppState().isArabic(context) + ? Positioned( + right: -15, + top: -10, + child: Transform.rotate( + angle: 10, + child: Container( + width: 65, + height: 32, + color: MyColors.darkDigitColor, + ), + ), + ) + : Positioned( + left: -20, + top: -10, + child: Transform.rotate( + angle: 15, + child: Container( + width: 65, + height: 32, + color: MyColors.darkDigitColor, + ), + ), + ), + SizedBox( + width: double.infinity, + height: double.infinity, + child: Row( + children: [ + const Expanded( + flex: 3, + child: SizedBox( + width: double.infinity, + height: double.infinity, + ), + ), + Expanded( + flex: AppState().isArabic(context) ? 4 : 5, + child: SizedBox( + width: double.infinity, + height: double.infinity, + child: Row( + mainAxisAlignment: MainAxisAlignment.start, + children: [ + Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + AppState().isArabic(context) ? 0.height : 5.height, + AutoSizeText( + LocaleKeys.getReadyForContest.tr(), + minFontSize: 08, + maxFontSize: 11, + style: TextStyle( + fontStyle: FontStyle.italic, + fontWeight: FontWeight.w600, + color: MyColors.white.withOpacity(0.83), + letterSpacing: -0.4, + ), + ), + AutoSizeText( + AppState().isArabic(context) ? provider.marathonDetailModel.titleAr ?? "" : provider.marathonDetailModel.titleEn ?? "", + style: TextStyle( + fontStyle: FontStyle.italic, + fontSize: 19, + fontWeight: FontWeight.bold, + color: MyColors.white.withOpacity(0.83), + height: 32 / 22, + ), + ), + 3.height, + BuildCountdownTimer( + timeToMarathon: DateTime.parse(provider.marathonDetailModel.startTime!).millisecondsSinceEpoch, + provider: provider, + screenFlag: 0, + ), + ], + ).paddingOnly( + left: AppState().isArabic(context) ? 12 : 3, + right: AppState().isArabic(context) ? 3 : 12, + ) + ], + ), + ), + ), + ], + ), + ), + AppState().isArabic(context) + ? Align( + alignment: Alignment.topRight, + child: SizedBox( + height: 20, + width: 35, + child: Transform.rotate( + angle: math.pi / 4.5, + child: Text( + LocaleKeys.brainMarathon.tr(), + textAlign: TextAlign.center, + maxLines: 2, + style: const TextStyle( + color: MyColors.white, + fontWeight: FontWeight.bold, + fontSize: 6, + height: 1.2, ), ), - AutoSizeText( - "Saudi Arabia", - style: TextStyle( - fontStyle: FontStyle.italic, - fontSize: 19, + ), + ), + ).paddingOnly(top: 5) + : Align( + alignment: Alignment.topLeft, + child: SizedBox( + height: 20, + width: 35, + child: Transform.rotate( + angle: -math.pi / 4.5, + child: Text( + LocaleKeys.brainMarathon.tr(), + textAlign: TextAlign.center, + maxLines: 2, + style: const TextStyle( + color: MyColors.kWhiteColor, fontWeight: FontWeight.bold, - color: MyColors.white.withOpacity(0.83), - height: 32 / 22, + fontSize: 6, + height: 1.2, ), ), - 3.height, - BuildCountdownTimer( - timeToMarathon: dummyEndTime, - provider: provider, - screenFlag: 0, - ), - ], - ).paddingOnly( - left: AppState().isArabic(context) ? 12 : 3, - right: AppState().isArabic(context) ? 3 : 12, - ) - ], - ), - ), - ), + ), + ), + ).paddingOnly(top: 5), + !AppState().isArabic(context) + ? Positioned( + right: 0, + bottom: 0, + child: RotatedBox( + quarterTurns: 4, + child: SvgPicture.asset("assets/images/arrow_next.svg", color: MyColors.whiteColor), + ).paddingAll(15), + ) + : Positioned( + bottom: 0, + left: 0, + child: RotatedBox( + quarterTurns: 2, + child: SvgPicture.asset("assets/images/arrow_next.svg", color: MyColors.whiteColor), + ).paddingAll(15), + ), ], + ).onPress( + () => Navigator.pushNamed(context, AppRoutes.marathonIntroScreen), ), - ), - Align( - alignment: Alignment.topLeft, - child: SizedBox( - height: 20, - width: 35, - child: Transform.rotate( - angle: -math.pi / 4.5, - child: Text( - LocaleKeys.brainMarathon.tr(), - textAlign: TextAlign.center, - maxLines: 2, - style: const TextStyle( - color: MyColors.kWhiteColor, - fontWeight: FontWeight.bold, - fontSize: 6, - height: 1.2, - ), - ), - ), - ), - ).paddingOnly(top: 5), - !AppState().isArabic(context) - ? Positioned( - right: 0, - bottom: 0, - child: RotatedBox( - quarterTurns: 4, - child: SvgPicture.asset("assets/images/arrow_next.svg", color: MyColors.whiteColor), - ).paddingAll(15), - ) - : Positioned( - bottom: 0, - left: 0, - child: RotatedBox( - quarterTurns: 2, - child: SvgPicture.asset("assets/images/arrow_next.svg", color: MyColors.whiteColor), - ).paddingAll(15), - ), - ], - ).onPress( - () => Navigator.pushNamed(context, AppRoutes.marathonIntroScreen), - ), - ); + ) + : const SizedBox(); } } diff --git a/lib/ui/marathon/widgets/marathon_header.dart b/lib/ui/marathon/widgets/marathon_header.dart index 0cc863b..fed6caa 100644 --- a/lib/ui/marathon/widgets/marathon_header.dart +++ b/lib/ui/marathon/widgets/marathon_header.dart @@ -28,8 +28,6 @@ class MarathonHeader extends StatelessWidget { color: MyColors.black, constraints: const BoxConstraints(), onPressed: () { - Provider.of(context, listen: false) - .resetValues(); Navigator.pop(context); }, ) diff --git a/lib/ui/marathon/widgets/question_card.dart b/lib/ui/marathon/widgets/question_card.dart index a3fe720..af538f8 100644 --- a/lib/ui/marathon/widgets/question_card.dart +++ b/lib/ui/marathon/widgets/question_card.dart @@ -1,89 +1,55 @@ import 'package:appinio_swiper/appinio_swiper.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; +import 'package:lottie/lottie.dart'; +import 'package:mohem_flutter_app/app_state/app_state.dart'; import 'package:mohem_flutter_app/classes/colors.dart'; import 'package:mohem_flutter_app/classes/decorations_helper.dart'; -import 'package:mohem_flutter_app/config/routes.dart'; +import 'package:mohem_flutter_app/classes/lottie_consts.dart'; +import 'package:mohem_flutter_app/extensions/int_extensions.dart'; +import 'package:mohem_flutter_app/extensions/string_extensions.dart'; import 'package:mohem_flutter_app/extensions/widget_extensions.dart'; -import 'package:mohem_flutter_app/models/marathon_question_model.dart'; +import 'package:mohem_flutter_app/models/marathon/question_model.dart'; import 'package:mohem_flutter_app/ui/marathon/marathon_provider.dart'; import 'package:provider/provider.dart'; -List isSelectedOptions = [ - false, - false, - false, - false, -]; - -class QuestionCard extends StatefulWidget { +class QuestionCard extends StatelessWidget { final MarathonProvider provider; const QuestionCard({Key? key, required this.provider}) : super(key: key); - @override - State createState() => _QuestionCardState(); -} - -class _QuestionCardState extends State { - final List questionCards = []; - - @override - void initState() { - _loadCards(); - super.initState(); - } - - void _loadCards() { - for (DummyQuestionModel question in questions) { - questionCards.add( - CardContent( - question: question, - provider: widget.provider, - ), - ); - } - } - @override Widget build(BuildContext context) { return CupertinoPageScaffold( - child: SizedBox( - height: 440, - width: double.infinity, - child: Consumer( - builder: (BuildContext context, MarathonProvider provider, _) { - return AppinioSwiper( - padding: EdgeInsets.zero, - isDisabled: true, - controller: provider.swiperController, - unswipe: (int index, AppinioSwiperDirection direction) {}, - cards: questionCards, - onSwipe: (int index, AppinioSwiperDirection direction) { - if (direction == AppinioSwiperDirection.left) { - provider.startTimer(context); - } - }, - ); - }, - ), - ), + child: provider.cardContentList.isEmpty + ? Lottie.asset(MyLottieConsts.hourGlassLottie, height: 250).paddingOnly(top: 50) + : SizedBox( + height: 440, + width: double.infinity, + child: Consumer( + builder: (BuildContext context, MarathonProvider provider, _) { + return AppinioSwiper( + duration: const Duration(milliseconds: 400), + padding: EdgeInsets.zero, + isDisabled: true, + controller: provider.swiperController, + unswipe: (int index, AppinioSwiperDirection direction) {}, + onSwipe: (int index, AppinioSwiperDirection direction) {}, + cards: provider.cardContentList, + ); + }, + ), + ), ); } } class CardContent extends StatelessWidget { - final DummyQuestionModel question; - final MarathonProvider provider; - - const CardContent({ - Key? key, - required this.question, - required this.provider, - }) : super(key: key); + const CardContent({Key? key}) : super(key: key); @override Widget build(BuildContext context) { + MarathonProvider provider = context.watch(); return Container( decoration: BoxDecoration( borderRadius: BorderRadius.circular(10), @@ -118,12 +84,12 @@ class CardContent extends StatelessWidget { topRight: Radius.circular(10), ), ), - child: const Center( + child: Center( child: Padding( - padding: EdgeInsets.symmetric(horizontal: 13), + padding: const EdgeInsets.symmetric(horizontal: 13), child: Text( - "What is the capital of Saudi Arabia?", - style: TextStyle( + AppState().isArabic(context) ? provider.currentQuestion.titleAr ?? "" : provider.currentQuestion.titleEn ?? "", + style: const TextStyle( color: MyColors.white, fontSize: 16, fontWeight: FontWeight.w600, @@ -132,49 +98,21 @@ class CardContent extends StatelessWidget { ), ), ), - AnswerContent(question: question, provider: provider), + const AnswerContent(), ], ), ); } } -class AnswerContent extends StatefulWidget { - final DummyQuestionModel question; - final MarathonProvider provider; - - const AnswerContent({Key? key, required this.question, required this.provider}) : super(key: key); - - @override - State createState() => _AnswerContentState(); -} - -class _AnswerContentState extends State { - void updateOption(int index, bool value) { - isSelectedOptions[0] = false; - isSelectedOptions[1] = false; - isSelectedOptions[2] = false; - isSelectedOptions[3] = false; - isSelectedOptions[index] = value; - setState(() {}); - } - - Decoration getContainerColor(int index) { - if (!isSelectedOptions[index]) { - return MyDecorations.getContainersDecoration(MyColors.greyF7Color); - } - if (isSelectedOptions[index] && context.watch().start > 0) { - return MyDecorations.getContainersDecoration(MyColors.yellowColorII); - } - return MyDecorations.getContainersDecoration( - isSelectedOptions[index] ? MyColors.greenColor : MyColors.greyF7Color, - ); - } +class AnswerContent extends StatelessWidget { + const AnswerContent({Key? key}) : super(key: key); @override Widget build(BuildContext context) { + MarathonProvider provider = context.watch(); return Container( - padding: const EdgeInsets.all(13), + padding: const EdgeInsets.symmetric(vertical: 31, horizontal: 13), decoration: const BoxDecoration( color: MyColors.kWhiteColor, borderRadius: BorderRadius.only( @@ -182,127 +120,48 @@ class _AnswerContentState extends State { bottomRight: Radius.circular(10), ), ), - child: Column( - mainAxisSize: MainAxisSize.min, - mainAxisAlignment: MainAxisAlignment.center, - crossAxisAlignment: CrossAxisAlignment.center, - children: [ - InkWell( - onTap: () { - if (widget.provider.currentQuestionNumber == 9) { - widget.provider.cancelTimer(); - widget.provider.resetValues(); - Navigator.pushReplacementNamed( - context, - AppRoutes.marathonWinnerSelection, - ); - return; - } - updateOption(0, true); - }, - child: Container( - alignment: Alignment.centerLeft, - decoration: getContainerColor(0), - child: Center( - child: Text( - widget.question.opt1!, - style: TextStyle( - color: isSelectedOptions[0] ? MyColors.white : MyColors.darkTextColor, - fontWeight: FontWeight.w600, - fontSize: 16, - ), - ).paddingOnly(top: 17, bottom: 17), - ), - ), - ), - const SizedBox(height: 15), - InkWell( - onTap: () { - if (widget.provider.currentQuestionNumber == 9) { - widget.provider.cancelTimer(); - widget.provider.resetValues(); - Navigator.pushReplacementNamed( - context, - AppRoutes.marathonWinnerSelection, - ); - return; - } - updateOption(1, true); - }, - child: Container( - alignment: Alignment.centerLeft, - decoration: getContainerColor(1), - child: Center( - child: Text( - widget.question.opt2!, - style: TextStyle( - color: isSelectedOptions[1] ? MyColors.white : MyColors.darkTextColor, - fontWeight: FontWeight.w600, - fontSize: 16, - ), - ).paddingOnly(top: 17, bottom: 17), - ), - ), - ), - const SizedBox(height: 15), - InkWell( - onTap: () { - if (widget.provider.currentQuestionNumber == 9) { - widget.provider.cancelTimer(); - widget.provider.resetValues(); - Navigator.pushReplacementNamed( - context, - AppRoutes.marathonWinnerSelection, - ); - return; - } - updateOption(2, true); - }, - child: Container( - alignment: Alignment.centerLeft, - decoration: getContainerColor(2), - child: Center( - child: Text( - widget.question.opt3!, - style: TextStyle( - color: isSelectedOptions[2] ? MyColors.white : MyColors.darkTextColor, - fontWeight: FontWeight.w600, - fontSize: 16, - ), - ).paddingOnly(top: 17, bottom: 17), - ), - ), - ), - const SizedBox(height: 15), - InkWell( - onTap: () { - if (widget.provider.currentQuestionNumber == 9) { - widget.provider.cancelTimer(); - widget.provider.resetValues(); - Navigator.pushReplacementNamed( - context, - AppRoutes.marathonWinnerSelection, + child: provider.currentQuestion.questionOptions != null + ? ListView.separated( + itemCount: provider.currentQuestion.questionOptions!.length, + shrinkWrap: true, + itemBuilder: (BuildContext context, int index) { + return AnswerTileForText( + index: index, + onAnswerTapped: () { + provider.updateCurrentQuestionOptionStatus(QuestionsOptionStatus.selected, index); + }, ); - return; - } - updateOption(3, true); - }, - child: Container( - alignment: Alignment.centerLeft, - decoration: getContainerColor(3), - child: Center( - child: Text( - widget.question.opt3!, - style: TextStyle( - color: isSelectedOptions[3] ? MyColors.white : MyColors.darkTextColor, - fontWeight: FontWeight.w600, - fontSize: 16, - ), - ).paddingOnly(top: 17, bottom: 17), - ), - ), - ), - ], + }, + separatorBuilder: (BuildContext context, int index) => 15.height, + ) + : const SizedBox(), + ); + } +} + +class AnswerTileForText extends StatelessWidget { + final int index; + final Function() onAnswerTapped; + + const AnswerTileForText({Key? key, required this.index, required this.onAnswerTapped}) : super(key: key); + + @override + Widget build(BuildContext context) { + MarathonProvider provider = context.watch(); + return InkWell( + onTap: () { + onAnswerTapped(); + }, + child: Container( + alignment: Alignment.centerLeft, + decoration: MyDecorations.getAnswersContainerColor(provider.currentQuestion.questionOptions![index].optionStatus!), + child: Center( + child: (AppState().isArabic(context) ? provider.currentQuestion.questionOptions![index].titleAr! : provider.currentQuestion.questionOptions![index].titleEn!) + .toText16( + color: provider.currentQuestion.questionOptions![index].optionStatus == QuestionsOptionStatus.unSelected ? MyColors.darkTextColor : MyColors.white, + ) + .paddingOnly(top: 17, bottom: 17), + ), ), ); } diff --git a/lib/ui/marathon/widgets/question_card_builder.dart b/lib/ui/marathon/widgets/question_card_builder.dart new file mode 100644 index 0000000..e4bce29 --- /dev/null +++ b/lib/ui/marathon/widgets/question_card_builder.dart @@ -0,0 +1,51 @@ +import 'package:flutter/material.dart'; +import 'package:mohem_flutter_app/models/marathon/question_model.dart'; + +class QuestionCardBuilder extends StatelessWidget { + final WidgetBuilder onQuestion; + final WidgetBuilder onCompleted; + final WidgetBuilder onWrongAnswer; + final WidgetBuilder onCorrectAnswer; + final WidgetBuilder onWinner; + final WidgetBuilder onSkippedAnswer; + final WidgetBuilder onFindingWinner; + final QuestionCardStatus questionCardStatus; + + const QuestionCardBuilder({ + Key? key, + required this.onQuestion, + required this.onCompleted, + required this.onCorrectAnswer, + required this.onWinner, + required this.onSkippedAnswer, + required this.onWrongAnswer, + required this.onFindingWinner, + required this.questionCardStatus, + }) : super(key: key); + + @override + Widget build(BuildContext context) { + switch (questionCardStatus) { + case QuestionCardStatus.question: + return onQuestion(context); + + case QuestionCardStatus.wrongAnswer: + return onWrongAnswer(context); + + case QuestionCardStatus.correctAnswer: + return onCorrectAnswer(context); + + case QuestionCardStatus.completed: + return onCompleted(context); + + case QuestionCardStatus.winnerFound: + return onWinner(context); + + case QuestionCardStatus.findingWinner: + return onFindingWinner(context); + + case QuestionCardStatus.skippedAnswer: + return onSkippedAnswer(context); + } + } +} diff --git a/lib/ui/misc/request_submit_screen.dart b/lib/ui/misc/request_submit_screen.dart index f5a2d1e..f05bacb 100644 --- a/lib/ui/misc/request_submit_screen.dart +++ b/lib/ui/misc/request_submit_screen.dart @@ -22,6 +22,7 @@ import 'package:mohem_flutter_app/widgets/button/default_button.dart'; import 'package:mohem_flutter_app/widgets/button/simple_button.dart'; import 'package:mohem_flutter_app/widgets/circular_avatar.dart'; import 'package:mohem_flutter_app/widgets/dialogs/confirm_dialog.dart'; +import 'package:mohem_flutter_app/widgets/image_picker.dart'; import 'package:mohem_flutter_app/widgets/input_widget.dart'; class RequestSubmitScreenParams { @@ -48,6 +49,7 @@ class _RequestSubmitScreenState extends State { List approverList = []; List attachmentFiles = []; + List attachments = []; @override void initState() { @@ -68,20 +70,20 @@ class _RequestSubmitScreenState extends State { } void submitRequest() async { - try { + try { Utils.showLoading(context); List> list = []; if (attachmentFiles.isNotEmpty) { - attachmentFiles.asMap().forEach((index, value) async { - String type = value.path.split('.').last; - String name = value.path.split('/').last; - List fileContent = await value.readAsBytes(); - String encodedFile = base64Encode(fileContent); + attachments.asMap().forEach((index, value) async { + String type = attachmentFiles[index].path.split('.').last; + String name = attachmentFiles[index].path.split('/').last; + // List fileContent = await value.readAsBytes(); + // String encodedFile = base64Encode(fileContent); list.add(AttachmentModel( attachmentID: index, pFILECONTENTTYPE: type, pFILENAME: name, - pFILEDATA: encodedFile, + pFILEDATA: value, pTRANSACTIONID: params!.transactionId, ).toJson()); }); @@ -129,7 +131,7 @@ class _RequestSubmitScreenState extends State { params!.pItemId, params!.transactionId, ); - }else if (params!.approvalFlag == 'endEmployment') { + } else if (params!.approvalFlag == 'endEmployment') { await TerminationDffApiClient().startTermApprovalProcess( "SUBMIT", comments.text, @@ -261,12 +263,18 @@ class _RequestSubmitScreenState extends State { title.toText16().expanded, 6.width, SimpleButton(LocaleKeys.add.tr(), () async { - FilePickerResult? result = await FilePicker.platform.pickFiles(allowMultiple: true); - if (result != null) { - attachmentFiles = attachmentFiles + result.paths.map((path) => File(path!)).toList(); - attachmentFiles = attachmentFiles.toSet().toList(); - setState(() {}); - } + ImageOptions.showImageOptionsNew(context, false, (String image, File file) { + setState(() { + attachmentFiles.add(file); + attachments.add(image); + Navigator.of(context).pop(); + }); + }); + // if (result != null) { + // attachmentFiles = attachmentFiles + result.paths.map((path) => File(path!)).toList(); + // attachmentFiles = attachmentFiles.toSet().toList(); + // setState(() {}); + // } }, fontSize: 14), ], ), diff --git a/lib/ui/my_attendance/dynamic_screens/dynamic_input_screen.dart b/lib/ui/my_attendance/dynamic_screens/dynamic_input_screen.dart index 1c86eb8..08d2be7 100644 --- a/lib/ui/my_attendance/dynamic_screens/dynamic_input_screen.dart +++ b/lib/ui/my_attendance/dynamic_screens/dynamic_input_screen.dart @@ -108,9 +108,11 @@ class _DynamicInputScreenState extends State { SubmitEITTransactionList submitEITTransactionList = await MyAttendanceApiClient().submitEitTransaction(dESCFLEXCONTEXTCODE, dynamicParams!.dynamicId, values, empID: dynamicParams!.selectedEmp ?? ''); Utils.hideLoading(context); - await Navigator.pushNamed(context, AppRoutes.requestSubmitScreen, + var res = await Navigator.pushNamed(context, AppRoutes.requestSubmitScreen, arguments: RequestSubmitScreenParams(LocaleKeys.submit.tr(), submitEITTransactionList.pTRANSACTIONID!, submitEITTransactionList.pITEMKEY!, 'eit')); - Utils.showLoading(context); + if (res != null && res == true) { + Utils.showLoading(context); + } await LeaveBalanceApiClient().cancelHrTransaction(submitEITTransactionList.pTRANSACTIONID!); Utils.hideLoading(context); } catch (ex) { diff --git a/lib/ui/my_team/subordinate_leave.dart b/lib/ui/my_team/subordinate_leave.dart index f08193c..e2fb999 100644 --- a/lib/ui/my_team/subordinate_leave.dart +++ b/lib/ui/my_team/subordinate_leave.dart @@ -99,7 +99,7 @@ class _SubordinateLeaveState extends State { itemBuilder: (BuildContext context, int index) { var diffDays = DateUtil.convertStringToDate(getSubordinatesLeavesTotalList[index].dATEEND!) .difference(DateUtil.convertStringToDate(getSubordinatesLeavesTotalList[index].dATESTART!)) - .inDays; + .inDays + 1; return Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ diff --git a/lib/ui/screens/announcements/announcements.dart b/lib/ui/screens/announcements/announcements.dart index d43c12c..941ff65 100644 --- a/lib/ui/screens/announcements/announcements.dart +++ b/lib/ui/screens/announcements/announcements.dart @@ -95,7 +95,7 @@ class _AnnouncementsState extends State { Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - (AppState().isArabic(context) ? _foundAnnouncements[index].titleAR! : getAnnouncementsObject[index].titleEN!).toText13(), + (AppState().isArabic(context) ? _foundAnnouncements[index].titleAR! : _foundAnnouncements[index].titleEN!).toText13(), 8.height, _foundAnnouncements[index].created!.toText10(color: MyColors.grey98Color) ], diff --git a/lib/ui/work_list/itg_detail_screen.dart b/lib/ui/work_list/itg_detail_screen.dart index cf33648..e123d22 100644 --- a/lib/ui/work_list/itg_detail_screen.dart +++ b/lib/ui/work_list/itg_detail_screen.dart @@ -35,6 +35,7 @@ class ItgDetailScreen extends StatefulWidget { class _ItgDetailScreenState extends State { int tabIndex = 0; + int animationIndex = 0; PageController controller = PageController(); bool showFabOptions = false; @@ -82,6 +83,7 @@ class _ItgDetailScreenState extends State { void getDataFromState() { if (requestDetails == null) { + animationIndex = animationIndex + 1; requestDetails = AppState().requestAllList![AppState().itgWorkListIndex!]; // ModalRoute.of(context)!.settings.arguments as WorkListResponseModel; providerData.itgFormsModel!.totalCount = providerData.itgFormsModel!.totalCount! - 1; getItgData(); @@ -95,151 +97,170 @@ class _ItgDetailScreenState extends State { return Scaffold( appBar: AppBarWidget(context, title: LocaleKeys.details.tr()), backgroundColor: Colors.white, - body: Stack( - children: [ - Column( - children: [ - Container( - padding: const EdgeInsets.only(left: 21, right: 21, top: 16, bottom: 16), - decoration: const BoxDecoration( - borderRadius: BorderRadius.only( - bottomLeft: Radius.circular(25), - bottomRight: Radius.circular(25), + body: AnimatedSwitcher( + duration: const Duration(milliseconds: 500), + switchInCurve: Curves.easeInToLinear, + transitionBuilder: (Widget child, Animation animation) { + Animation custom = Tween( + begin: const Offset(1.0, 0.0), + end: Offset.zero, + ).animate(animation); + return ClipRect( + child: SlideTransition( + position: custom, + child: child, + // textDirection: TextDirection.ltr, + ), + ); + }, + child: Stack( + key: ValueKey(animationIndex), + children: [ + Column( + children: [ + Container( + padding: const EdgeInsets.only(left: 21, right: 21, top: 16, bottom: 16), + decoration: const BoxDecoration( + borderRadius: BorderRadius.only( + bottomLeft: Radius.circular(25), + bottomRight: Radius.circular(25), + ), + gradient: LinearGradient( + transform: GradientRotation(.83), + begin: Alignment.topRight, + end: Alignment.bottomLeft, + colors: [ + MyColors.gradiantEndColor, + MyColors.gradiantStartColor, + ], + ), ), - gradient: LinearGradient( - transform: GradientRotation(.83), - begin: Alignment.topRight, - end: Alignment.bottomLeft, - colors: [ - MyColors.gradiantEndColor, - MyColors.gradiantStartColor, + child: Row( + children: [ + myTab(LocaleKeys.requestDetails.tr(), 0), + myTab(LocaleKeys.approvalLevel.tr(), 1), + myTab(LocaleKeys.requesterDetails.tr(), 2), ], ), ), - child: Row( + PageView( + controller: controller, + onPageChanged: (pageIndex) { + setState(() { + tabIndex = pageIndex; + }); + }, children: [ - myTab(LocaleKeys.requestDetails.tr(), 0), - myTab(LocaleKeys.approvalLevel.tr(), 1), - myTab(LocaleKeys.requesterDetails.tr(), 2), + RequestDetailFragment(fields: itgRequest?.fieldGoups?[1].fields ?? []), + ApprovalLevelfragment( + wFHistory: itgRequest?.wFHistory ?? [], + voidCallback: reloadITG, + ), + RequestDetailFragment(fields: itgRequest?.fieldGoups?[0].fields ?? []), ], - ), - ), - PageView( - controller: controller, - onPageChanged: (pageIndex) { - setState(() { - tabIndex = pageIndex; - }); - }, - children: [ - RequestDetailFragment(fields: itgRequest?.fieldGoups?[1].fields ?? []), - ApprovalLevelfragment( - wFHistory: itgRequest?.wFHistory ?? [], - voidCallback: reloadITG, - ), - RequestDetailFragment(fields: itgRequest?.fieldGoups?[0].fields ?? []), - ], - ).expanded, - if (isApproveAvailable || isRejectAvailable || isCloseAvailable) - Container( - padding: const EdgeInsets.only(top: 14, bottom: 14, left: 21, right: 21), - decoration: const BoxDecoration( - color: Colors.white, - border: Border( - top: BorderSide( - color: MyColors.lightGreyEFColor, - width: 1.0, + ).expanded, + if (isApproveAvailable || isRejectAvailable || isCloseAvailable) + Container( + padding: const EdgeInsets.only(top: 14, bottom: 14, left: 21, right: 21), + decoration: const BoxDecoration( + color: Colors.white, + border: Border( + top: BorderSide( + color: MyColors.lightGreyEFColor, + width: 1.0, + ), ), ), - ), - child: Row( + child: Row( + children: [ + if (isRejectAvailable) + DefaultButton( + LocaleKeys.reject.tr(), + () => performAction("REJECTED"), + colors: const [ + Color(0xffE47A7E), + Color(0xffDE6D71), + ], + ).expanded, + if (isApproveAvailable && isRejectAvailable) 8.width, + if (isApproveAvailable) + DefaultButton( + LocaleKeys.approve.tr(), + () => performAction("APPROVED"), + colors: const [ + Color(0xff28C884), + Color(0xff1BB271), + ], + ).expanded, + if (isCloseAvailable) + DefaultButton( + LocaleKeys.ok.tr(), + () => performAction("CLOSE"), + colors: const [ + Color(0xff32D892), + Color(0xff1AB170), + ], + ).expanded, + 8.width, + Container( + height: 43, + width: 43, + decoration: const BoxDecoration( + shape: BoxShape.circle, + color: MyColors.lightGreyE6Color, + ), + child: Icon(showFabOptions ? Icons.more_vert_rounded : Icons.more_horiz_rounded, color: MyColors.darkIconColor), + ).onPress(() { + setState(() { + showFabOptions = true; + }); + }) + ], + ), + ) + ], + ), + IgnorePointer( + ignoring: !showFabOptions, + child: AnimatedOpacity( + opacity: showFabOptions ? 1 : 0, + duration: const Duration(milliseconds: 250), + child: Container( + padding: const EdgeInsets.only(left: 21, right: 21, bottom: 75 - 12), + width: double.infinity, + height: double.infinity, + color: Colors.white.withOpacity(.67), + alignment: Alignment.bottomRight, + child: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.end, children: [ - if (isRejectAvailable) - DefaultButton( - LocaleKeys.reject.tr(), - () => performAction("REJECTED"), - colors: const [ - Color(0xffE47A7E), - Color(0xffDE6D71), - ], - ).expanded, - if (isApproveAvailable && isRejectAvailable) 8.width, - if (isApproveAvailable) - DefaultButton( - LocaleKeys.approve.tr(), - () => performAction("APPROVED"), - colors: const [ - Color(0xff28C884), - Color(0xff1BB271), - ], - ).expanded, - if (isCloseAvailable) - DefaultButton( - LocaleKeys.ok.tr(), - () => performAction("CLOSE"), - colors: const [ - Color(0xff32D892), - Color(0xff1AB170), - ], - ).expanded, - 8.width, - Container( - height: 43, - width: 43, - decoration: const BoxDecoration( - shape: BoxShape.circle, - color: MyColors.lightGreyE6Color, - ), - child: Icon(showFabOptions ? Icons.more_vert_rounded : Icons.more_horiz_rounded, color: MyColors.darkIconColor), - ).onPress(() { - setState(() { - showFabOptions = true; - }); - }) + myFab(LocaleKeys.skip.tr(), "assets/images/skip.svg").onPress(() { + if (AppState().requestAllList!.length - 1 > AppState().itgWorkListIndex!) { + animationIndex = animationIndex + 1; + AppState().itgWorkListIndex = AppState().itgWorkListIndex! + 1; + requestDetails = null; + itgRequest = null; + tabIndex = 0; + showFabOptions = false; + getDataFromState(); + } else if (AppState().requestAllList!.length - 1 == AppState().itgWorkListIndex!) { + Navigator.pop(context); + } + }), + 12.height, + ...viewApiButtonsList(allowedActionList), ], ), - ) - ], - ), - IgnorePointer( - ignoring: !showFabOptions, - child: AnimatedOpacity( - opacity: showFabOptions ? 1 : 0, - duration: const Duration(milliseconds: 250), - child: Container( - padding: const EdgeInsets.only(left: 21, right: 21, bottom: 75 - 12), - width: double.infinity, - height: double.infinity, - color: Colors.white.withOpacity(.67), - alignment: Alignment.bottomRight, - child: Column( - mainAxisSize: MainAxisSize.min, - crossAxisAlignment: CrossAxisAlignment.end, - children: [ - myFab(LocaleKeys.skip.tr(), "assets/images/skip.svg").onPress(() { - if (AppState().requestAllList!.length - 1 > AppState().itgWorkListIndex!) { - AppState().itgWorkListIndex = AppState().itgWorkListIndex! + 1; - requestDetails = null; - itgRequest = null; - tabIndex = 0; - showFabOptions = false; - getDataFromState(); - } else if (AppState().requestAllList!.length - 1 == AppState().itgWorkListIndex!) { - Navigator.pop(context); - } - }), - 12.height, - ...viewApiButtonsList(allowedActionList), - ], ), - ), - ).onPress(() { - setState(() { - showFabOptions = false; - }); - }), - ), - ], + ).onPress(() { + setState(() { + showFabOptions = false; + }); + }), + ), + ], + ), ), floatingActionButton: (!isApproveAvailable && !isRejectAvailable && !isCloseAvailable) ? Container( @@ -514,6 +535,7 @@ class _ItgDetailScreenState extends State { Utils.hideLoading(context); Utils.showToast(LocaleKeys.yourChangeHasBeenSavedSuccessfully.tr()); // Navigator.pop(context, "delegate_reload"); + animationIndex=animationIndex+1; AppState().requestAllList!.removeAt(AppState().itgWorkListIndex!); if (AppState().requestAllList!.isEmpty) { Navigator.pop(context, "delegate_reload"); @@ -534,9 +556,11 @@ class _ItgDetailScreenState extends State { void performDataCorrectionORReportGeneratedAction(String requestType, int taskId, int itemId, String employeeNumber) async { try { Utils.showLoading(context); + animationIndex = animationIndex + 1; ITGRequest? itgRequest = await WorkListApiClient().grantITGRequest(requestType, taskId, itemId, employeeNumber, "", ""); Utils.hideLoading(context); Utils.showToast(LocaleKeys.yourChangeHasBeenSavedSuccessfully.tr()); + AppState().requestAllList!.removeAt(AppState().itgWorkListIndex!); if (AppState().requestAllList!.isEmpty) { Navigator.pop(context, "delegate_reload"); @@ -555,6 +579,7 @@ class _ItgDetailScreenState extends State { } void reloadITG() { + animationIndex = animationIndex + 1; AppState().requestAllList!.removeAt(AppState().itgWorkListIndex!); if (AppState().requestAllList!.isEmpty) { Navigator.pop(context, "delegate_reload"); diff --git a/lib/ui/work_list/work_list_screen.dart b/lib/ui/work_list/work_list_screen.dart index f9f8d91..da1b60f 100644 --- a/lib/ui/work_list/work_list_screen.dart +++ b/lib/ui/work_list/work_list_screen.dart @@ -528,7 +528,7 @@ class _WorkListScreenState extends State { 10.height, Row( children: [ - DateUtil.formatDateToDate(DateUtil.convertSimpleStringDateToDate(workData.bEGINDATE!), false).toText10(color: MyColors.lightTextColor).expanded, + DateUtil.formatDateToDate(DateUtil.convertSimpleStringDateToDateddMMyyyy(workData.bEGINDATE!), false).toText10(color: MyColors.lightTextColor).expanded, RotatedBox(quarterTurns: AppState().isArabic(context) ? 2 : 4, child: SvgPicture.asset("assets/images/arrow_next.svg", color: MyColors.darkIconColor)), ], ), diff --git a/lib/ui/work_list/worklist_detail_screen.dart b/lib/ui/work_list/worklist_detail_screen.dart index 824edc3..8b22041 100644 --- a/lib/ui/work_list/worklist_detail_screen.dart +++ b/lib/ui/work_list/worklist_detail_screen.dart @@ -55,6 +55,7 @@ class WorkListDetailScreen extends StatefulWidget { class _WorkListDetailScreenState extends State { int tabIndex = 0; + int animationIndex = 0; PageController controller = PageController(); bool showFabOptions = false; @@ -146,7 +147,9 @@ class _WorkListDetailScreenState extends State { getPRNotification(); } - controller.jumpToPage(0); + if (controller.hasClients) { + controller.jumpToPage(0); + } // List dataToFetch = await Future.wait([ // @@ -187,173 +190,191 @@ class _WorkListDetailScreenState extends State { @override Widget build(BuildContext context) { getDataFromState(); - return Scaffold( appBar: AppBarWidget(context, title: LocaleKeys.details.tr()), backgroundColor: Colors.white, - body: Stack( - children: [ - Column( - children: [ - Container( - padding: const EdgeInsets.only(left: 21, right: 21, top: 16, bottom: 16), - decoration: const BoxDecoration( - borderRadius: BorderRadius.only( - bottomLeft: Radius.circular(25), - bottomRight: Radius.circular(25), - ), - gradient: LinearGradient( - transform: GradientRotation(.83), - begin: Alignment.topRight, - end: Alignment.bottomLeft, - colors: [ - MyColors.gradiantEndColor, - MyColors.gradiantStartColor, - ], - ), - ), - child: Row( - children: [ - myTab(LocaleKeys.info.tr(), 0), - (workListData!.iTEMTYPE == "HRSSA" || workListData!.iTEMTYPE == "STAMP") ? myTab(LocaleKeys.details.tr(), 1) : myTab(LocaleKeys.request.tr(), 1), - myTab(LocaleKeys.actions.tr(), 2), - myTab(LocaleKeys.attachments.tr(), 3), - ], - ), - ), - if ((workListData?.sUBJECT ?? "").isNotEmpty) workListData!.sUBJECT!.toText14().paddingOnly(top: 20, right: 21, left: 21), - PageView( - controller: controller, - onPageChanged: (pageIndex) { - setState(() { - tabIndex = pageIndex; - }); - }, - children: [ - InfoFragment( - poHeaderList: getPoNotificationBody?.pOHeader ?? [], - workListData: workListData, - itemCreationHeader: getItemCreationNtfBody?.itemCreationHeader ?? [], - getStampMsNotifications: getStampMsNotifications, - getStampNsNotifications: getStampNsNotifications, - getEitCollectionNotificationBodyList: getEitCollectionNotificationBodyList, - getPhonesNotificationBodyList: getPhonesNotificationBodyList, - getBasicDetNtfBodyList: getBasicDetNtfBodyList, - getAbsenceCollectionNotificationBodyList: getAbsenceCollectionNotificationBodyList, - getContactNotificationBodyList: getContactNotificationBodyList, - getPrNotificationBodyList: getPrNotificationBody, - ), - (workListData!.iTEMTYPE == "HRSSA" || workListData!.iTEMTYPE == "STAMP") - ? DetailFragment(workListData, memberInformationListModel) - : RequestFragment( - moNotificationBodyList: getMoNotificationBodyList, - poLinesList: getPoNotificationBody?.pOLines ?? [], - itemCreationLines: getItemCreationNtfBody?.itemCreationLines ?? [], - prLinesList: getPrNotificationBody?.pRLines ?? [], - ), - isActionHistoryLoaded - ? actionHistoryList.isEmpty - ? Utils.getNoDataWidget(context) - : ActionsFragment( - workListData!.nOTIFICATIONID, - actionHistoryList, - voidCallback: reloadWorkList, - ) - : showLoadingAnimation(), - isAttachmentLoaded - ? getAttachmentList.isEmpty - ? Utils.getNoDataWidget(context) - : AttachmentsFragment(getAttachmentList) - : showLoadingAnimation(), - ], - ).expanded, - if (isApproveAvailable || isRejectAvailable || isCloseAvailable) + body: AnimatedSwitcher( + duration: const Duration(milliseconds: 500), + switchInCurve: Curves.easeInToLinear, + transitionBuilder: (Widget child, Animation animation) { + Animation custom = Tween( + begin: const Offset(1.0, 0.0), + end: Offset.zero, + ).animate(animation); + return ClipRect( + child: SlideTransition( + position: custom, + child: child, + // textDirection: TextDirection.ltr, + ), + ); + }, + child: Stack( + key: ValueKey(animationIndex), + children: [ + Column( + children: [ Container( - padding: const EdgeInsets.only(top: 14, bottom: 14, left: 21, right: 21), + padding: const EdgeInsets.only(left: 21, right: 21, top: 16, bottom: 16), decoration: const BoxDecoration( - color: Colors.white, - border: Border( - top: BorderSide(color: MyColors.lightGreyEFColor, width: 1.0), + borderRadius: BorderRadius.only( + bottomLeft: Radius.circular(25), + bottomRight: Radius.circular(25), + ), + gradient: LinearGradient( + transform: GradientRotation(.83), + begin: Alignment.topRight, + end: Alignment.bottomLeft, + colors: [ + MyColors.gradiantEndColor, + MyColors.gradiantStartColor, + ], ), ), child: Row( children: [ - if (isRejectAvailable) - DefaultButton( - LocaleKeys.reject.tr(), - () => performAction("REJECTED"), - colors: const [Color(0xffE47A7E), Color(0xffDE6D71)], - ).expanded, - if (isApproveAvailable && isRejectAvailable) 8.width, - if (isApproveAvailable) - DefaultButton( - LocaleKeys.approve.tr(), - () => performAction("APPROVED"), - colors: const [Color(0xff28C884), Color(0xff1BB271)], - ).expanded, - if (isCloseAvailable) - DefaultButton( - LocaleKeys.ok.tr(), - () => performAction("CLOSE"), - colors: const [Color(0xff32D892), Color(0xff1AB170)], - ).expanded, - 8.width, - Container( - height: 43, - width: 43, - decoration: const BoxDecoration( - shape: BoxShape.circle, - color: MyColors.lightGreyE6Color, - ), - child: Icon(showFabOptions ? Icons.more_vert_rounded : Icons.more_horiz_rounded, color: MyColors.darkIconColor), - ).onPress(() { - setState(() { - showFabOptions = true; - }); - }) + (workListData!.iTEMTYPE == "HRSSA" || workListData!.iTEMTYPE == "STAMP") ? myTab(LocaleKeys.details.tr(), 0) : myTab(LocaleKeys.request.tr(), 0), + myTab(LocaleKeys.actions.tr(), 1), + myTab(LocaleKeys.info.tr(), 2), + myTab(LocaleKeys.attachments.tr(), 3), ], ), - ) - ], - ), - IgnorePointer( - ignoring: !showFabOptions, - child: AnimatedOpacity( - opacity: showFabOptions ? 1 : 0, - duration: const Duration(milliseconds: 250), - child: Container( - padding: const EdgeInsets.only(left: 21, right: 21, bottom: 75 - 12), - width: double.infinity, - height: double.infinity, - color: Colors.white.withOpacity(.67), - alignment: Alignment.bottomRight, - child: Column( - mainAxisSize: MainAxisSize.min, - crossAxisAlignment: CrossAxisAlignment.end, + ), + if ((workListData?.sUBJECT ?? "").isNotEmpty) workListData!.sUBJECT!.toText14().paddingOnly(top: 20, right: 21, left: 21), + PageView( + controller: controller, + onPageChanged: (pageIndex) { + setState(() { + tabIndex = pageIndex; + }); + }, children: [ - myFab(LocaleKeys.skip.tr(), "assets/images/skip.svg").onPress(() { - if (AppState().workList!.length - 1 > AppState().workListIndex!) { - AppState().setWorkListIndex = AppState().workListIndex! + 1; - workListData = null; - showFabOptions = false; - tabIndex = 0; - getDataFromState(); - } else if (AppState().workList!.length - 1 == AppState().workListIndex!) { - Navigator.pop(context); - } - }), - 12.height, - ...viewApiButtonsList(notificationButtonsList), + (workListData!.iTEMTYPE == "HRSSA" || workListData!.iTEMTYPE == "STAMP") + ? DetailFragment(workListData, memberInformationListModel) + : RequestFragment( + moNotificationBodyList: getMoNotificationBodyList, + poLinesList: getPoNotificationBody?.pOLines ?? [], + itemCreationLines: getItemCreationNtfBody?.itemCreationLines ?? [], + prLinesList: getPrNotificationBody?.pRLines ?? [], + ), + isActionHistoryLoaded + ? actionHistoryList.isEmpty + ? Utils.getNoDataWidget(context) + : ActionsFragment( + workListData!.nOTIFICATIONID, + actionHistoryList, + voidCallback: reloadWorkList, + ) + : showLoadingAnimation(), + InfoFragment( + poHeaderList: getPoNotificationBody?.pOHeader ?? [], + workListData: workListData, + itemCreationHeader: getItemCreationNtfBody?.itemCreationHeader ?? [], + getStampMsNotifications: getStampMsNotifications, + getStampNsNotifications: getStampNsNotifications, + getEitCollectionNotificationBodyList: getEitCollectionNotificationBodyList, + getPhonesNotificationBodyList: getPhonesNotificationBodyList, + getBasicDetNtfBodyList: getBasicDetNtfBodyList, + getAbsenceCollectionNotificationBodyList: getAbsenceCollectionNotificationBodyList, + getContactNotificationBodyList: getContactNotificationBodyList, + getPrNotificationBodyList: getPrNotificationBody, + ), + isAttachmentLoaded + ? getAttachmentList.isEmpty + ? Utils.getNoDataWidget(context) + : AttachmentsFragment(getAttachmentList) + : showLoadingAnimation(), ], + ).expanded, + if (isApproveAvailable || isRejectAvailable || isCloseAvailable) + Container( + padding: const EdgeInsets.only(top: 14, bottom: 14, left: 21, right: 21), + decoration: const BoxDecoration( + color: Colors.white, + border: Border( + top: BorderSide(color: MyColors.lightGreyEFColor, width: 1.0), + ), + ), + child: Row( + children: [ + if (isRejectAvailable) + DefaultButton( + LocaleKeys.reject.tr(), + () => performAction("REJECTED"), + colors: const [Color(0xffE47A7E), Color(0xffDE6D71)], + ).expanded, + if (isApproveAvailable && isRejectAvailable) 8.width, + if (isApproveAvailable) + DefaultButton( + LocaleKeys.approve.tr(), + () => performAction("APPROVED"), + colors: const [Color(0xff28C884), Color(0xff1BB271)], + ).expanded, + if (isCloseAvailable) + DefaultButton( + LocaleKeys.ok.tr(), + () => performAction("CLOSE"), + colors: const [Color(0xff32D892), Color(0xff1AB170)], + ).expanded, + 8.width, + Container( + height: 43, + width: 43, + decoration: const BoxDecoration( + shape: BoxShape.circle, + color: MyColors.lightGreyE6Color, + ), + child: Icon(showFabOptions ? Icons.more_vert_rounded : Icons.more_horiz_rounded, color: MyColors.darkIconColor), + ).onPress(() { + setState(() { + showFabOptions = true; + }); + }) + ], + ), + ) + ], + ), + IgnorePointer( + ignoring: !showFabOptions, + child: AnimatedOpacity( + opacity: showFabOptions ? 1 : 0, + duration: const Duration(milliseconds: 250), + child: Container( + padding: const EdgeInsets.only(left: 21, right: 21, bottom: 75 - 12), + width: double.infinity, + height: double.infinity, + color: Colors.white.withOpacity(.67), + alignment: Alignment.bottomRight, + child: Column( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.end, + children: [ + myFab(LocaleKeys.skip.tr(), "assets/images/skip.svg").onPress(() { + if (AppState().workList!.length - 1 > AppState().workListIndex!) { + animationIndex = animationIndex + 1; + AppState().setWorkListIndex = AppState().workListIndex! + 1; + workListData = null; + showFabOptions = false; + tabIndex = 0; + getDataFromState(); + } else if (AppState().workList!.length - 1 == AppState().workListIndex!) { + Navigator.pop(context); + } + }), + 12.height, + ...viewApiButtonsList(notificationButtonsList), + ], + ), ), - ), - ).onPress(() { - setState(() { - showFabOptions = false; - }); - }), - ), - ], + ).onPress(() { + setState(() { + showFabOptions = false; + }); + }), + ), + ], + ), ), floatingActionButton: (!isApproveAvailable && !isRejectAvailable && !isCloseAvailable) ? Container( @@ -667,6 +688,7 @@ class _WorkListDetailScreenState extends State { GenericResponseModel model = await WorkListApiClient().postNotificationActions(payload); Utils.hideLoading(context); Utils.showToast(LocaleKeys.yourChangeHasBeenSavedSuccessfully.tr()); + animationIndex=animationIndex+1; AppState().workList!.removeAt(AppState().workListIndex!); if (AppState().workList!.isEmpty) { Navigator.pop(context, "delegate_reload"); @@ -685,6 +707,7 @@ class _WorkListDetailScreenState extends State { } void reloadWorkList() { + animationIndex = animationIndex + 1; AppState().workList!.removeAt(AppState().workListIndex!); if (AppState().workList!.isEmpty) { Navigator.pop(context, "delegate_reload"); diff --git a/lib/ui/work_list/worklist_fragments/actions_fragment.dart b/lib/ui/work_list/worklist_fragments/actions_fragment.dart index fa29d65..98b5b72 100644 --- a/lib/ui/work_list/worklist_fragments/actions_fragment.dart +++ b/lib/ui/work_list/worklist_fragments/actions_fragment.dart @@ -147,15 +147,15 @@ class ActionsFragment extends StatelessWidget { if (actionHistoryList[index].aCTIONCODE == "SUBMIT") { return ""; } else if (actionHistoryList[index].aCTIONCODE == "PENDING") { - if (actionHistoryList[++index].nOTIFICATIONDATE!.isEmpty) { + if (actionHistoryList[index + 1].nOTIFICATIONDATE!.isEmpty) { return ""; } - DateTime dateTimeFrom = DateUtil.convertSimpleStringDateToDate(actionHistoryList[++index].nOTIFICATIONDATE!); + DateTime dateTimeFrom = DateUtil.convertSimpleStringDateToDate(actionHistoryList[index + 1].nOTIFICATIONDATE!); Duration duration = DateTime.now().difference(dateTimeFrom); return "Action duration: " + DateUtil.formatDuration(duration); } else { DateTime dateTimeTo = DateUtil.convertSimpleStringDateToDate(actionHistoryList[index].nOTIFICATIONDATE!); - DateTime dateTimeFrom = DateUtil.convertSimpleStringDateToDate(actionHistoryList[++index].nOTIFICATIONDATE!); + DateTime dateTimeFrom = DateUtil.convertSimpleStringDateToDate(actionHistoryList[index + 1].nOTIFICATIONDATE!); Duration duration = dateTimeTo.difference(dateTimeFrom); return "Action duration: " + DateUtil.formatDuration(duration); } diff --git a/lib/ui/work_list/worklist_fragments/detail_fragment.dart b/lib/ui/work_list/worklist_fragments/detail_fragment.dart index 43b5d7d..03e2272 100644 --- a/lib/ui/work_list/worklist_fragments/detail_fragment.dart +++ b/lib/ui/work_list/worklist_fragments/detail_fragment.dart @@ -46,6 +46,7 @@ class _DetailFragmentState extends State { ], ).objectContainerView(), 12.height, + widget.memberInformationListModel != null ? Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.min, @@ -69,7 +70,7 @@ class _DetailFragmentState extends State { isItLast: true, ), ], - ).objectContainerView(), + ).objectContainerView() : Container(), ], ).paddingAll(21), ); diff --git a/lib/widgets/app_bar_widget.dart b/lib/widgets/app_bar_widget.dart index c2129c1..6f0d7fd 100644 --- a/lib/widgets/app_bar_widget.dart +++ b/lib/widgets/app_bar_widget.dart @@ -5,6 +5,7 @@ import 'package:mohem_flutter_app/config/routes.dart'; import 'package:mohem_flutter_app/extensions/int_extensions.dart'; import 'package:mohem_flutter_app/extensions/string_extensions.dart'; import 'package:mohem_flutter_app/extensions/widget_extensions.dart'; +import 'package:mohem_flutter_app/widgets/circular_avatar.dart'; AppBar AppBarWidget(BuildContext context, {required String title, bool showHomeButton = true, bool showNotificationButton = false, bool showMemberButton = false, String? image, List? actions}) { @@ -25,10 +26,11 @@ AppBar AppBarWidget(BuildContext context, ), 4.width, if (image != null) - SvgPicture.asset( - image, + CircularAvatar( + url: image, height: 40, width: 40, + isImageBase64: true, ), if (image != null) 14.width, title.toText24(color: MyColors.darkTextColor, isBold: true).expanded, @@ -59,7 +61,7 @@ AppBar AppBarWidget(BuildContext context, }, icon: const Icon(Icons.people, color: MyColors.textMixColor), ), - ...actions??[] + ...actions ?? [] ], ); } diff --git a/lib/widgets/image_picker.dart b/lib/widgets/image_picker.dart index f92f9f4..69bf7e4 100644 --- a/lib/widgets/image_picker.dart +++ b/lib/widgets/image_picker.dart @@ -20,7 +20,7 @@ class ImageOptions { if (Platform.isAndroid) { cameraImageAndroid(image); } else { - File _image = File((await ImagePicker.platform.pickImage(source: ImageSource.camera, imageQuality: 20))?.path ?? ""); + File _image = File((await ImagePicker.platform.pickImage(source: ImageSource.camera, imageQuality: 10))?.path ?? ""); String fileName = _image.path; var bytes = File(fileName).readAsBytesSync(); String base64Encode = base64.encode(bytes); @@ -33,7 +33,7 @@ class ImageOptions { if (Platform.isAndroid) { galleryImageAndroid(image); } else { - File _image = File((await ImagePicker.platform.pickImage(source: ImageSource.gallery, imageQuality: 20))?.path ?? ""); + File _image = File((await ImagePicker.platform.pickImage(source: ImageSource.gallery, imageQuality: 10))?.path ?? ""); String fileName = _image.path; var bytes = File(fileName).readAsBytesSync(); String base64Encode = base64.encode(bytes); @@ -74,7 +74,7 @@ class ImageOptions { if (Platform.isAndroid) { galleryImageAndroid(image); } else { - File _image = File((await ImagePicker.platform.pickImage(source: ImageSource.gallery, imageQuality: 20))?.path ?? ""); + File _image = File((await ImagePicker.platform.pickImage(source: ImageSource.gallery, imageQuality: 10))?.path ?? ""); String fileName = _image.path; var bytes = File(fileName).readAsBytesSync(); String base64Encode = base64.encode(bytes); @@ -91,7 +91,7 @@ class ImageOptions { if (Platform.isAndroid) { cameraImageAndroid(image); } else { - File _image = File((await ImagePicker.platform.pickImage(source: ImageSource.camera, imageQuality: 20))?.path ?? ""); + File _image = File((await ImagePicker.platform.pickImage(source: ImageSource.camera, imageQuality: 10))?.path ?? ""); String fileName = _image.path; var bytes = File(fileName).readAsBytesSync(); String base64Encode = base64.encode(bytes); @@ -114,7 +114,7 @@ class ImageOptions { } void galleryImageAndroid(Function(String, File) image) async { - File _image = File((await ImagePicker.platform.pickImage(source: ImageSource.gallery, imageQuality: 20))?.path ?? ""); + File _image = File((await ImagePicker.platform.pickImage(source: ImageSource.gallery, imageQuality: 10))?.path ?? ""); String fileName = _image.path; var bytes = File(fileName).readAsBytesSync(); String base64Encode = base64.encode(bytes); @@ -124,7 +124,7 @@ void galleryImageAndroid(Function(String, File) image) async { } void cameraImageAndroid(Function(String, File) image) async { - File _image = File((await ImagePicker.platform.pickImage(source: ImageSource.camera, imageQuality: 20))?.path ?? ""); + File _image = File((await ImagePicker.platform.pickImage(source: ImageSource.camera, imageQuality: 10))?.path ?? ""); String fileName = _image.path; var bytes = File(fileName).readAsBytesSync(); String base64Encode = base64.encode(bytes); diff --git a/lib/widgets/mark_attendance_widget.dart b/lib/widgets/mark_attendance_widget.dart index c41b89c..a6b6cfc 100644 --- a/lib/widgets/mark_attendance_widget.dart +++ b/lib/widgets/mark_attendance_widget.dart @@ -14,6 +14,7 @@ import 'package:mohem_flutter_app/generated/locale_keys.g.dart'; import 'package:mohem_flutter_app/models/generic_response_model.dart'; import 'package:mohem_flutter_app/provider/dashboard_provider_model.dart'; import 'package:mohem_flutter_app/ui/dialogs/success_dialog.dart'; +import 'package:mohem_flutter_app/widgets/dialogs/confirm_dialog.dart'; import 'package:mohem_flutter_app/widgets/dialogs/dialogs.dart'; import 'package:mohem_flutter_app/widgets/location/Location.dart'; import 'package:mohem_flutter_app/widgets/nfc/nfc_reader_sheet.dart'; @@ -144,14 +145,28 @@ class _MarkAttendanceWidgetState extends State { Utils.showLoading(context); try { GenericResponseModel? g = await DashboardApiClient().markAttendance(pointType: 2, nfcValue: nfcId, isGpsRequired: isNfcLocationEnabled, lat: lat, long: lng); - bool status = await model.fetchAttendanceTracking(context); - Utils.hideLoading(context); - showMDialog( - context, - backgroundColor: Colors.transparent, - isDismissable: false, - child: SuccessDialog(widget.isFromDashboard), - ); + if(g?.messageStatus != 1) { + Utils.hideLoading(context); + showDialog( + context: context, + builder: (cxt) => ConfirmDialog( + message: g?.errorEndUserMessage ?? "Unexpected error occurred", + onTap: () { + Navigator.pop(context); + }, + ), + ); + } else { + bool status = await model.fetchAttendanceTracking(context); + Utils.hideLoading(context); + showMDialog( + context, + backgroundColor: Colors.transparent, + isDismissable: false, + child: SuccessDialog(widget.isFromDashboard), + ); + } + } catch (ex) { print(ex); Utils.hideLoading(context); @@ -166,14 +181,27 @@ class _MarkAttendanceWidgetState extends State { Utils.showLoading(context); try { GenericResponseModel? g = await DashboardApiClient().markAttendance(pointType: 2, nfcValue: nfcId ?? "", isGpsRequired: isNfcLocationEnabled, lat: lat, long: lng); - bool status = await model.fetchAttendanceTracking(context); - Utils.hideLoading(context); - showMDialog( - context, - backgroundColor: Colors.transparent, - isDismissable: false, - child: SuccessDialog(widget.isFromDashboard), - ); + if(g?.messageStatus != 1) { + Utils.hideLoading(context); + showDialog( + context: context, + builder: (cxt) => ConfirmDialog( + message: g?.errorEndUserMessage ?? "Unexpected error occurred", + onTap: () { + Navigator.pop(context); + }, + ), + ); + } else { + bool status = await model.fetchAttendanceTracking(context); + Utils.hideLoading(context); + showMDialog( + context, + backgroundColor: Colors.transparent, + isDismissable: false, + child: SuccessDialog(widget.isFromDashboard), + ); + } } catch (ex) { print(ex); Utils.hideLoading(context); diff --git a/lib/widgets/shimmer/dashboard_shimmer_widget.dart b/lib/widgets/shimmer/dashboard_shimmer_widget.dart index 369b808..fc243f0 100644 --- a/lib/widgets/shimmer/dashboard_shimmer_widget.dart +++ b/lib/widgets/shimmer/dashboard_shimmer_widget.dart @@ -188,7 +188,58 @@ class ServicesMenuShimmer extends StatelessWidget { } } +class MarathonBannerShimmer extends StatelessWidget { + const MarathonBannerShimmer({Key? key}) : super(key: key); + + @override + Widget build(BuildContext context) { + return Container( + decoration: BoxDecoration( + color: Colors.white, + borderRadius: BorderRadius.circular(15), + boxShadow: [ + BoxShadow( + color: const Color(0xff000000).withOpacity(.05), + blurRadius: 26, + offset: const Offset(0, -3), + ), + ], + ), + child: Column( + mainAxisAlignment: MainAxisAlignment.spaceBetween, + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + SvgPicture.asset("assets/images/monthly_attendance.svg").toShimmer(), + Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisAlignment: MainAxisAlignment.start, + children: [ + "Attendan".toText11(isBold: false).toShimmer(), + 5.height, + Row( + crossAxisAlignment: CrossAxisAlignment.end, + children: [ + Expanded( + child: LocaleKeys.attendance.tr().toText11(isBold: false).toShimmer(), + ), + 6.width, + SvgPicture.asset("assets/images/arrow_next.svg").paddingOnly(bottom: 4).toShimmer() + ], + ), + ], + ) + ], + ).paddingOnly(left: 10, right: 10, bottom: 10, top: 12), + ); + } +} + class ChatHomeShimmer extends StatelessWidget { + bool isDetailedScreen; + + ChatHomeShimmer({Key? key, required this.isDetailedScreen}) : super(key: key); + + @override @override Widget build(BuildContext context) { return Container( @@ -207,42 +258,42 @@ class ChatHomeShimmer extends StatelessWidget { child: Row( crossAxisAlignment: CrossAxisAlignment.start, children: [ - Container( - width: 48.0, - height: 48.0, - decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.all(Radius.circular(40))), - ), - const Padding( - padding: EdgeInsets.symmetric(horizontal: 8.0), - ), - Expanded( - child: Column( - crossAxisAlignment: CrossAxisAlignment.start, - children: [ - Container( - width: double.infinity, - height: 8.0, - color: Colors.white, - ), - const Padding( - padding: EdgeInsets.symmetric(vertical: 2.0), - ), - Container( - width: double.infinity, - height: 8.0, - color: Colors.white, - ), - const Padding( - padding: EdgeInsets.symmetric(vertical: 2.0), - ), - Container( - width: 40.0, - height: 8.0, - color: Colors.white, - ), - ], + if (!isDetailedScreen) + Container( + width: 48.0, + height: 48.0, + decoration: const BoxDecoration(color: Colors.white, borderRadius: BorderRadius.all(Radius.circular(40))), + ), + if (!isDetailedScreen) + const Padding( + padding: EdgeInsets.symmetric(horizontal: 8.0), ), - ) + Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Container( + width: double.infinity, + height: 8.0, + color: Colors.white, + ), + const Padding( + padding: EdgeInsets.symmetric(vertical: 2.0), + ), + Container( + width: double.infinity, + height: 8.0, + color: Colors.white, + ), + const Padding( + padding: EdgeInsets.symmetric(vertical: 2.0), + ), + Container( + width: 40.0, + height: 8.0, + color: Colors.white, + ), + ], + ).expanded ], ), ), diff --git a/pubspec.yaml b/pubspec.yaml index f5742bb..4fc00c8 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -79,13 +79,12 @@ dependencies: pull_to_refresh: ^2.0.0 # lottie json animations lottie: any -# Steps Progress - steps_indicator: ^1.3.0 # Marathon Card Swipe appinio_swiper: ^1.1.1 expandable: ^5.0.1 - +# networkImage + cached_network_image: ^3.2.2 #Chat signalr_netcore: ^1.3.3 @@ -94,8 +93,8 @@ dependencies: flutter_webrtc: ^0.9.16 camera: ^0.10.0+4 - - + #Encryption + flutter_des: ^2.1.0 video_player: ^2.4.7 just_audio: ^0.9.30