gaz refill timer

main_design2.0
zaid_daoud 2 years ago
parent 13d4b71128
commit d80e28f706

@ -1,4 +1,5 @@
import 'dart:convert'; import 'dart:convert';
import 'dart:developer';
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:http/http.dart'; import 'package:http/http.dart';
@ -113,10 +114,10 @@ class GasRefillProvider extends ChangeNotifier {
"floor": {"id": floor?.id, "name": floor?.name, "value": floor?.value}, "floor": {"id": floor?.id, "name": floor?.name, "value": floor?.value},
if (expectedDateTime != null) "expectedDate": expectedDateTime?.toIso8601String(), if (expectedDateTime != null) "expectedDate": expectedDateTime?.toIso8601String(),
if (expectedDateTime != null) "expectedTime": expectedDateTime?.toIso8601String(), if (expectedDateTime != null) "expectedTime": expectedDateTime?.toIso8601String(),
if (startDate != null) "startDate": startDate?.toIso8601String(), if (timer?.startAt != null) "startDate": timer.startAt.toIso8601String(),
if (startDate != null) "startTime": startDate?.toIso8601String(), if (timer?.startAt != null) "startTime": timer.startAt.toIso8601String(),
if (endDate != null) "endDate": endDate?.toIso8601String(), if (timer?.endAt != null) "endDate": timer.endAt.toIso8601String(),
if (endDate != null) "endTime": endDate?.toIso8601String(), if (timer?.endAt != null) "endTime": timer.endAt.toIso8601String(),
"department": {"id": department?.id, "departmentName": department?.name, "departmentCode": "", "ntCode": ""}, "department": {"id": department?.id, "departmentName": department?.name, "departmentCode": "", "ntCode": ""},
"GazRefillNo": "GR-${DateTime.now().toString().split(" ").first}", "GazRefillNo": "GR-${DateTime.now().toString().split(" ").first}",
"status": model.status.toMap(), "status": model.status.toMap(),
@ -159,12 +160,12 @@ class GasRefillProvider extends ChangeNotifier {
"status": newModel.status.toMap(), "status": newModel.status.toMap(),
"expectedDate": newModel.expectedDate?.toIso8601String(), "expectedDate": newModel.expectedDate?.toIso8601String(),
"expectedTime": newModel.expectedDate?.toIso8601String(), "expectedTime": newModel.expectedDate?.toIso8601String(),
"startDate": newModel.startDate?.toIso8601String(), if (timer?.startAt != null) "startDate": timer.startAt.toIso8601String(),
"startTime": newModel.startDate?.toIso8601String(), if (timer?.startAt != null) "startTime": timer.startAt.toIso8601String(),
"endDate": newModel.endDate?.toIso8601String(), if (timer?.endAt != null) "endDate": timer.endAt.toIso8601String(),
"endTime": newModel.endDate?.toIso8601String(), if (timer?.endAt != null) "endTime": timer.endAt.toIso8601String(),
// "workingHours": ((endDate?.difference(startDate)?.inMinutes ?? 0) / 60), // "workingHours": ((endDate?.difference(startDate)?.inMinutes ?? 0) / 60),
'workingHours': newModel.workingHours, 'workingHours': timer.durationInSecond != null ? timer.durationInSecond / 60 / 60 : newModel.workingHours,
"assignedEmployee": oldModel?.assignedEmployee?.id == null ? null : oldModel?.assignedEmployee?.toJson(), "assignedEmployee": oldModel?.assignedEmployee?.id == null ? null : oldModel?.assignedEmployee?.toJson(),
"site": hospital?.toMap(), "site": hospital?.toMap(),
"building": building?.toJson(includeFloors: false), "building": building?.toJson(includeFloors: false),
@ -183,24 +184,25 @@ class GasRefillProvider extends ChangeNotifier {
"deliverdQty": model.deliveredQuantity, "deliverdQty": model.deliveredQuantity,
}) })
.toList(); .toList();
log(body.toString());
Response response; return -1;
try { // Response response;
response = await ApiManager.instance.put(URLs.updateGasRefill, body: body); // try {
// response = await post( // response = await ApiManager.instance.put(URLs.updateGasRefill, body: body);
// Uri.parse("$host${URLs.updateGasRefill}/${newModel.id}"), // // response = await post(
// body: body, // // Uri.parse("$host${URLs.updateGasRefill}/${newModel.id}"),
// ); // // body: body,
// // );
stateCode = response.statusCode; //
if (response.statusCode >= 200 && response.statusCode < 300) { // stateCode = response.statusCode;
oldModel.fromGasRefillModel(newModel); // if (response.statusCode >= 200 && response.statusCode < 300) {
notifyListeners(); // oldModel.fromGasRefillModel(newModel);
} // notifyListeners();
return response.statusCode; // }
} catch (error) { // return response.statusCode;
return -1; // } catch (error) {
} // return -1;
// }
} }
Hospital hospital; Hospital hospital;
@ -208,7 +210,5 @@ class GasRefillProvider extends ChangeNotifier {
Floors floor; Floors floor;
Departments department; Departments department;
DateTime expectedDateTime; DateTime expectedDateTime;
DateTime startDate;
DateTime endDate;
TimerModel timer; TimerModel timer;
} }

@ -12,6 +12,7 @@ import 'package:test_sa/models/gas_refill/gas_refill_details.dart';
import 'package:test_sa/models/gas_refill/gas_refill_model.dart'; import 'package:test_sa/models/gas_refill/gas_refill_model.dart';
import 'package:test_sa/models/lookup.dart'; import 'package:test_sa/models/lookup.dart';
import 'package:test_sa/models/subtitle.dart'; import 'package:test_sa/models/subtitle.dart';
import 'package:test_sa/models/timer_model.dart';
import 'package:test_sa/views/app_style/sizing.dart'; import 'package:test_sa/views/app_style/sizing.dart';
import 'package:test_sa/views/widgets/app_text_form_field.dart'; import 'package:test_sa/views/widgets/app_text_form_field.dart';
import 'package:test_sa/views/widgets/buttons/app_button.dart'; import 'package:test_sa/views/widgets/buttons/app_button.dart';
@ -156,14 +157,15 @@ class _RequestGasRefillState extends State<RequestGasRefill> {
if (widget.gasRefillModel != null) { if (widget.gasRefillModel != null) {
_formModel.status = const Lookup(value: 0); _formModel.status = const Lookup(value: 0);
_gasRefillProvider.expectedDateTime = _formModel.expectedDate; _gasRefillProvider.expectedDateTime = _formModel.expectedDate;
_gasRefillProvider.timer = TimerModel(startAt: widget.gasRefillModel?.startDate, endAt: widget.gasRefillModel?.endDate);
} else {
_gasRefillProvider.timer = null;
} }
HospitalsProvider().getHospitalsListByVal(searchVal: _userProvider.user?.clientName).then((value) { HospitalsProvider().getHospitalsListByVal(searchVal: _userProvider.user?.clientName).then((value) {
_gasRefillProvider.hospital = value?.firstWhere((element) => element.name == _userProvider.user?.clientName, orElse: () => null); _gasRefillProvider.hospital = value?.firstWhere((element) => element.name == _userProvider.user?.clientName, orElse: () => null);
_gasRefillProvider.building = _gasRefillProvider.hospital?.buildings?.firstWhere((element) => element.name == widget.gasRefillModel?.building?.name, orElse: () => null); _gasRefillProvider.building = _gasRefillProvider.hospital?.buildings?.firstWhere((element) => element.name == widget.gasRefillModel?.building?.name, orElse: () => null);
_gasRefillProvider.floor = _gasRefillProvider.building?.floors?.firstWhere((element) => element.name == widget.gasRefillModel?.floor?.name, orElse: () => null); _gasRefillProvider.floor = _gasRefillProvider.building?.floors?.firstWhere((element) => element.name == widget.gasRefillModel?.floor?.name, orElse: () => null);
_gasRefillProvider.department = _gasRefillProvider.floor?.departments?.firstWhere((element) => element.name == widget.gasRefillModel?.department?.departmentName, orElse: () => null); _gasRefillProvider.department = _gasRefillProvider.floor?.departments?.firstWhere((element) => element.name == widget.gasRefillModel?.department?.departmentName, orElse: () => null);
_gasRefillProvider.startDate = widget.gasRefillModel?.startDate;
_gasRefillProvider.endDate = widget.gasRefillModel?.endDate;
_firstTime = false; _firstTime = false;
setState(() {}); setState(() {});
}); });
@ -252,6 +254,7 @@ class _RequestGasRefillState extends State<RequestGasRefill> {
BuildingTypeMenu( BuildingTypeMenu(
initialValue: _gasRefillProvider?.building, initialValue: _gasRefillProvider?.building,
building: _gasRefillProvider?.hospital?.buildings, building: _gasRefillProvider?.hospital?.buildings,
enabled: widget.gasRefillModel == null,
onSelect: (status) { onSelect: (status) {
_gasRefillProvider.building = status; _gasRefillProvider.building = status;
setState(() {}); setState(() {});
@ -261,6 +264,7 @@ class _RequestGasRefillState extends State<RequestGasRefill> {
FloorTypeMenu( FloorTypeMenu(
initialValue: _gasRefillProvider?.floor, initialValue: _gasRefillProvider?.floor,
floors: _gasRefillProvider?.building?.floors, floors: _gasRefillProvider?.building?.floors,
enabled: widget.gasRefillModel == null,
onSelect: (status) { onSelect: (status) {
_gasRefillProvider.floor = status; _gasRefillProvider.floor = status;
setState(() {}); setState(() {});
@ -270,6 +274,7 @@ class _RequestGasRefillState extends State<RequestGasRefill> {
DepartmentTypeMenu( DepartmentTypeMenu(
initialValue: _gasRefillProvider?.department, initialValue: _gasRefillProvider?.department,
departments: _gasRefillProvider?.floor?.departments, departments: _gasRefillProvider?.floor?.departments,
enabled: widget.gasRefillModel == null,
onSelect: (status) { onSelect: (status) {
_gasRefillProvider.department = status; _gasRefillProvider.department = status;
setState(() {}); setState(() {});
@ -286,8 +291,6 @@ class _RequestGasRefillState extends State<RequestGasRefill> {
timer: _gasRefillProvider.timer, timer: _gasRefillProvider.timer,
onChange: (timer) async { onChange: (timer) async {
_gasRefillProvider.timer = timer; _gasRefillProvider.timer = timer;
_formModel.startDate ??= timer.startAt;
_gasRefillProvider.endDate = timer.endAt;
_formModel.workingHours = num.tryParse((((timer?.durationInSecond ?? 0) / 60) / 60)?.toStringAsFixed(2) ?? "0"); _formModel.workingHours = num.tryParse((((timer?.durationInSecond ?? 0) / 60) / 60)?.toStringAsFixed(2) ?? "0");
return true; return true;
}, },

@ -3,12 +3,15 @@ import 'package:test_sa/models/hospital.dart';
import 'package:test_sa/views/app_style/colors.dart'; import 'package:test_sa/views/app_style/colors.dart';
import 'package:test_sa/views/app_style/sizing.dart'; import 'package:test_sa/views/app_style/sizing.dart';
import '../loaders/app_loading.dart';
class BuildingTypeMenu extends StatefulWidget { class BuildingTypeMenu extends StatefulWidget {
final Function(Buildings) onSelect; final Function(Buildings) onSelect;
Buildings initialValue; Buildings initialValue;
List<Buildings> building; List<Buildings> building;
bool enabled;
BuildingTypeMenu({Key key, this.onSelect, this.initialValue, this.building = const []}) : super(key: key); BuildingTypeMenu({Key key, this.onSelect, this.initialValue, this.building = const [], this.enabled = true}) : super(key: key);
@override @override
_BuildingTypeMenuState createState() { _BuildingTypeMenuState createState() {
@ -51,46 +54,55 @@ class _BuildingTypeMenuState extends State<BuildingTypeMenu> {
decoration: BoxDecoration( decoration: BoxDecoration(
color: AColors.inputFieldBackgroundColor, color: AColors.inputFieldBackgroundColor,
border: Border.all( border: Border.all(
color: Color(0xffefefef), color: const Color(0xffefefef),
), ),
borderRadius: BorderRadius.circular(AppStyle.borderRadius * AppStyle.getScaleFactor(context)), borderRadius: BorderRadius.circular(AppStyle.borderRadius * AppStyle.getScaleFactor(context)),
// boxShadow: const [ // boxShadow: const [
// AppStyle.boxShadow // AppStyle.boxShadow
// ] // ]
), ),
child: DropdownButton<Buildings>( child: widget.enabled
value: _selectedBuilding, ? DropdownButton<Buildings>(
iconSize: 24, value: _selectedBuilding,
icon: const Icon(Icons.keyboard_arrow_down_rounded), iconSize: 24,
elevation: 0, icon: const Icon(Icons.keyboard_arrow_down_rounded),
isExpanded: true, elevation: 0,
hint: Text( isExpanded: true,
"Select Building", hint: Text(
style: Theme.of(context).textTheme.subtitle1, "Select Building",
), style: Theme.of(context).textTheme.subtitle1,
style: TextStyle(color: Theme.of(context).primaryColor), ),
underline: SizedBox.shrink(), style: TextStyle(color: Theme.of(context).primaryColor),
onChanged: (Buildings newValue) { underline: const SizedBox.shrink(),
setState(() { onChanged: (Buildings newValue) {
_selectedBuilding = newValue; setState(() {
}); _selectedBuilding = newValue;
widget.onSelect(newValue); });
}, widget.onSelect(newValue);
items: _building?.map<DropdownMenuItem<Buildings>>((Buildings value) { },
return DropdownMenuItem<Buildings>( items: _building?.map<DropdownMenuItem<Buildings>>((Buildings value) {
value: value, return DropdownMenuItem<Buildings>(
child: Text( value: value,
value.name ?? "", child: Text(
style: Theme.of(context).textTheme.subtitle1.copyWith( value.name ?? "",
color: Theme.of(context).primaryColor, style: Theme.of(context).textTheme.subtitle1.copyWith(
fontSize: 11, color: Theme.of(context).primaryColor,
//fontWeight: FontWeight.bold fontSize: 11,
//fontWeight: FontWeight.bold
),
), ),
);
})?.toList() ??
[],
)
: widget.initialValue == null
? const Padding(
padding: EdgeInsets.all(8.0),
child: ALoading(),
)
: ListTile(
title: Center(child: Text(widget.initialValue.name)),
), ),
);
})?.toList() ??
[],
),
); );
} }
} }

@ -3,12 +3,21 @@ import 'package:test_sa/models/hospital.dart';
import 'package:test_sa/views/app_style/colors.dart'; import 'package:test_sa/views/app_style/colors.dart';
import 'package:test_sa/views/app_style/sizing.dart'; import 'package:test_sa/views/app_style/sizing.dart';
import '../loaders/app_loading.dart';
class DepartmentTypeMenu extends StatefulWidget { class DepartmentTypeMenu extends StatefulWidget {
final Function(Departments) onSelect; final Function(Departments) onSelect;
Departments initialValue; Departments initialValue;
List<Departments> departments; List<Departments> departments;
bool enabled;
DepartmentTypeMenu({Key key, this.onSelect, this.initialValue, this.departments = const []}) : super(key: key); DepartmentTypeMenu({
Key key,
this.onSelect,
this.initialValue,
this.departments = const [],
this.enabled = true,
}) : super(key: key);
@override @override
_DepartmentTypeMenuState createState() { _DepartmentTypeMenuState createState() {
@ -58,39 +67,43 @@ class _DepartmentTypeMenuState extends State<DepartmentTypeMenu> {
// AppStyle.boxShadow // AppStyle.boxShadow
// ] // ]
), ),
child: DropdownButton<Departments>( child: widget.enabled
value: _selected, ? DropdownButton<Departments>(
iconSize: 24, value: _selected,
icon: const Icon(Icons.keyboard_arrow_down_rounded), iconSize: 24,
elevation: 0, icon: const Icon(Icons.keyboard_arrow_down_rounded),
isExpanded: true, elevation: 0,
hint: Text( isExpanded: true,
"Select Department", hint: Text(
style: Theme.of(context).textTheme.subtitle1, "Select Department",
), style: Theme.of(context).textTheme.subtitle1,
style: TextStyle(color: Theme.of(context).primaryColor), ),
underline: SizedBox.shrink(), style: TextStyle(color: Theme.of(context).primaryColor),
onChanged: (Departments newValue) { underline: SizedBox.shrink(),
setState(() { onChanged: (Departments newValue) {
_selected = newValue; setState(() {
}); _selected = newValue;
widget.onSelect(newValue); });
}, widget.onSelect(newValue);
items: widget?.departments?.map<DropdownMenuItem<Departments>>((Departments value) { },
return DropdownMenuItem<Departments>( items: widget?.departments?.map<DropdownMenuItem<Departments>>((Departments value) {
value: value, return DropdownMenuItem<Departments>(
child: Text( value: value,
value.name, child: Text(
style: Theme.of(context).textTheme.subtitle1.copyWith( value.name,
color: Theme.of(context).primaryColor, style: Theme.of(context).textTheme.subtitle1.copyWith(
fontSize: 11, color: Theme.of(context).primaryColor,
//fontWeight: FontWeight.bold fontSize: 11,
//fontWeight: FontWeight.bold
),
), ),
), );
); })?.toList() ??
})?.toList() ?? [],
[], )
), : widget.initialValue == null
? const Padding(padding: EdgeInsets.all(8.0), child: ALoading())
: ListTile(title: Center(child: Text(widget.initialValue.name))),
); );
} }
} }

@ -3,12 +3,21 @@ import 'package:test_sa/models/hospital.dart';
import 'package:test_sa/views/app_style/colors.dart'; import 'package:test_sa/views/app_style/colors.dart';
import 'package:test_sa/views/app_style/sizing.dart'; import 'package:test_sa/views/app_style/sizing.dart';
import '../loaders/app_loading.dart';
class FloorTypeMenu extends StatefulWidget { class FloorTypeMenu extends StatefulWidget {
final Function(Floors) onSelect; final Function(Floors) onSelect;
Floors initialValue; Floors initialValue;
List<Floors> floors; List<Floors> floors;
bool enabled;
FloorTypeMenu({Key key, this.onSelect, this.initialValue, this.floors = const []}) : super(key: key); FloorTypeMenu({
Key key,
this.onSelect,
this.initialValue,
this.floors = const [],
this.enabled = true,
}) : super(key: key);
@override @override
_FloorTypeMenuState createState() { _FloorTypeMenuState createState() {
@ -51,46 +60,55 @@ class _FloorTypeMenuState extends State<FloorTypeMenu> {
decoration: BoxDecoration( decoration: BoxDecoration(
color: AColors.inputFieldBackgroundColor, color: AColors.inputFieldBackgroundColor,
border: Border.all( border: Border.all(
color: Color(0xffefefef), color: const Color(0xffefefef),
), ),
borderRadius: BorderRadius.circular(AppStyle.borderRadius * AppStyle.getScaleFactor(context)), borderRadius: BorderRadius.circular(AppStyle.borderRadius * AppStyle.getScaleFactor(context)),
// boxShadow: const [ // boxShadow: const [
// AppStyle.boxShadow // AppStyle.boxShadow
// ] // ]
), ),
child: DropdownButton<Floors>( child: widget.enabled
value: _selected, ? DropdownButton<Floors>(
iconSize: 24, value: _selected,
icon: const Icon(Icons.keyboard_arrow_down_rounded), iconSize: 24,
elevation: 0, icon: const Icon(Icons.keyboard_arrow_down_rounded),
isExpanded: true, elevation: 0,
hint: Text( isExpanded: true,
"Select Floor", hint: Text(
style: Theme.of(context).textTheme.subtitle1, "Select Floor",
), style: Theme.of(context).textTheme.subtitle1,
style: TextStyle(color: Theme.of(context).primaryColor), ),
underline: SizedBox.shrink(), style: TextStyle(color: Theme.of(context).primaryColor),
onChanged: (Floors newValue) { underline: const SizedBox.shrink(),
setState(() { onChanged: (Floors newValue) {
_selected = newValue; setState(() {
}); _selected = newValue;
widget.onSelect(newValue); });
}, widget.onSelect(newValue);
items: _floors?.map<DropdownMenuItem<Floors>>((Floors value) { },
return DropdownMenuItem<Floors>( items: _floors?.map<DropdownMenuItem<Floors>>((Floors value) {
value: value, return DropdownMenuItem<Floors>(
child: Text( value: value,
value.name ?? "", child: Text(
style: Theme.of(context).textTheme.subtitle1.copyWith( value.name ?? "",
color: Theme.of(context).primaryColor, style: Theme.of(context).textTheme.subtitle1.copyWith(
fontSize: 11, color: Theme.of(context).primaryColor,
//fontWeight: FontWeight.bold fontSize: 11,
//fontWeight: FontWeight.bold
),
), ),
);
})?.toList() ??
[],
)
: widget.initialValue == null
? const Padding(
padding: EdgeInsets.all(8.0),
child: ALoading(),
)
: ListTile(
title: Center(child: Text(widget.initialValue.name)),
), ),
);
})?.toList() ??
[],
),
); );
} }
} }

Loading…
Cancel
Save