|
|
|
@ -1,14 +1,21 @@
|
|
|
|
|
import 'dart:convert';
|
|
|
|
|
|
|
|
|
|
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_svg/flutter_svg.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/api/chat/chat_provider_model.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/api/worklist/worklist_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';
|
|
|
|
|
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/models/chat/get_search_user_chat_model.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/models/get_action_history_list_model.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/models/worklist/get_favorite_replacements_model.dart';
|
|
|
|
|
import 'package:mohem_flutter_app/models/worklist/replacement_list_model.dart';
|
|
|
|
@ -21,17 +28,19 @@ class SearchEmployeeBottomSheet extends StatefulWidget {
|
|
|
|
|
String title, apiMode;
|
|
|
|
|
List<GetActionHistoryList>? actionHistoryList;
|
|
|
|
|
Function(ReplacementList) onSelectEmployee;
|
|
|
|
|
bool fromChat;
|
|
|
|
|
|
|
|
|
|
SearchEmployeeBottomSheet(
|
|
|
|
|
{required this.title,
|
|
|
|
|
required this.apiMode,
|
|
|
|
|
this.notificationID,
|
|
|
|
|
this.actionHistoryList,
|
|
|
|
|
required this.onSelectEmployee});
|
|
|
|
|
SearchEmployeeBottomSheet({
|
|
|
|
|
required this.title,
|
|
|
|
|
required this.apiMode,
|
|
|
|
|
this.notificationID,
|
|
|
|
|
this.actionHistoryList,
|
|
|
|
|
required this.onSelectEmployee,
|
|
|
|
|
required this.fromChat,
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
State<SearchEmployeeBottomSheet> createState() =>
|
|
|
|
|
_SearchEmployeeBottomSheetState();
|
|
|
|
|
State<SearchEmployeeBottomSheet> createState() => _SearchEmployeeBottomSheetState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _SearchEmployeeBottomSheetState extends State<SearchEmployeeBottomSheet> {
|
|
|
|
@ -49,6 +58,9 @@ class _SearchEmployeeBottomSheetState extends State<SearchEmployeeBottomSheet> {
|
|
|
|
|
List<ReplacementList>? favouriteUserList;
|
|
|
|
|
List<ReplacementList>? nonFavouriteUserList;
|
|
|
|
|
|
|
|
|
|
// Chat Items
|
|
|
|
|
List<ChatUser>? chatUsersList = [];
|
|
|
|
|
|
|
|
|
|
int _selectedSearchIndex = 0;
|
|
|
|
|
|
|
|
|
|
void fetchUserByInput({bool isNeedLoading = true}) async {
|
|
|
|
@ -59,12 +71,30 @@ class _SearchEmployeeBottomSheetState extends State<SearchEmployeeBottomSheet> {
|
|
|
|
|
userId: _selectedSearchIndex == 1 ? searchText : "",
|
|
|
|
|
email: _selectedSearchIndex == 2 ? searchText : "",
|
|
|
|
|
);
|
|
|
|
|
favouriteUserList = replacementList
|
|
|
|
|
?.where((element) => element.isFavorite ?? false)
|
|
|
|
|
.toList();
|
|
|
|
|
nonFavouriteUserList = replacementList
|
|
|
|
|
?.where((element) => !(element.isFavorite ?? false))
|
|
|
|
|
.toList();
|
|
|
|
|
favouriteUserList = replacementList?.where((element) => element.isFavorite ?? false).toList();
|
|
|
|
|
nonFavouriteUserList = replacementList?.where((element) => !(element.isFavorite ?? false)).toList();
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
setState(() {});
|
|
|
|
|
} catch (e) {
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
Utils.handleException(e, context, null);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (isNeedLoading) Utils.hideLoading(context);
|
|
|
|
|
setState(() {});
|
|
|
|
|
return null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void fetchChatUser({bool isNeedLoading = true}) async {
|
|
|
|
|
try {
|
|
|
|
|
Utils.showLoading(context);
|
|
|
|
|
|
|
|
|
|
chatUsersList = await ChatProviderModel().getChatMemberFromSearch(searchText, int.parse(AppState().chatDetails!.response!.id.toString()));
|
|
|
|
|
print("================================");
|
|
|
|
|
print(jsonEncode(chatUsersList));
|
|
|
|
|
//
|
|
|
|
|
// favouriteUserList = replacementList?.where((element) => element.isFavorite ?? false).toList();
|
|
|
|
|
// nonFavouriteUserList = replacementList?.where((element) => !(element.isFavorite ?? false)).toList();
|
|
|
|
|
Utils.hideLoading(context);
|
|
|
|
|
setState(() {});
|
|
|
|
|
} catch (e) {
|
|
|
|
@ -114,57 +144,113 @@ class _SearchEmployeeBottomSheetState extends State<SearchEmployeeBottomSheet> {
|
|
|
|
|
IconButton(
|
|
|
|
|
constraints: const BoxConstraints(),
|
|
|
|
|
onPressed: () async {
|
|
|
|
|
await SystemChannels.textInput
|
|
|
|
|
.invokeMethod('TextInput.hide');
|
|
|
|
|
fetchUserByInput();
|
|
|
|
|
await SystemChannels.textInput.invokeMethod('TextInput.hide');
|
|
|
|
|
widget.fromChat ? fetchChatUser() : fetchUserByInput();
|
|
|
|
|
},
|
|
|
|
|
icon: Icon(Icons.search))
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
|
|
|
|
|
if (replacementList != null)
|
|
|
|
|
replacementList!.isEmpty
|
|
|
|
|
? Utils.getNoDataWidget(context).expanded
|
|
|
|
|
: ListView(
|
|
|
|
|
physics: const BouncingScrollPhysics(),
|
|
|
|
|
padding: EdgeInsets.only(top: 21, bottom: 8),
|
|
|
|
|
children: [
|
|
|
|
|
if (favouriteUserList?.isNotEmpty ?? false) ...[
|
|
|
|
|
"Favorites".toText16(),
|
|
|
|
|
12.height,
|
|
|
|
|
ListView.separated(
|
|
|
|
|
physics: const NeverScrollableScrollPhysics(),
|
|
|
|
|
shrinkWrap: true,
|
|
|
|
|
itemBuilder: (cxt, index) =>
|
|
|
|
|
employeeItemView(favouriteUserList![index]),
|
|
|
|
|
separatorBuilder: (cxt, index) => Container(
|
|
|
|
|
height: 1,
|
|
|
|
|
color: MyColors.borderE3Color,
|
|
|
|
|
),
|
|
|
|
|
itemCount: favouriteUserList?.length ?? 0),
|
|
|
|
|
12.height,
|
|
|
|
|
],
|
|
|
|
|
if (nonFavouriteUserList?.isNotEmpty ?? false) ...[
|
|
|
|
|
"Related".toText16(),
|
|
|
|
|
12.height,
|
|
|
|
|
ListView.separated(
|
|
|
|
|
physics: const NeverScrollableScrollPhysics(),
|
|
|
|
|
shrinkWrap: true,
|
|
|
|
|
itemBuilder: (cxt, index) => employeeItemView(
|
|
|
|
|
nonFavouriteUserList![index]),
|
|
|
|
|
separatorBuilder: (cxt, index) => Container(
|
|
|
|
|
height: 1,
|
|
|
|
|
color: MyColors.borderE3Color,
|
|
|
|
|
: ListView(
|
|
|
|
|
physics: const BouncingScrollPhysics(),
|
|
|
|
|
padding: EdgeInsets.only(top: 21, bottom: 8),
|
|
|
|
|
children: [
|
|
|
|
|
if (favouriteUserList?.isNotEmpty ?? false) ...[
|
|
|
|
|
"Favorites".toText16(),
|
|
|
|
|
12.height,
|
|
|
|
|
ListView.separated(
|
|
|
|
|
physics: const NeverScrollableScrollPhysics(),
|
|
|
|
|
shrinkWrap: true,
|
|
|
|
|
itemBuilder: (cxt, index) => employeeItemView(favouriteUserList![index]),
|
|
|
|
|
separatorBuilder: (cxt, index) => Container(
|
|
|
|
|
height: 1,
|
|
|
|
|
color: MyColors.borderE3Color,
|
|
|
|
|
),
|
|
|
|
|
itemCount: favouriteUserList?.length ?? 0),
|
|
|
|
|
12.height,
|
|
|
|
|
],
|
|
|
|
|
if (nonFavouriteUserList?.isNotEmpty ?? false) ...[
|
|
|
|
|
"Related".toText16(),
|
|
|
|
|
12.height,
|
|
|
|
|
ListView.separated(
|
|
|
|
|
physics: const NeverScrollableScrollPhysics(),
|
|
|
|
|
shrinkWrap: true,
|
|
|
|
|
itemBuilder: (cxt, index) => employeeItemView(nonFavouriteUserList![index]),
|
|
|
|
|
separatorBuilder: (cxt, index) => Container(
|
|
|
|
|
height: 1,
|
|
|
|
|
color: MyColors.borderE3Color,
|
|
|
|
|
),
|
|
|
|
|
itemCount: nonFavouriteUserList?.length ?? 0),
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
).expanded,
|
|
|
|
|
|
|
|
|
|
if(widget.fromChat)
|
|
|
|
|
if (chatUsersList != null && widget.fromChat)
|
|
|
|
|
chatUsersList!.isEmpty
|
|
|
|
|
? Utils.getNoDataWidget(context)
|
|
|
|
|
: ListView(
|
|
|
|
|
physics: const BouncingScrollPhysics(),
|
|
|
|
|
padding: EdgeInsets.only(top: 0, bottom: 8),
|
|
|
|
|
children: [
|
|
|
|
|
ListView.separated(
|
|
|
|
|
physics: const NeverScrollableScrollPhysics(),
|
|
|
|
|
shrinkWrap: true,
|
|
|
|
|
|
|
|
|
|
itemBuilder: (cxt, index) {
|
|
|
|
|
return 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: chatUsersList![index].userStatus == 1 ? MyColors.green2DColor : Colors.red,
|
|
|
|
|
borderRadius: const BorderRadius.all(
|
|
|
|
|
Radius.circular(10),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
itemCount: nonFavouriteUserList?.length ?? 0),
|
|
|
|
|
]
|
|
|
|
|
],
|
|
|
|
|
).expanded
|
|
|
|
|
)
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
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]},
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
separatorBuilder: (cxt, index) => Container(
|
|
|
|
|
height: 1,
|
|
|
|
|
color: MyColors.borderE3Color,
|
|
|
|
|
),
|
|
|
|
|
itemCount: chatUsersList?.length ?? 0),
|
|
|
|
|
12.height,
|
|
|
|
|
],
|
|
|
|
|
).expanded,
|
|
|
|
|
],
|
|
|
|
|
).paddingOnly(left: 21, right: 21, bottom: 0, top: 21).expanded,
|
|
|
|
|
Container(
|
|
|
|
|
width: double.infinity,
|
|
|
|
|
height: 1,
|
|
|
|
|
color: MyColors.lightGreyEFColor),
|
|
|
|
|
|
|
|
|
|
Container(width: double.infinity, height: 1, color: MyColors.lightGreyEFColor),
|
|
|
|
|
DefaultButton(
|
|
|
|
|
LocaleKeys.cancel.tr(),
|
|
|
|
|
() {
|
|
|
|
@ -201,11 +287,7 @@ class _SearchEmployeeBottomSheetState extends State<SearchEmployeeBottomSheet> {
|
|
|
|
|
Expanded(
|
|
|
|
|
child: (replacement.employeeDisplayName ?? "").toText12(),
|
|
|
|
|
),
|
|
|
|
|
Icon(Icons.star,
|
|
|
|
|
size: 16,
|
|
|
|
|
color: replacement.isFavorite!
|
|
|
|
|
? MyColors.yellowFavColor
|
|
|
|
|
: MyColors.borderCEColor),
|
|
|
|
|
Icon(Icons.star, size: 16, color: replacement.isFavorite! ? MyColors.yellowFavColor : MyColors.borderCEColor),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
@ -228,9 +310,7 @@ class _SearchEmployeeBottomSheetState extends State<SearchEmployeeBottomSheet> {
|
|
|
|
|
width: double.infinity,
|
|
|
|
|
height: double.infinity,
|
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
|
color: value == groupValue
|
|
|
|
|
? MyColors.grey3AColor
|
|
|
|
|
: Colors.transparent,
|
|
|
|
|
color: value == groupValue ? MyColors.grey3AColor : Colors.transparent,
|
|
|
|
|
borderRadius: BorderRadius.all(const Radius.circular(100)),
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|