You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
mohemm-flutter-app/lib/ui/my_team/employee_details.dart

298 lines
11 KiB
Dart

import 'dart:collection';
import 'dart:ui';
import 'package:easy_localization/easy_localization.dart';
import 'package:flutter/material.dart';
import 'package:flutter_html/html_parser.dart';
import 'package:flutter_svg/flutter_svg.dart';
import 'package:mohem_flutter_app/api/my_team/my_team_api_client.dart';
import 'package:mohem_flutter_app/api/worklist/worklist_api_client.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/dashboard/menu_entries.dart';
import 'package:mohem_flutter_app/models/generic_response_model.dart';
import 'package:mohem_flutter_app/models/my_team/get_employee_subordinates_list.dart';
import 'package:mohem_flutter_app/models/profile_menu.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';
import 'package:mohem_flutter_app/provider/dashboard_provider_model.dart';
import 'package:mohem_flutter_app/widgets/circular_avatar.dart';
import 'package:url_launcher/url_launcher.dart';
class EmployeeDetails extends StatefulWidget {
EmployeeDetails();
@override
_EmployeeDetailsState createState() => _EmployeeDetailsState();
}
class _EmployeeDetailsState extends State<EmployeeDetails> {
GetEmployeeSubordinatesList? getEmployeeSubordinates;
static List<GetMenuEntriesList> menuData = [];
List<ProfileMenu> menu =[];
String? selectedFavLetter;
List<String>? favLetters;
List<GetFavoriteReplacements>? favUsersList;
List<ReplacementList>? replacementList;
@override
void initState() {
super.initState();
// setState(() {});
}
//favorite
void fetchChangeFav({required String email, required String employeName, required String image, required String userName, bool isFav = false, bool isNeedToRefresh = false}) async {
Utils.showLoading(context);
getEmployeeSubordinates = ModalRoute.of(context)?.settings.arguments as GetEmployeeSubordinatesList;
GenericResponseModel model = await MyTeamApiClient().changeFavoriteReplacements(
email: email,
employeName: employeName,
image: image,
userName: userName,
isFav: isFav,
);
getEmployeeSubordinates!.isFavorite = isFav;
Utils.hideLoading(context);
setState(() {});
}
@override
Widget build(BuildContext context) {
if(getEmployeeSubordinates == null) {
getEmployeeSubordinates = ModalRoute.of(context)?.settings.arguments as GetEmployeeSubordinatesList;
setMenu();
}
return Scaffold(
extendBody: true,
backgroundColor: MyColors.lightGreyEFColor,
body: Stack(children: [
Container(
height: 200,
margin: EdgeInsets.only(top: 30),
decoration: BoxDecoration(image: DecorationImage(image: MemoryImage(Utils.getPostBytes(getEmployeeSubordinates!.eMPLOYEEIMAGE)), fit: BoxFit.cover)),
child: new BackdropFilter(
filter: new ImageFilter.blur(sigmaX: 10.0, sigmaY: 10.0),
child: new Container(
decoration: new BoxDecoration(color: Colors.white.withOpacity(0.0)),
),
),
),
SingleChildScrollView(
scrollDirection: Axis.vertical,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
60.height,
Container(
padding: EdgeInsets.only(left: 15, right: 15, bottom: 8),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: [
IconButton(
onPressed: () {
Navigator.pop(context);
},
icon: Icon(
Icons.arrow_back_ios,
color: Colors.white,
),
),
],
),
),
myTeamInfo()
],
),
)
]));
}
Widget myTeamInfo() {
Uri phoneNumber = Uri.parse('tel:${getEmployeeSubordinates?.eMPLOYEEMOBILENUMBER}');
double _width = MediaQuery
.of(context)
.size
.width;
return Column(
children: [
Stack(children: [
Container(
margin: EdgeInsets.fromLTRB(21, 40, 21, 0),
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
IconButton(
onPressed: (){
if(getEmployeeSubordinates!.isFavorite != true){
showFavoriteAlertDialog(context);
setState(() {});
}else{
fetchChangeFav(
email: getEmployeeSubordinates?.eMPLOYEEEMAILADDRESS ?? "",
employeName: getEmployeeSubordinates!.eMPLOYEENAME ?? "",
image: getEmployeeSubordinates!.eMPLOYEEIMAGE ?? "",
userName: getEmployeeSubordinates!.eMPLOYEENUMBER ?? "",
isFav: false,);
setState(() {});
} },
icon: getEmployeeSubordinates!.isFavorite != true
? Icon(
Icons.star_outline,
size: 35,
color: MyColors.green9CColor,
)
: Icon(
Icons.star_outlined,
size: 35,
color: MyColors.green9CColor,
),
),
getEmployeeSubordinates?.eMPLOYEEMOBILENUMBER == ""
? SvgPicture.asset("assets/images/call-disable.svg", height: 25, width: 25,).paddingOnly(left:6, right: 17)
: InkWell(
onTap:() {
launchUrl(phoneNumber);
},
child: SvgPicture.asset("assets/images/call.svg", height: 25, width: 25,).paddingOnly(left:6, right: 17),
),
],
),
getEmployeeSubordinates!.eMPLOYEENAME!.toText21(maxlines: 2),
("${getEmployeeSubordinates!.eMPLOYEENUMBER!} | ${getEmployeeSubordinates!.jOBNAME!}").toText13(color: MyColors.grey80Color),
getEmployeeSubordinates!.eMPLOYEEEMAILADDRESS!.toText13(),
],
).objectContainerView(),
),
Container(
height: 68, alignment: Alignment.center, child: ProfileImage()).paddingOnly(top: 10),
]),
12.height,
Container(
margin: EdgeInsets.fromLTRB(21, 0, 21, 0),
child: Column(
children: menu.map((ProfileMenu i) => rowItem(i, context)).toList(),
).objectContainerView(),
),
// ),
],
);
}
Widget ProfileImage() =>
getEmployeeSubordinates?.eMPLOYEEIMAGE == null
? SvgPicture.asset("assets/images/user.svg",height: 68, width: 68, )
: CircleAvatar(
radius: 70,
backgroundImage: MemoryImage(Utils.getPostBytes(getEmployeeSubordinates?.eMPLOYEEIMAGE)),
backgroundColor: Colors.black,
);
Widget rowItem(obj, context) {
return InkWell(
onTap: () {
Navigator.pushNamed(context, obj.route, arguments:obj.arguments);
},
child: ListTile(
leading: SvgPicture.asset('assets/images/' + obj.icon),
title: Text(obj.name,
style: TextStyle(color: MyColors.grey3AColor,
fontSize: 16)),
trailing: Icon(Icons.arrow_forward,
color: MyColors.grey3AColor,),
),
);
}
void setMenu(){
menu = [
ProfileMenu(name: LocaleKeys.profileDetails.tr(), icon: "profile_details.svg", route: AppRoutes.profileDetails, arguments:getEmployeeSubordinates),
ProfileMenu(name: LocaleKeys.createRequest.tr(), icon: "create_request.svg", route: AppRoutes.createRequest,arguments: getEmployeeSubordinates),
ProfileMenu(name: LocaleKeys.viewAttendance.tr(), icon: "view_attendance.svg", route: AppRoutes.viewAttendance, arguments: getEmployeeSubordinates),
ProfileMenu(name: LocaleKeys.teamMembers.tr(), icon: "team.svg", route: AppRoutes.teamMembers, arguments: getEmployeeSubordinates),
];
}
void showFavoriteAlertDialog(BuildContext context) {
Widget cancelButton = TextButton(
child: Text(
LocaleKeys.cancel.tr(),
),
onPressed: () {
Navigator.pop(context);
},
);
Widget continueButton = TextButton(
child: Text(
LocaleKeys.ok.tr(),
),
onPressed: () {
fetchChangeFav(
email: getEmployeeSubordinates?.eMPLOYEEEMAILADDRESS ?? "",
employeName: getEmployeeSubordinates!.eMPLOYEENAME ?? "",
image: getEmployeeSubordinates!.eMPLOYEEIMAGE ?? "",
userName: getEmployeeSubordinates!.eMPLOYEENUMBER ?? "",
isFav: true,
);
setState(() {});
Navigator.pop(context);
},
);
AlertDialog alert = AlertDialog(
title: Text(
LocaleKeys.confirm.tr(),
),
content: Container(
height: 150,
child: Column(
children: [
Text("Do you want to add" + "${getEmployeeSubordinates!.eMPLOYEENAME.toString()}" + "in your favorite list "),
CircularAvatar(
url: getEmployeeSubordinates!.eMPLOYEEIMAGE ?? "",
height: 50,
width: 50,
isImageBase64: true,
).paddingOnly(top: 21),
// 16.width,
],
),
),
actions: [
cancelButton,
continueButton,
],
);
showDialog(
context: context,
builder: (BuildContext context) {
return alert;
},
);
}
}
GetMenuEntriesList getMenuEntries(String type) {
List<GetMenuEntriesList> data = _EmployeeDetailsState.menuData.where((GetMenuEntriesList test) => test.functionName == type).toList();
if (data.isNotEmpty) {
return data[0];
} else {
return GetMenuEntriesList();
}
}