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.
188 lines
8.1 KiB
Dart
188 lines
8.1 KiB
Dart
|
|
import 'dart:io';
|
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
|
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.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/classes/colors.dart';
|
|
import 'package:mohem_flutter_app/classes/date_uitl.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/my_team/get_subordinates_leaves_total_vacations_list_model.dart';
|
|
import 'package:mohem_flutter_app/widgets/app_bar_widget.dart';
|
|
import 'package:mohem_flutter_app/widgets/button/default_button.dart';
|
|
import 'package:mohem_flutter_app/widgets/dynamic_forms/dynamic_textfield_widget.dart';
|
|
|
|
|
|
class SubordinateLeave extends StatefulWidget {
|
|
const SubordinateLeave({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
_SubordinateLeaveState createState() => _SubordinateLeaveState();
|
|
}
|
|
|
|
class _SubordinateLeaveState extends State<SubordinateLeave> {
|
|
List<GetSubordinatesLeavesTotalVacationsList> getSubordinatesLeavesTotalList = [];
|
|
DateTime selectedDateFrom = DateTime.now();
|
|
DateTime selectedDateTo = DateTime.now();
|
|
bool showList = false;
|
|
|
|
|
|
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
}
|
|
|
|
void getSubordinatesLeaves()async {
|
|
try {
|
|
Utils.showLoading(context);
|
|
getSubordinatesLeavesTotalList = await MyTeamApiClient().getSubordinatesLeavesList(DateUtil.convertDateToStringLocation(selectedDateFrom), DateUtil.convertDateToStringLocation(selectedDateTo));
|
|
showList= true;
|
|
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: LocaleKeys.subordinateLeave.tr(),
|
|
),
|
|
backgroundColor: MyColors.backgroundColor,
|
|
body: Column(
|
|
children: [
|
|
Expanded(
|
|
child: SingleChildScrollView(
|
|
scrollDirection: Axis.vertical,
|
|
child: Column(
|
|
children: [
|
|
Column(
|
|
children: [
|
|
DynamicTextFieldWidget(
|
|
LocaleKeys.dateFrom.tr(),
|
|
selectedDateFrom.toString().split(" ")[0],
|
|
suffixIconData: Icons.calendar_today,
|
|
isEnable: false,
|
|
onTap: () async {
|
|
selectedDateFrom = await _selectDate(context, DateTime.now());
|
|
setState(() {});
|
|
},
|
|
),
|
|
12.height,
|
|
DynamicTextFieldWidget(
|
|
LocaleKeys.dateTo.tr(),
|
|
selectedDateTo.toString().split(" ")[0],
|
|
suffixIconData: Icons.calendar_today,
|
|
isEnable: false,
|
|
onTap: () async {
|
|
selectedDateTo = await _selectDate(context, DateTime.now());
|
|
setState(() {});
|
|
},
|
|
)
|
|
],
|
|
).objectContainerView(),
|
|
Container(
|
|
margin: EdgeInsets.only(left: 21, right: 21),
|
|
width: MediaQuery.of(context).size.width,
|
|
child: SingleChildScrollView(
|
|
scrollDirection: Axis.vertical,
|
|
child: Column(
|
|
children: [
|
|
showList? ListView.separated(
|
|
scrollDirection: Axis.vertical,
|
|
shrinkWrap: true,
|
|
physics: ScrollPhysics(),
|
|
separatorBuilder: (BuildContext cxt,int index) => 12.height,
|
|
itemCount: getSubordinatesLeavesTotalList.length,
|
|
itemBuilder: (BuildContext context,int index) {
|
|
var diffDays = DateUtil.convertStringToDate(getSubordinatesLeavesTotalList[index].dATEEND!).difference(DateUtil.convertStringToDate(getSubordinatesLeavesTotalList[index].dATESTART!)).inDays;
|
|
return getSubordinatesLeavesTotalList.isEmpty
|
|
? Utils.getNoDataWidget(context)
|
|
: Row(
|
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
|
children: [
|
|
SvgPicture.asset("assets/images/user.svg"),
|
|
14.width,
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
"${getSubordinatesLeavesTotalList[index].eMPLOYEENAME}".toText16(isBold: true, color: MyColors.grey3AColor),
|
|
10.height,
|
|
Row(
|
|
children: [
|
|
(LocaleKeys.from.tr() + ': ${DateUtil.getFormattedDate(DateUtil.convertStringToDate(getSubordinatesLeavesTotalList[index].dATESTART!), "MMM dd yyyy")}').toText10(isBold: true, color: MyColors.grey57Color),
|
|
14.width,
|
|
(LocaleKeys.to.tr() + ': ${DateUtil.getFormattedDate(DateUtil.convertStringToDate(getSubordinatesLeavesTotalList[index].dATEEND!), "MMM dd yyyy")}').toText10(isBold: true, color: MyColors.grey57Color),
|
|
],
|
|
),
|
|
(LocaleKeys.numberDays.tr()+ ": $diffDays").toText10(color: MyColors.grey3AColor),
|
|
],
|
|
).expanded
|
|
],
|
|
).objectContainerView();
|
|
}
|
|
)
|
|
:Container(),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
DefaultButton(
|
|
LocaleKeys.submit.tr(), () async {
|
|
getSubordinatesLeaves();
|
|
}).insideContainer
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
|
|
|
|
Future<DateTime> _selectDate(BuildContext context, DateTime selectedDate) async {
|
|
DateTime time = selectedDate;
|
|
if (!Platform.isIOS) {
|
|
await showCupertinoModalPopup(
|
|
context: context,
|
|
builder: (cxt) => Container(
|
|
height: 250,
|
|
color: Colors.white,
|
|
child: CupertinoDatePicker(
|
|
backgroundColor: Colors.white,
|
|
mode: CupertinoDatePickerMode.date,
|
|
onDateTimeChanged: (value) {
|
|
if (value != null && value != selectedDate) {
|
|
time = value;
|
|
}
|
|
},
|
|
initialDateTime: selectedDate,
|
|
),
|
|
),
|
|
);
|
|
} else {
|
|
DateTime? picked = await showDatePicker(context: context, initialDate: selectedDate, initialEntryMode: DatePickerEntryMode.calendarOnly, firstDate: DateTime(2015, 8), lastDate: DateTime(2101));
|
|
if (picked != null && picked != selectedDate) {
|
|
time = picked;
|
|
}
|
|
}
|
|
return time;
|
|
}
|
|
}
|