Chat Fixes & Favorite Api Implementation

merge-requests/52/head
Aamir Muhammad 2 years ago
parent 8ba3dcf43b
commit 67f4fdef28

@ -141,20 +141,13 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
)
.build();
hubConnection.onclose(
({Exception? error}) {
// logger.d(error);
},
({Exception? error}) {},
);
hubConnection.onreconnecting(
({Exception? error}) {
// logger.d(error);
// logger.d("Reconnecting");
},
({Exception? error}) {},
);
hubConnection.onreconnected(
({String? connectionId}) {
// logger.d("Reconnected");
},
({String? connectionId}) {},
);
if (hubConnection.state != HubConnectionState.Connected) {
await hubConnection.start();
@ -403,7 +396,6 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
sFileType = "";
message.clear();
notifyListeners();
// scrollDown();
}
void sendChatMessage(int targetUserId, String targetUserName) async {
@ -437,7 +429,6 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
}
sendChatToServer(
chatEventId: 1, fileTypeId: null, targetUserId: targetUserId, targetUserName: targetUserName, chatReplyId: repliedMsg.first.userChatHistoryId, isAttachment: false, isReply: true);
//chatReplyId
}
if (isFileSelected && isMsgReply) {
logger.d("Attachment Message With Reply");
@ -445,60 +436,14 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
dynamic value = await uploadAttachments(AppState().chatDetails!.response!.id.toString(), selectedFile);
String? ext = getFileExtension(selectedFile.path);
sendChatToServer(
chatEventId: 2,
fileTypeId: getFileType(ext.toString()),
targetUserId: targetUserId,
targetUserName: targetUserName,
isAttachment: true,
chatReplyId: repliedMsg.first.userChatHistoryId,
isReply: true);
}
// dynamic contain = searchedChats!.where((ChatUser element) => element.id == targetUserId);
// if (contain.isEmpty) {
// searchedChats!.add(
// ChatUser(
// id: targetUserId,
// userName: targetUserName,
// ),
// );
// notifyListeners();
// }
// Uuid uuid = const Uuid();
// dynamic fileID = fileUploadResponse.isEmpty ? null : getFileType(chatMessage);
// SingleUserChatModel data = SingleUserChatModel(
// chatEventId: fileUploadResponse.isEmpty ? 1 : 2,
// chatSource: 1,
// contant: chatMessage,
// contantNo: uuid.v4(),
// conversationId: uuid.v4(),
// createdDate: DateTime.now(),
// currentUserId: AppState().chatDetails!.response!.id,
// currentUserName: AppState().chatDetails!.response!.userName,
// targetUserId: targetUserId,
// targetUserName: targetUserName,
// fileTypeId: fileID,
// isReplied: false,
// // fileTypeResponse: FileTypeResponse(
// // fileTypeId: 0,
// // fileTypeDescription: fileUploadResponse.isEmpty ? null : fileUploadResponse.first["filePath"],
// // fileName: fileUploadResponse.isEmpty ? null : fileUploadResponse.first["filePath"],
// // fileKind: "image",
// // fileTypeName: fileUploadResponse.isEmpty ? null : fileUploadResponse.first["filePath"].toString().split(".").last),
// );
//
// String chatData =
// '{"contant":"$chatMessage","contantNo":"${uuid.v4()}","chatEventId":${fileUploadResponse.isEmpty ? 1 : 2},"fileTypeId": $fileID,"currentUserId":${AppState().chatDetails!.response!.id},"chatSource":1,"userChatHistoryLineRequestList":[{"isSeen":false,"isDelivered":false,"targetUserId":$targetUserId,"targetUserStatus":1}],"conversationId":"${uuid.v4()}"}';
// await hubConnection.invoke("AddChatUserAsync", args: <Object>[json.decode(chatData)]);
// userChatHistory.add(data);
// message.clear();
// notifyListeners();
// scrollDown();
}
void scrollListener() {
if (userChatHistory.length < paginationVal) {
print("Get New Data");
chatEventId: 2,
fileTypeId: getFileType(ext.toString()),
targetUserId: targetUserId,
targetUserName: targetUserName,
isAttachment: true,
chatReplyId: repliedMsg.first.userChatHistoryId,
isReply: true,
);
}
}
@ -513,18 +458,7 @@ class ChatProviderModel with ChangeNotifier, DiagnosticableTreeMixin {
} else {
Utils.showToast("Max 1 mb size is allowed to upload");
}
//Utils.showLoading(context);
notifyListeners();
//Utils.hideLoading(context);
// Utils.showLoading(context);
// await m.uploadAttachments(AppState().chatDetails!.response!.id.toString(), file).then((value) {
// if (value == null) {
// m.logger.d("Returned EMPTY");
// } else {
// m.sendChatMessage(value.isEmpty ? m.message.text : value.first["filePath"], userDetails["targetUser"].id, userDetails["targetUser"].userName, value);
// }
// });
// Utils.hideLoading(context);
});
}

@ -10,6 +10,7 @@ class ApiConsts {
static String user = baseUrlServices + "api/User/";
static String cocRest = baseUrlServices + "COCWS.svc/REST/";
//Chat
static String chatServerBaseUrl = "https://apiderichat.hmg.com";
static String chatServerBaseApiUrl = "https://apiderichat.hmg.com/api/";
static String chatHubConnectionUrl = chatServerBaseUrl + "/ConnectionChatHub";
@ -18,12 +19,6 @@ class ApiConsts {
static String chatSingleUserHistoryUrl = "UserChatHistory/GetUserChatHistory";
static String chatMediaImageUploadUrl = "shared/upload";
static String chatFavoriteUsers = "FavUser/getFavUserById/";
//https://apiderichat.hmg.com/api/FavUser/getFavUserById/42062
//https://apiderichat.hmg.com/api/shared/upload
// 42062 is CurrentUserID and 36745 is targetUserID and 0 is For Pagination
// static String chatSearchMember = "https://apiderichat.hmg.com/api/user/getUserWithStatusAndFavAsync/aamir.muhammad/36239";
}
class SharedPrefsConsts {

@ -29,7 +29,7 @@ class ChatBubble extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Padding(
// padding: EdgeInsets.zero,
// padding: EdgeInsets.zero,
padding: EdgeInsets.only(left: isCurrentUser ? 110 : 20, right: isCurrentUser ? 20 : 110, bottom: 9),
child: Align(
@ -51,7 +51,7 @@ class ChatBubble extends StatelessWidget {
borderRadius: BorderRadius.circular(10),
),
child: Padding(
padding: EdgeInsets.only(top: isReplied ? 8 : 5, right:8, left: 8, bottom: 5),
padding: EdgeInsets.only(top: isReplied ? 8 : 5, right: 8, left: 8, bottom: 5),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.start,
@ -85,7 +85,6 @@ class ChatBubble extends StatelessWidget {
),
if (isReplied) 8.height,
text.toText12(color: isCurrentUser ? MyColors.grey57Color : MyColors.white),
Row(
crossAxisAlignment: CrossAxisAlignment.end,
mainAxisAlignment: MainAxisAlignment.end,
@ -100,7 +99,6 @@ class ChatBubble extends StatelessWidget {
),
],
),
],
),
),

@ -8,19 +8,14 @@ import 'package:flutter_svg/flutter_svg.dart';
import 'package:mohem_flutter_app/api/chat/chat_provider_model.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/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/ui/chat/chat_bubble.dart';
import 'package:mohem_flutter_app/widgets/app_bar_widget.dart';
import 'package:mohem_flutter_app/widgets/image_picker.dart';
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:sizer/sizer.dart';
import 'package:swipe_to/swipe_to.dart';
class ChatDetailScreen extends StatelessWidget {
@ -30,13 +25,13 @@ class ChatDetailScreen extends StatelessWidget {
ScrollController scrollController = ScrollController();
RefreshController _refreshController = RefreshController(initialRefresh: false);
void onRefresh() async {
print("Refresh Triggered");
await Future.delayed(Duration(milliseconds: 1000));
void getMoreChat() async {
if (userDetails != null) {
data.paginationVal = data.paginationVal + 10;
data.getSingleUserChatHistory(senderUID: AppState().chatDetails!.response!.id.toString(), receiverUID: userDetails["targetUser"].id, loadMore: true);
}
await Future.delayed(Duration(milliseconds: 1000));
_refreshController.refreshCompleted();
}
@ -45,16 +40,6 @@ class ChatDetailScreen extends StatelessWidget {
userDetails = ModalRoute.of(context)!.settings.arguments;
data = Provider.of<ChatProviderModel>(context, listen: false);
if (userDetails != null) data.getSingleUserChatHistory(senderUID: AppState().chatDetails!.response!.id.toString(), receiverUID: userDetails["targetUser"].id, loadMore: false);
//
// if (userDetails != null) {
// scrollController.addListener(() {
// if (scrollController.position.minScrollExtent == scrollController.offset) {
// data.paginationVal++;
// data.getSingleUserChatHistory(senderUID: AppState().chatDetails!.response!.id.toString(), receiverUID: userDetails["targetUser"].id, loadMore: true);
// }
// });
// }
return Scaffold(
backgroundColor: const Color(0xFFF8F8F8),
appBar: AppBarWidget(context, title: userDetails["targetUser"].userName, showHomeButton: false, image: userDetails["targetUser"].image),
@ -73,34 +58,28 @@ class ChatDetailScreen extends StatelessWidget {
color: MyColors.gradiantEndColor,
),
controller: _refreshController,
onRefresh: onRefresh,
onRefresh: getMoreChat,
child: ListView.builder(
controller: scrollController,
shrinkWrap: true,
itemCount: m.userChatHistory.length,
padding: EdgeInsets.zero,
itemBuilder: (BuildContext context, int i) {
return GestureDetector(
onTap: () {
m.logger.d(jsonEncode(m.userChatHistory[i]));
m.logger.d(jsonEncode(m.userChatHistory.length));
},
child: 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(),
),
onRightSwipe: () {
m.chatReply(m.userChatHistory[i]);
},
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(),
),
onRightSwipe: () {
m.chatReply(m.userChatHistory[i]);
},
);
},
),
@ -203,7 +182,7 @@ class ChatDetailScreen extends StatelessWidget {
],
)
: null,
suffixIcon: Container(
suffixIcon: SizedBox(
width: 96,
child: Row(
mainAxisAlignment: MainAxisAlignment.end,

@ -27,7 +27,7 @@ class ChatHomeScreen extends StatefulWidget {
}
class _ChatHomeScreenState extends State<ChatHomeScreen> {
TextEditingController search = new TextEditingController();
TextEditingController search = TextEditingController();
late ChatProviderModel data;
@override
@ -213,8 +213,6 @@ class _ChatHomeScreenState extends State<ChatHomeScreen> {
apiMode: LocaleKeys.delegate.tr(),
fromChat: true,
onSelectEmployee: (_selectedEmployee) {
// Navigator.pop(context);
// selectedReplacementEmployee = _selectedEmployee;
setState(() {});
},
),

@ -136,12 +136,13 @@ class _SearchEmployeeBottomSheetState extends State<SearchEmployeeBottomSheet> {
},
).expanded,
IconButton(
constraints: const BoxConstraints(),
onPressed: () async {
await SystemChannels.textInput.invokeMethod('TextInput.hide');
widget.fromChat ? fetchChatUser() : fetchUserByInput();
},
icon: Icon(Icons.search))
constraints: const BoxConstraints(),
onPressed: () async {
await SystemChannels.textInput.invokeMethod('TextInput.hide');
widget.fromChat ? fetchChatUser() : fetchUserByInput();
},
icon: const Icon(Icons.search),
)
],
),
if (replacementList != null)
@ -184,62 +185,21 @@ class _SearchEmployeeBottomSheetState extends State<SearchEmployeeBottomSheet> {
if (chatUsersList != null && widget.fromChat)
chatUsersList!.isEmpty
? Column(
children: [
20.height,
Utils.getNoDataWidget(context),
],
)
children: [
20.height,
Utils.getNoDataWidget(context),
],
)
: ListView(
physics: const BouncingScrollPhysics(),
padding: const EdgeInsets.only(top: 15,),
padding: const EdgeInsets.only(
top: 15,
),
children: <Widget>[
ListView.separated(
physics: const NeverScrollableScrollPhysics(),
shrinkWrap: true,
itemBuilder: (BuildContext cxt, int index) {
// return ListTile(
// leading: Stack(
// children: <Widget>[
// SvgPicture.asset(
// "assets/images/user.svg",
// height: 48,
// width: 48,
// ),
// Positioned(
// right: 5,
// bottom: 1,
// child: Container(
// width: 10,
// height: 10,
// decoration: BoxDecoration(
// color: chatUsersList![index].userStatus == 1 ? MyColors.green2DColor : Colors.red,
// borderRadius: const BorderRadius.all(
// Radius.circular(10),
// ),
// ),
// ),
// )
// ],
// ),
// title: (chatUsersList![index].userName ?? "").toText14(color: MyColors.darkTextColor),
// // subtitle: (chatUsersList![index].isTyping == true ? "Something is Typing" : "Last message text").toText11(color: MyColors.normalTextColor),
// // trailing: ("Today").toText10(color: MyColors.lightTextColor),
// minVerticalPadding: 0,
// onTap: () {
// Navigator.pop(context);
// Navigator.pushNamed(
// context,
// AppRoutes.chatDetailed,
// arguments: {"targetUser": chatUsersList![index]},
// );
// },
// );
return SizedBox(
height: 55,
child: ListTile(
@ -279,12 +239,9 @@ class _SearchEmployeeBottomSheetState extends State<SearchEmployeeBottomSheet> {
onLongPress: () {},
),
);
},
separatorBuilder: (BuildContext context, int index) => const Padding(
padding: EdgeInsets.only(right: 10, left: 70, bottom: 0,top: 0),
padding: EdgeInsets.only(right: 10, left: 70, bottom: 0, top: 0),
child: Divider(
color: Color(0xFFE5E5E5),
),
@ -349,7 +306,9 @@ class _SearchEmployeeBottomSheetState extends State<SearchEmployeeBottomSheet> {
decoration: BoxDecoration(
color: Colors.transparent,
border: Border.all(color: MyColors.borderColor, width: 1),
borderRadius: const BorderRadius.all(Radius.circular(100)),
borderRadius: const BorderRadius.all(
Radius.circular(100),
),
),
padding: const EdgeInsets.all(4),
child: Container(
@ -357,7 +316,9 @@ class _SearchEmployeeBottomSheetState extends State<SearchEmployeeBottomSheet> {
height: double.infinity,
decoration: BoxDecoration(
color: value == groupValue ? MyColors.grey3AColor : Colors.transparent,
borderRadius: BorderRadius.all(const Radius.circular(100)),
borderRadius: const BorderRadius.all(
Radius.circular(100),
),
),
),
),

Loading…
Cancel
Save