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/my_team.dart

242 lines
10 KiB
Dart

import 'package:flutter/material.dart';
import 'package:mohem_flutter_app/api/my_team/my_team_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/string_extensions.dart';
import 'package:mohem_flutter_app/extensions/widget_extensions.dart';
import 'package:mohem_flutter_app/models/my_team/get_employee_subordinates_list.dart';
import 'package:mohem_flutter_app/widgets/app_bar_widget.dart';
import 'package:url_launcher/url_launcher.dart';
class MyTeam extends StatefulWidget {
const MyTeam({Key? key}) : super(key: key);
@override
_MyTeamState createState() => _MyTeamState();
}
class _MyTeamState extends State<MyTeam> {
String searchEmpEmail ="";
String searchEmpName ="";
String searchEmpNo = "";
String? empId;
List<GetEmployeeSubordinatesList> getEmployeeSubordinatesList = [];
TextEditingController? _textEditingController = TextEditingController();
List<GetEmployeeSubordinatesList> getEmployeeSListOnSearch = [];
String dropdownValue = 'Name';
void initState() {
super.initState();
getEmployeeSubordinates();
}
void getEmployeeSubordinates() async {
try {
Utils.showLoading(context);
getEmployeeSubordinatesList = await MyTeamApiClient().getEmployeeSubordinates(searchEmpEmail.toString(), searchEmpName.toString(), searchEmpNo.toString());
getEmployeeSListOnSearch =getEmployeeSubordinatesList;
Utils.hideLoading(context);
setState(() {});
} catch (ex) {
Utils.hideLoading(context);
Utils.handleException(ex, context, null);
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBarWidget(
context,
title:"My Team Members",
),
backgroundColor: MyColors.backgroundColor,
body: SingleChildScrollView(
child: Column(
children: [
Container(
width: double.infinity,
margin: EdgeInsets.only(
top: 28,
left: 18,
right: 18,
// bottom: 28
),
padding: EdgeInsets.only( left: 10, right: 10),
height: 65,
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.5),
spreadRadius: 5,
blurRadius: 26,
offset: Offset(0, 3),
),
],
color: Colors.white,
borderRadius: BorderRadius.circular(10.0),
),
child:
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children : <Widget>[
Expanded(
child:
TextField(
onChanged: dropdownValue =="Name" ?
(String value){
getEmployeeSListOnSearch = getEmployeeSubordinatesList.where((GetEmployeeSubordinatesList element)
=> element.eMPLOYEENAME!.toLowerCase().contains(value.toLowerCase())).toList();
setState(() {});
}: (String value){
getEmployeeSListOnSearch = getEmployeeSubordinatesList.where((GetEmployeeSubordinatesList element)
=> element.eMPLOYEEEMAILADDRESS!.toLowerCase().contains(value.toLowerCase())).toList();
setState(() {});
},
controller: _textEditingController,
decoration: InputDecoration(
filled: true,
fillColor: Colors.white,
border: InputBorder.none,
enabledBorder: InputBorder.none,
focusedBorder: InputBorder.none,
// contentPadding: EdgeInsets.fromLTRB(10, 15, 10, 15),
hintText: 'Search by $dropdownValue',
hintStyle: TextStyle(fontSize: 16.0, color: Colors.black,),
),
)),
dropDown()
]),
),
Container(
width: MediaQuery.of(context).size.width,
child: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: Column(
children: <Widget>[
_textEditingController!.text.isNotEmpty && getEmployeeSListOnSearch.isEmpty ?
Container(
child: "No Results found".toText16(color: MyColors.blackColor),).paddingOnly(top: 10)
: ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
physics: ScrollPhysics(),
itemCount: _textEditingController!.text.isNotEmpty ? getEmployeeSListOnSearch.length : getEmployeeSubordinatesList.length,
itemBuilder: (context, index) {
var phoneNumber = Uri.parse('tel:${getEmployeeSListOnSearch[index].eMPLOYEEMOBILENUMBER}');
return Container(
width: double.infinity,
margin: EdgeInsets.only(
top: 18,
left: 18,
right: 18,
),
padding: EdgeInsets.only(left: 10, right: 10, top: 10, bottom: 10),
// height: 110,
decoration: BoxDecoration(
boxShadow: [
BoxShadow(
color: Colors.grey.withOpacity(0.5),
spreadRadius: 5,
blurRadius: 26,
offset: Offset(0, 3),
),
],
color: Colors.white,
borderRadius: BorderRadius.circular(10.0),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Row(
children: [
Column(
children: [
CircleAvatar(
radius: 25,
backgroundImage: MemoryImage(Utils.getPostBytes(getEmployeeSListOnSearch[index].eMPLOYEEIMAGE)),
backgroundColor: Colors.black,
),
],
),
SizedBox(
width: 10,
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
"Present".toText13(color: MyColors.greenColor),
"${getEmployeeSListOnSearch[index].eMPLOYEENAME}".toText16(color: MyColors.blackColor),
"${getEmployeeSListOnSearch[index].pOSITIONNAME}".toText13(color: MyColors.blackColor),
],
),
],
),
Column(
children: [
IconButton(
onPressed: () {
launchUrl(phoneNumber);
},
icon: Icon(
Icons.whatsapp,
color: Colors.green,
),
),
IconButton(
onPressed: () async{
Navigator.pushNamed(context,AppRoutes.employeeDetails,arguments: getEmployeeSListOnSearch[index]);
// Navigator.of(context).push(MaterialPageRoute(builder: (context)=> EmployeeDetails(getEmployeeSubordinates: getEmployeeSubordinatesList[index])),);
},
icon: Icon(
Icons.arrow_forward_outlined,
color: Colors.grey,
),
),
],
),
],
),
);
})
],
),
)
)
],
),
)
);
}
Widget dropDown(){
return DropdownButton<String>(
value: dropdownValue,
icon: const Icon(Icons.keyboard_arrow_down),
elevation: 16,
onChanged: (String? newValue) {
setState(() {
dropdownValue = newValue!;
});
},
items: <String>['Name', 'Email']
.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
);
}
}