Chat Fixes & User Chat Counter

merge-requests/81/head
Aamir Muhammad 3 years ago
parent cecb2d59e9
commit f6f801f9cf

@ -12,8 +12,6 @@ class ApiConsts {
static String user = baseUrlServices + "api/User/"; static String user = baseUrlServices + "api/User/";
static String cocRest = baseUrlServices + "COCWS.svc/REST/"; static String cocRest = baseUrlServices + "COCWS.svc/REST/";
// todo @aamir move api end point last repo to concerned method.
//Chat //Chat
static String chatServerBaseUrl = "https://apiderichat.hmg.com/"; static String chatServerBaseUrl = "https://apiderichat.hmg.com/";
static String chatServerBaseApiUrl = chatServerBaseUrl + "api/"; static String chatServerBaseApiUrl = chatServerBaseUrl + "api/";

@ -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<void> 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<Uint8List, Uint8List> 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<CipherParameters, CipherParameters>(KeyParameter(key), null));
// // var byte = Uint8List.fromList(utf8.encode(text));
// // var data = cipher.process(byte);
// // print(data);
// // }
//
// }

@ -120,7 +120,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
if (element.isSeen != null) { if (element.isSeen != null) {
if (!element.isSeen!) { if (!element.isSeen!) {
print("Found Un Read"); print("Found Un Read");
logger.d(jsonEncode(element)); element.isSeen = true;
dynamic data = [ dynamic data = [
{"userChatHistoryId": element.userChatHistoryId, "TargetUserId": element.targetUserId, "isDelivered": true, "isSeen": true} {"userChatHistoryId": element.userChatHistoryId, "TargetUserId": element.targetUserId, "isDelivered": true, "isSeen": true}
]; ];
@ -131,9 +131,10 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
for (ChatUser element in searchedChats!) { for (ChatUser element in searchedChats!) {
if (element.id == receiverID) { if (element.id == receiverID) {
element.unreadMessageCount = 0; element.unreadMessageCount = 0;
notifyListeners(); // notifyListeners();
} }
} }
notifyListeners();
} }
} }
@ -223,7 +224,6 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
void chatNotDelivered(List<Object?>? args) { void chatNotDelivered(List<Object?>? args) {
dynamic items = args!.toList(); dynamic items = args!.toList();
logger.d(items);
for (dynamic item in items[0]) { for (dynamic item in items[0]) {
searchedChats!.forEach( searchedChats!.forEach(
(ChatUser element) { (ChatUser element) {
@ -288,8 +288,16 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
} }
userChatHistory.insert(0, data.first); 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} {"userChatHistoryId": data.first.userChatHistoryId, "TargetUserId": temp.first.targetUserId, "isDelivered": true, "isSeen": isChatScreenActive ? true : false}
]; ];
updateUserChatHistoryOnMsg(list); updateUserChatHistoryOnMsg(list);
@ -624,7 +632,6 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
} }
void clearSelections() { void clearSelections() {
print("Hereee i am ");
searchedChats = pChatHistory; searchedChats = pChatHistory;
search.clear(); search.clear();
isChatScreenActive = false; isChatScreenActive = false;

@ -307,13 +307,21 @@ class DashboardProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
Future<HubConnection> getHubConnection() async { Future<HubConnection> getHubConnection() async {
HubConnection hub; HubConnection hub;
try {
HttpConnectionOptions httpOp = HttpConnectionOptions(skipNegotiation: false, logMessageContent: true); HttpConnectionOptions httpOp = HttpConnectionOptions(skipNegotiation: false, logMessageContent: true);
hub = HubConnectionBuilder() hub = HubConnectionBuilder()
.withUrl(ApiConsts.chatHubConnectionUrl + "?UserId=${AppState().chatDetails!.response!.id}&source=Web&access_token=${AppState().chatDetails!.response!.token}", options: httpOp) .withUrl(ApiConsts.chatHubConnectionUrl + "?UserId=${AppState().chatDetails!.response!.id}&source=Web&access_token=${AppState().chatDetails!.response!.token}", options: httpOp)
.withAutomaticReconnect(retryDelays: <int>[2000, 5000, 10000, 20000]).build(); .withAutomaticReconnect(retryDelays: <int>[2000, 5000, 10000, 20000]).build();
isChatHubLoding = false; isChatHubLoding = false;
return hub; return hub;
} catch (e) {
getUserAutoLoginToken().whenComplete(() {
getHubConnection();
});
throw e;
} }
}
void notify() { void notify() {
notifyListeners(); notifyListeners();
} }

@ -28,6 +28,7 @@ class ChatBubble extends StatelessWidget {
String? fileTypeDescription; String? fileTypeDescription;
bool isDelivered = false; bool isDelivered = false;
String userName = ''; String userName = '';
late Offset screenOffset;
void makeAssign() { void makeAssign() {
isCurrentUser = cItem.currentUserId == AppState().chatDetails!.response!.id ? true : false; isCurrentUser = cItem.currentUserId == AppState().chatDetails!.response!.id ? true : false;
@ -41,6 +42,8 @@ class ChatBubble extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
Size windowSize = MediaQuery.of(context).size;
screenOffset = Offset(windowSize.width / 2, windowSize.height / 2);
makeAssign(); makeAssign();
return isCurrentUser ? currentUser(context) : receiptUser(context); return isCurrentUser ? currentUser(context) : receiptUser(context);
} }
@ -108,7 +111,11 @@ class ChatBubble extends StatelessWidget {
).paddingOnly(right: 5, bottom: 7), ).paddingOnly(right: 5, bottom: 7),
if (fileTypeID == 12 || fileTypeID == 4 || fileTypeID == 3) if (fileTypeID == 12 || fileTypeID == 4 || fileTypeID == 3)
showImage(isReplyPreview: false, fileName: cItem.contant!, fileTypeDescription: cItem.fileTypeResponse!.fileTypeDescription).paddingOnly(right: 5).onPress(() { 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(), cItem.contant!.toText12(),
Align( Align(
@ -177,18 +184,23 @@ class ChatBubble extends StatelessWidget {
child: showImage( child: showImage(
isReplyPreview: true, isReplyPreview: true,
fileName: cItem.userChatReplyResponse!.contant!, fileName: cItem.userChatReplyResponse!.contant!,
fileTypeDescription: cItem.userChatReplyResponse!.fileTypeResponse!.fileTypeDescription ?? "image/jpg")), fileTypeDescription: cItem.userChatReplyResponse!.fileTypeResponse!.fileTypeDescription ?? "image/jpg"),
),
).paddingOnly(left: 10, right: 10, bottom: 16, top: 16) ).paddingOnly(left: 10, right: 10, bottom: 16, top: 16)
], ],
), ),
), ),
).paddingOnly(right: 5, bottom: 7), ).paddingOnly(right: 5, bottom: 7),
if (fileTypeID == 12 || fileTypeID == 4 || fileTypeID == 3) if (fileTypeID == 12 || fileTypeID == 4 || fileTypeID == 3)
showImage(isReplyPreview: false, fileName: cItem.contant!, fileTypeDescription: cItem.fileTypeResponse!.fileTypeDescription ?? "image/jpg").paddingOnly(right: 5).onPress(() { 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!)); showDialog(
context: context,
anchorPoint: screenOffset,
builder: (BuildContext context) => ChatImagePreviewScreen(imgTitle: cItem.contant ?? "", img: cItem.image!),
);
}) })
else else
(cItem.contant! ?? "").toText12(color: Colors.white), (cItem.contant ?? "").toText12(color: Colors.white),
Align( Align(
alignment: Alignment.centerRight, alignment: Alignment.centerRight,
child: dateTime.toText10(color: Colors.white.withOpacity(.71)), child: dateTime.toText10(color: Colors.white.withOpacity(.71)),

@ -12,30 +12,41 @@ class ChatImagePreviewScreen extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return GestureDetector( return Dialog(
onTap: () {
Navigator.of(context).pop();
},
child: Dialog(
backgroundColor: Colors.transparent, backgroundColor: Colors.transparent,
insetPadding: const EdgeInsets.all(10), insetPadding: const EdgeInsets.all(10),
child: Stack( child: Stack(
alignment: Alignment.center, alignment: Alignment.center,
fit: StackFit.loose,
children: [ children: [
Image.memory( Image.memory(
img, img,
fit: BoxFit.cover, fit: BoxFit.cover,
height: 400, height: 400,
width: double.infinity, width: double.infinity,
).paddingAll(10), ).paddingAll(15),
const Positioned( Positioned(
right: 0, right: 0,
top: 0, top: 0,
child: Icon(Icons.cancel, color: MyColors.redA3Color, size: 35), 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),
) )
], ],
), ),
),
); );
} }
} }

@ -63,7 +63,7 @@ class _ChatHomeScreenState extends State<ChatHomeScreen> {
hintText: LocaleKeys.searchfromchat.tr(), hintText: LocaleKeys.searchfromchat.tr(),
hintStyle: const TextStyle(color: MyColors.lightTextColor, fontStyle: FontStyle.italic, fontWeight: FontWeight.w500, fontSize: 12), hintStyle: const TextStyle(color: MyColors.lightTextColor, fontStyle: FontStyle.italic, fontWeight: FontWeight.w500, fontSize: 12),
filled: true, filled: true,
fillColor: const Color(0xFFF7F7F7), fillColor: MyColors.greyF7Color,
suffixIconConstraints: const BoxConstraints(), suffixIconConstraints: const BoxConstraints(),
suffixIcon: m.search.text.isNotEmpty suffixIcon: m.search.text.isNotEmpty
? IconButton( ? IconButton(
@ -83,7 +83,6 @@ class _ChatHomeScreenState extends State<ChatHomeScreen> {
shrinkWrap: true, shrinkWrap: true,
physics: const ClampingScrollPhysics(), physics: const ClampingScrollPhysics(),
itemBuilder: (BuildContext context, int index) { itemBuilder: (BuildContext context, int index) {
// todo @aamir, remove list tile, make a custom ui instead
return SizedBox( return SizedBox(
height: 55, height: 55,
child: Row( child: Row(
@ -103,11 +102,8 @@ class _ChatHomeScreenState extends State<ChatHomeScreen> {
height: 10, height: 10,
decoration: BoxDecoration( decoration: BoxDecoration(
color: m.searchedChats![index].userStatus == 1 ? MyColors.green2DColor : Colors.red, 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<ChatHomeScreen> {
), ),
), ),
onPressed: () async { onPressed: () async {
// String plainText = 'Muhamad.Alam@cloudsolutions.com.sa';
// String key = "PeShVmYp";
// passEncrypt(plainText, "PeShVmYp");
showMyBottomSheet( showMyBottomSheet(
context, context,
callBackFunc: () {}, callBackFunc: () {},
@ -231,137 +224,10 @@ class _ChatHomeScreenState extends State<ChatHomeScreen> {
OutlineInputBorder fieldBorder({required double radius, required int color}) { OutlineInputBorder fieldBorder({required double radius, required int color}) {
return OutlineInputBorder( return OutlineInputBorder(
borderRadius: BorderRadius.circular( borderRadius: BorderRadius.circular(radius),
radius,
),
borderSide: BorderSide( 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<int> eByt = utf8.encode(ekey);
List<int> eIvByt = utf8.encode(eIV);
List<int> 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<Uint8List, Uint8List> 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<CipherParameters, CipherParameters>(KeyParameter(key), null));
// var byte = Uint8List.fromList(utf8.encode(text));
// var data = cipher.process(byte);
// print(data);
// }
} }

@ -6,6 +6,7 @@ import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter_countdown_timer/flutter_countdown_timer.dart'; import 'package:flutter_countdown_timer/flutter_countdown_timer.dart';
import 'package:flutter_svg/flutter_svg.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/app_state/app_state.dart';
import 'package:mohem_flutter_app/classes/colors.dart'; import 'package:mohem_flutter_app/classes/colors.dart';
import 'package:mohem_flutter_app/classes/utils.dart'; import 'package:mohem_flutter_app/classes/utils.dart';
@ -63,6 +64,14 @@ class _DashboardScreenState extends State<DashboardScreen> {
void buildHubConnection() async { void buildHubConnection() async {
hubConnection = await data.getHubConnection(); hubConnection = await data.getHubConnection();
await hubConnection.start(); await hubConnection.start();
hubConnection.onreconnecting(({Exception? error}) {
print("============== Reconnecting ======================");
if (hubConnection.state != HubConnectionState.Connected) {
data.getUserAutoLoginToken().whenComplete(() {
buildHubConnection();
});
}
});
} }
@override @override
@ -106,9 +115,11 @@ class _DashboardScreenState extends State<DashboardScreen> {
// onPressed: () { // onPressed: () {
// data.getITGNotification().then((val) { // data.getITGNotification().then((val) {
// if (val!.result!.data != null) { // if (val!.result!.data != null) {
// print("-------------------- Survey ----------------------------");
// if (val.result!.data!.notificationType == "Survey") { // if (val.result!.data!.notificationType == "Survey") {
// Navigator.pushNamed(context, AppRoutes.survey, arguments: val.result!.data); // Navigator.pushNamed(context, AppRoutes.survey, arguments: val.result!.data);
// } else { // } else {
// print("------------------------------------------- Ads --------------------");
// DashboardApiClient().getAdvertisementDetail(val.result!.data!.notificationMasterId ?? "").then( // DashboardApiClient().getAdvertisementDetail(val.result!.data!.notificationMasterId ?? "").then(
// (value) { // (value) {
// if (value!.mohemmItgResponseItem!.statusCode == 200) { // if (value!.mohemmItgResponseItem!.statusCode == 200) {

@ -69,7 +69,7 @@ class _ITGAdsScreenState extends State<ITGAdsScreen> {
await controller.setLooping(false); await controller.setLooping(false);
return controller; return controller;
} catch (e) { } catch (e) {
return new VideoPlayerController.asset("dataSource"); return VideoPlayerController.asset("dataSource");
} }
} }
@ -94,21 +94,21 @@ class _ITGAdsScreenState extends State<ITGAdsScreen> {
if (advertisementData != null) { if (advertisementData != null) {
checkFileType(); checkFileType();
} }
double height = MediaQuery.of(context).size.height * .25; // double height = MediaQuery.of(context).size.height * .25;
return Scaffold( return Scaffold(
body: Column( body: Stack(
children: [ children: [
if (isVideo) if (isVideo)
SizedBox( FutureBuilder(
height: MediaQuery.of(context).size.height * .3,
child: FutureBuilder(
future: _futureController, future: _futureController,
builder: (BuildContext context, AsyncSnapshot<Object?> snapshot) { builder: (BuildContext context, AsyncSnapshot<Object?> snapshot) {
if (snapshot.connectionState == ConnectionState.done && snapshot.data != null) { if (snapshot.connectionState == ConnectionState.done && snapshot.data != null) {
_controller = snapshot.data as VideoPlayerController; _controller = snapshot.data as VideoPlayerController;
return AspectRatio( return Positioned.fill(
child: AspectRatio(
aspectRatio: _controller.value.aspectRatio, aspectRatio: _controller.value.aspectRatio,
child: VideoPlayer(_controller), child: VideoPlayer(_controller),
),
); );
} else { } else {
return const Center( return const Center(
@ -117,7 +117,6 @@ class _ITGAdsScreenState extends State<ITGAdsScreen> {
} }
}, },
), ),
),
if (isImage) Image.file(imageFile), if (isImage) Image.file(imageFile),
if (skip) if (skip)
ElevatedButton( ElevatedButton(

@ -94,11 +94,6 @@ dependencies:
camera: ^0.10.0+4 camera: ^0.10.0+4
#Encryption
cryptography: ^2.0.5
cryptography_flutter: ^2.0.2
video_player: ^2.4.7 video_player: ^2.4.7
just_audio: ^0.9.30 just_audio: ^0.9.30

Loading…
Cancel
Save