From f6f801f9cff59303cc5675677fa5a7710adc5e4a Mon Sep 17 00:00:00 2001 From: "Aamir.Muhammad" Date: Sun, 4 Dec 2022 16:15:47 +0300 Subject: [PATCH] Chat Fixes & User Chat Counter --- lib/classes/consts.dart | 4 +- lib/classes/encryption.dart | 188 ++++++++++++++++++ lib/provider/chat_provider_model.dart | 17 +- lib/provider/dashboard_provider_model.dart | 20 +- lib/ui/chat/chat_bubble.dart | 32 ++- lib/ui/chat/chat_full_image_preview.dart | 57 +++--- lib/ui/chat/chat_home_screen.dart | 142 +------------ lib/ui/landing/dashboard_screen.dart | 11 + .../itg/its_add_screen_video_image.dart | 37 ++-- pubspec.yaml | 5 - 10 files changed, 304 insertions(+), 209 deletions(-) create mode 100644 lib/classes/encryption.dart diff --git a/lib/classes/consts.dart b/lib/classes/consts.dart index 13c4258..841f29c 100644 --- a/lib/classes/consts.dart +++ b/lib/classes/consts.dart @@ -3,7 +3,7 @@ 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/"; @@ -12,8 +12,6 @@ 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/"; diff --git a/lib/classes/encryption.dart b/lib/classes/encryption.dart new file mode 100644 index 0000000..67466fe --- /dev/null +++ b/lib/classes/encryption.dart @@ -0,0 +1,188 @@ +// import 'dart:convert'; +// +// import 'package:encrypt/encrypt.dart'; +// import 'package:crypto/crypto.dart'; +// +// class Encryption { +// static final Encryption instance = Encryption._(); +// +// late IV _iv; +// late Encrypter _encrypter; +// +// Encryption._() { +// const mykey = 'PeShVmYp'; +// const myiv = 'j70IbWYn'; +// var keyUtf8 = utf8.encode(mykey); +// var ivUtf8 = utf8.encode(myiv); +// var key = sha256.convert(keyUtf8).toString().substring(0, 32); +// var iv = sha256.convert(ivUtf8).toString().substring(0, 16); +// _iv = IV.fromUtf8(iv); +// +// _encrypter = Encrypter(AES(Key.fromUtf8(key), mode: AESMode.cbc)); +// } +// +// String encrypt(String value) { +// return _encrypter.encrypt(value, iv: _iv).base64; +// } +// +// String decrypt(String base64value) { +// var encrypted = Encrypted.fromBase64(base64value); +// return _encrypter.decrypt(encrypted, iv: _iv); +// } +// +// // +// // void passEncrypt(String text, String pass) async { +// // var salt = randomUint8List(8); +// // var keyndIV = deriveKeyAndIV(pass, salt); +// // var key = encrypt.Key(keyndIV.item1); +// // var iv = encrypt.IV(keyndIV.item2); +// // var encrypter = encrypt.Encrypter(encrypt.AES(key, mode: encrypt.AESMode.cbc, padding: "PKCS7")); +// // var encrypted = encrypter.encrypt(text, iv: iv); +// // Uint8List encryptedBytesWithSalt = Uint8List.fromList(createUint8ListFromString("Salted__") + salt + encrypted.bytes); +// // var resulttt = base64.encode(encryptedBytesWithSalt); +// // print("Enc : " + resulttt); +// // +// // decryptAESCryptoJS(resulttt, pass); +// // } +// // +// // Uint8List randomUint8List(int length) { +// // assert(length > 0); +// // var random = Random(); +// // var ret = Uint8List(length); +// // for (var i = 0; i < length; i++) { +// // ret[i] = random.nextInt(256); +// // } +// // return ret; +// // } +// // +// // void decryptAESCryptoJS(String encrypted, String passphrase) { +// // try { +// // Uint8List encryptedBytesWithSalt = base64.decode(encrypted); +// // Uint8List encryptedBytes = encryptedBytesWithSalt.sublist(16, encryptedBytesWithSalt.length); +// // var salt = encryptedBytesWithSalt.sublist(8, 16); +// // var keyndIV = deriveKeyAndIV(passphrase, salt); +// // var key = encrypt.Key(keyndIV.item1); +// // var iv = encrypt.IV(keyndIV.item2); +// // var encrypter = encrypt.Encrypter(encrypt.AES(key, mode: encrypt.AESMode.cbc, padding: "PKCS7")); +// // var decrypted = encrypter.decrypt64(base64.encode(encryptedBytes), iv: iv); +// // print("Dec : " + decrypted); +// // // return decrypted; +// // } catch (error) { +// // throw error; +// // } +// // } +// // +// // Future enc(String input) async { +// // var ekey = "PeShVmYpPeShVmYp"; +// // var eIV = "j70IbWYnj70IbWYn"; +// // +// // var abc = Encryption.instance.encrypt(input); +// // // +// // // var inputByt = utf8.encode(input); +// // // final encrypted = encrypter.encrypt(plainText); +// // // final decrypted = encrypter.decrypt(encrypted); +// // // +// // // print(decrypted); // Lorem ipsum dolor sit amet, consectetur adipiscing elit +// // // print(encrypted.base64); // R4PxiU3h8YoIRqVowBXm36ZcCeNeZ4s1OvVBTfFlZRdmohQqOpPQqD1YecJeZMAop/hZ4OxqgC1WtwvX/hP9mw== +// // // /// +// // +// // var key = encrypt.Key.fromUtf8(ekey.substring(0, 8)); +// // var iv = encrypt.IV.fromLength(8); +// // var encrypter = Encrypter(AES(key)); +// // var encrypted = encrypter.encrypt(input, iv: iv); +// // var decrypted = encrypter.decrypt(encrypted, iv: iv); +// // print("====== ORI =========="); +// // print("e4PTDencHsiLJv0XcbT2I4tafb7dqJP9c72PEnhp1Uv6U2GZ/gODtA=="); +// // print("====== ENC =========="); +// // print(encrypted.base64); +// // print("====== DEC =========="); +// // print(decrypted); +// // print("====== B64 =========="); +// // String bs64 = base64.encode(utf8.encode(input)); +// // print(bs64); +// // +// // // try { +// // // var cipher = _cipher; +// // // var secretBox = await cipher.encrypt( +// // // iByt, +// // // secretKey: SecretKeyData(eByt), +// // // nonce: eIvByt, +// // // ); +// // // print(utf8.decode(secretBox.cipherText)); +// // // } catch (error) { +// // // print(error); +// // // return; +// // // } +// // } +// // ///Accepts encrypted data and decrypt it. Returns plain text +// // String decryptWithAES(String key, Encrypted encryptedData) { +// // var cipherKey = encrypt.Key.fromUtf8(key); +// // var encryptService = Encrypter(AES(cipherKey, mode: AESMode.cbc,padding: null)); +// // var initVector = IV.fromUtf8(key.substring(0, 16)); +// // return encryptService.decrypt(encryptedData, iv: initVector); +// // } +// // +// // ///Encrypts the given plainText using the key. Returns encrypted data +// // Encrypted encryptWithAES(String key, String plainText) { +// // var cipherKey = encrypt.Key.fromUtf8(key); +// // var encryptService = Encrypter(AES(cipherKey, mode: AESMode.cbc,padding: null)); +// // var initVector = IV.fromUtf8("j70IbWYn"); +// // Encrypted encryptedData = encryptService.encrypt(plainText, iv: initVector); +// // print(encryptedData.base64); +// // return encryptedData; +// // } +// // +// // Tuple2 deriveKeyAndIV(String passphrase, Uint8List salt) { +// // var password = createUint8ListFromString(passphrase); +// // Uint8List concatenatedHashes = Uint8List(0); +// // Uint8List currentHash = Uint8List(0); +// // bool enoughBytesForKey = false; +// // Uint8List preHash = Uint8List(0); +// // +// // while (!enoughBytesForKey) { +// // int preHashLength = currentHash.length + password.length + salt.length; +// // if (currentHash.length > 0) +// // preHash = Uint8List.fromList(currentHash + password + salt); +// // else +// // preHash = Uint8List.fromList(password + salt); +// // +// // currentHash = preHash; +// // concatenatedHashes = Uint8List.fromList(concatenatedHashes + currentHash); +// // if (concatenatedHashes.length >= 48) enoughBytesForKey = true; +// // } +// // +// // var keyBtyes = concatenatedHashes.sublist(0, 32); +// // var ivBtyes = concatenatedHashes.sublist(32, 48); +// // return new Tuple2(keyBtyes, ivBtyes); +// // } +// // +// // Uint8List createUint8ListFromString(String s) { +// // var ret = new Uint8List(s.length); +// // for (var i = 0; i < s.length; i++) { +// // ret[i] = s.codeUnitAt(i); +// // } +// // return ret; +// // } +// // +// // Uint8List genRandomWithNonZero(int seedLength) { +// // var random = Random.secure(); +// // const int randomMax = 245; +// // Uint8List uint8list = Uint8List(seedLength); +// // for (int i = 0; i < seedLength; i++) { +// // uint8list[i] = random.nextInt(randomMax) + 1; +// // } +// // return uint8list; +// // } +// // +// // +// // +// // void test(String text, String kk) { +// // Uint8List key = Uint8List.fromList(utf8.encode(kk)); +// // PaddedBlockCipher cipher = exp.PaddedBlockCipherImpl(exp.PKCS7Padding(), exp.ECBBlockCipher(exp.AESEngine())); +// // cipher.init(true, PaddedBlockCipherParameters(KeyParameter(key), null)); +// // var byte = Uint8List.fromList(utf8.encode(text)); +// // var data = cipher.process(byte); +// // print(data); +// // } +// +// } diff --git a/lib/provider/chat_provider_model.dart b/lib/provider/chat_provider_model.dart index f3821f3..886951c 100644 --- a/lib/provider/chat_provider_model.dart +++ b/lib/provider/chat_provider_model.dart @@ -120,7 +120,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { if (element.isSeen != null) { if (!element.isSeen!) { print("Found Un Read"); - logger.d(jsonEncode(element)); + element.isSeen = true; dynamic data = [ {"userChatHistoryId": element.userChatHistoryId, "TargetUserId": element.targetUserId, "isDelivered": true, "isSeen": true} ]; @@ -131,9 +131,10 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { for (ChatUser element in searchedChats!) { if (element.id == receiverID) { element.unreadMessageCount = 0; - notifyListeners(); + // notifyListeners(); } } + notifyListeners(); } } @@ -223,7 +224,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) { @@ -288,8 +288,16 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { } userChatHistory.insert(0, data.first); + if (searchedChats != null) { + for (ChatUser user in searchedChats!) { + if (user.id == data.first.currentUserId) { + var tempCount = user.unreadMessageCount ?? 0; + user.unreadMessageCount = tempCount + 1; + } + } + } - var list = [ + List list = [ {"userChatHistoryId": data.first.userChatHistoryId, "TargetUserId": temp.first.targetUserId, "isDelivered": true, "isSeen": isChatScreenActive ? true : false} ]; updateUserChatHistoryOnMsg(list); @@ -624,7 +632,6 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin { } void clearSelections() { - print("Hereee i am "); searchedChats = pChatHistory; search.clear(); isChatScreenActive = false; diff --git a/lib/provider/dashboard_provider_model.dart b/lib/provider/dashboard_provider_model.dart index 59b62b6..461196f 100644 --- a/lib/provider/dashboard_provider_model.dart +++ b/lib/provider/dashboard_provider_model.dart @@ -307,13 +307,21 @@ class DashboardProviderModel with ChangeNotifier, DiagnosticableTreeMixin { 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; + 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 notify() { notifyListeners(); } diff --git a/lib/ui/chat/chat_bubble.dart b/lib/ui/chat/chat_bubble.dart index 8995da1..ec772f6 100644 --- a/lib/ui/chat/chat_bubble.dart +++ b/lib/ui/chat/chat_bubble.dart @@ -28,6 +28,7 @@ class ChatBubble extends StatelessWidget { String? fileTypeDescription; bool isDelivered = false; String userName = ''; + late Offset screenOffset; void makeAssign() { isCurrentUser = cItem.currentUserId == AppState().chatDetails!.response!.id ? true : false; @@ -41,6 +42,8 @@ class ChatBubble extends StatelessWidget { @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); } @@ -108,7 +111,11 @@ class ChatBubble extends StatelessWidget { ).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, builder: (BuildContext context) => ChatImagePreviewScreen(imgTitle: cItem.contant!, img: cItem.image!)); + showDialog( + context: context, + anchorPoint: screenOffset, + builder: (BuildContext context) => ChatImagePreviewScreen(imgTitle: cItem.contant!, img: cItem.image!), + ); }), cItem.contant!.toText12(), Align( @@ -172,23 +179,28 @@ class ChatBubble extends StatelessWidget { 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")), + 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, builder: (BuildContext context) => ChatImagePreviewScreen(imgTitle: cItem.contant!, img: cItem.image!)); + 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), + (cItem.contant ?? "").toText12(color: Colors.white), Align( alignment: Alignment.centerRight, child: dateTime.toText10(color: Colors.white.withOpacity(.71)), diff --git a/lib/ui/chat/chat_full_image_preview.dart b/lib/ui/chat/chat_full_image_preview.dart index 26364c5..c731c25 100644 --- a/lib/ui/chat/chat_full_image_preview.dart +++ b/lib/ui/chat/chat_full_image_preview.dart @@ -12,29 +12,40 @@ class ChatImagePreviewScreen extends StatelessWidget { @override Widget build(BuildContext context) { - return GestureDetector( - onTap: () { - Navigator.of(context).pop(); - }, - child: Dialog( - backgroundColor: Colors.transparent, - insetPadding: const EdgeInsets.all(10), - child: Stack( - alignment: Alignment.center, - children: [ - Image.memory( - img, - fit: BoxFit.cover, - height: 400, - width: double.infinity, - ).paddingAll(10), - const Positioned( - right: 0, - top: 0, - child: Icon(Icons.cancel, color: MyColors.redA3Color, size: 35), - ) - ], - ), + return Dialog( + backgroundColor: Colors.transparent, + insetPadding: const EdgeInsets.all(10), + child: Stack( + alignment: Alignment.center, + fit: StackFit.loose, + children: [ + Image.memory( + img, + fit: BoxFit.cover, + height: 400, + width: double.infinity, + ).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_screen.dart b/lib/ui/chat/chat_home_screen.dart index cd2245d..e2f2dc2 100644 --- a/lib/ui/chat/chat_home_screen.dart +++ b/lib/ui/chat/chat_home_screen.dart @@ -63,7 +63,7 @@ class _ChatHomeScreenState extends State { hintText: LocaleKeys.searchfromchat.tr(), hintStyle: const TextStyle(color: MyColors.lightTextColor, fontStyle: FontStyle.italic, fontWeight: FontWeight.w500, fontSize: 12), filled: true, - fillColor: const Color(0xFFF7F7F7), + fillColor: MyColors.greyF7Color, suffixIconConstraints: const BoxConstraints(), suffixIcon: m.search.text.isNotEmpty ? IconButton( @@ -83,7 +83,6 @@ class _ChatHomeScreenState extends State { shrinkWrap: true, physics: const ClampingScrollPhysics(), itemBuilder: (BuildContext context, int index) { - // todo @aamir, remove list tile, make a custom ui instead return SizedBox( height: 55, child: Row( @@ -103,11 +102,8 @@ class _ChatHomeScreenState extends State { height: 10, decoration: BoxDecoration( color: m.searchedChats![index].userStatus == 1 ? MyColors.green2DColor : Colors.red, - borderRadius: const BorderRadius.all( - Radius.circular(10), - ), ), - ), + ).circle(10), ) ], ), @@ -211,9 +207,6 @@ class _ChatHomeScreenState extends State { ), ), onPressed: () async { - // String plainText = 'Muhamad.Alam@cloudsolutions.com.sa'; - // String key = "PeShVmYp"; - // passEncrypt(plainText, "PeShVmYp"); showMyBottomSheet( context, callBackFunc: () {}, @@ -231,137 +224,10 @@ 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), ), ); } - // - // void passEncrypt(String text, String pass) async { - // var salt = randomUint8List(8); - // var keyndIV = deriveKeyAndIV(pass, salt); - // var key = encrypt.Key(keyndIV.item1); - // var iv = encrypt.IV(keyndIV.item2); - // var encrypter = encrypt.Encrypter(encrypt.AES(key, mode: encrypt.AESMode.cbc, padding: "PKCS7")); - // var encrypted = encrypter.encrypt(text, iv: iv); - // Uint8List encryptedBytesWithSalt = Uint8List.fromList(createUint8ListFromString("Salted__") + salt + encrypted.bytes); - // var resulttt = base64.encode(encryptedBytesWithSalt); - // print("Enc : " + resulttt); - // - // decryptAESCryptoJS(resulttt, pass); - // } - // - // Uint8List randomUint8List(int length) { - // assert(length > 0); - // var random = Random(); - // var ret = Uint8List(length); - // for (var i = 0; i < length; i++) { - // ret[i] = random.nextInt(256); - // } - // return ret; - // } - // - // void decryptAESCryptoJS(String encrypted, String passphrase) { - // try { - // Uint8List encryptedBytesWithSalt = base64.decode(encrypted); - // Uint8List encryptedBytes = encryptedBytesWithSalt.sublist(16, encryptedBytesWithSalt.length); - // var salt = encryptedBytesWithSalt.sublist(8, 16); - // var keyndIV = deriveKeyAndIV(passphrase, salt); - // var key = encrypt.Key(keyndIV.item1); - // var iv = encrypt.IV(keyndIV.item2); - // var encrypter = encrypt.Encrypter(encrypt.AES(key, mode: encrypt.AESMode.cbc, padding: "PKCS7")); - // var decrypted = encrypter.decrypt64(base64.encode(encryptedBytes), iv: iv); - // print("Dec : " + decrypted); - // // return decrypted; - // } catch (error) { - // throw error; - // } - // } - - void enc(String input) { - var ekey = "PeShVmYp"; - var eIV = "j70IbWYn"; - List eByt = utf8.encode(ekey); - List eIvByt = utf8.encode(eIV); - List iByt = utf8.encode(input); - - - - } - - // ///Accepts encrypted data and decrypt it. Returns plain text - // String decryptWithAES(String key, Encrypted encryptedData) { - // var cipherKey = encrypt.Key.fromUtf8(key); - // var encryptService = Encrypter(AES(cipherKey, mode: AESMode.cbc,padding: null)); - // var initVector = IV.fromUtf8(key.substring(0, 16)); - // return encryptService.decrypt(encryptedData, iv: initVector); - // } - // - // ///Encrypts the given plainText using the key. Returns encrypted data - // Encrypted encryptWithAES(String key, String plainText) { - // var cipherKey = encrypt.Key.fromUtf8(key); - // var encryptService = Encrypter(AES(cipherKey, mode: AESMode.cbc,padding: null)); - // var initVector = IV.fromUtf8("j70IbWYn"); - // Encrypted encryptedData = encryptService.encrypt(plainText, iv: initVector); - // print(encryptedData.base64); - // return encryptedData; - // } - // - // Tuple2 deriveKeyAndIV(String passphrase, Uint8List salt) { - // var password = createUint8ListFromString(passphrase); - // Uint8List concatenatedHashes = Uint8List(0); - // Uint8List currentHash = Uint8List(0); - // bool enoughBytesForKey = false; - // Uint8List preHash = Uint8List(0); - // - // while (!enoughBytesForKey) { - // int preHashLength = currentHash.length + password.length + salt.length; - // if (currentHash.length > 0) - // preHash = Uint8List.fromList(currentHash + password + salt); - // else - // preHash = Uint8List.fromList(password + salt); - // - // currentHash = preHash; - // concatenatedHashes = Uint8List.fromList(concatenatedHashes + currentHash); - // if (concatenatedHashes.length >= 48) enoughBytesForKey = true; - // } - // - // var keyBtyes = concatenatedHashes.sublist(0, 32); - // var ivBtyes = concatenatedHashes.sublist(32, 48); - // return new Tuple2(keyBtyes, ivBtyes); - // } - // - // Uint8List createUint8ListFromString(String s) { - // var ret = new Uint8List(s.length); - // for (var i = 0; i < s.length; i++) { - // ret[i] = s.codeUnitAt(i); - // } - // return ret; - // } - // - // Uint8List genRandomWithNonZero(int seedLength) { - // var random = Random.secure(); - // const int randomMax = 245; - // Uint8List uint8list = Uint8List(seedLength); - // for (int i = 0; i < seedLength; i++) { - // uint8list[i] = random.nextInt(randomMax) + 1; - // } - // return uint8list; - // } - // - // - // - // void test(String text, String kk) { - // Uint8List key = Uint8List.fromList(utf8.encode(kk)); - // PaddedBlockCipher cipher = exp.PaddedBlockCipherImpl(exp.PKCS7Padding(), exp.ECBBlockCipher(exp.AESEngine())); - // cipher.init(true, PaddedBlockCipherParameters(KeyParameter(key), null)); - // var byte = Uint8List.fromList(utf8.encode(text)); - // var data = cipher.process(byte); - // print(data); - // } } diff --git a/lib/ui/landing/dashboard_screen.dart b/lib/ui/landing/dashboard_screen.dart index 7cf28cf..b449bd1 100644 --- a/lib/ui/landing/dashboard_screen.dart +++ b/lib/ui/landing/dashboard_screen.dart @@ -6,6 +6,7 @@ import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/material.dart'; import 'package:flutter_countdown_timer/flutter_countdown_timer.dart'; 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/utils.dart'; @@ -63,6 +64,14 @@ class _DashboardScreenState extends State { void buildHubConnection() async { hubConnection = await data.getHubConnection(); await hubConnection.start(); + hubConnection.onreconnecting(({Exception? error}) { + print("============== Reconnecting ======================"); + if (hubConnection.state != HubConnectionState.Connected) { + data.getUserAutoLoginToken().whenComplete(() { + buildHubConnection(); + }); + } + }); } @override @@ -106,9 +115,11 @@ 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) { 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 a71a71b..bcb9ed4 100644 --- a/lib/ui/landing/itg/its_add_screen_video_image.dart +++ b/lib/ui/landing/itg/its_add_screen_video_image.dart @@ -69,7 +69,7 @@ class _ITGAdsScreenState extends State { await controller.setLooping(false); return controller; } catch (e) { - return new VideoPlayerController.asset("dataSource"); + return VideoPlayerController.asset("dataSource"); } } @@ -94,29 +94,28 @@ class _ITGAdsScreenState extends State { if (advertisementData != null) { checkFileType(); } - double height = MediaQuery.of(context).size.height * .25; + // 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/pubspec.yaml b/pubspec.yaml index a2efb36..f17ce5f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -94,11 +94,6 @@ dependencies: camera: ^0.10.0+4 - #Encryption - cryptography: ^2.0.5 - cryptography_flutter: ^2.0.2 - - video_player: ^2.4.7 just_audio: ^0.9.30