gaz refill timer

main_design2.0
zaid_daoud 3 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;
try {
response = await ApiManager.instance.put(URLs.updateGasRefill, body: body);
// response = await post(
// Uri.parse("$host${URLs.updateGasRefill}/${newModel.id}"),
// body: body,
// );
stateCode = response.statusCode;
if (response.statusCode >= 200 && response.statusCode < 300) {
oldModel.fromGasRefillModel(newModel);
notifyListeners();
}
return response.statusCode;
} catch (error) {
return -1; return -1;
} // Response response;
// try {
// response = await ApiManager.instance.put(URLs.updateGasRefill, body: body);
// // response = await post(
// // Uri.parse("$host${URLs.updateGasRefill}/${newModel.id}"),
// // body: body,
// // );
//
// stateCode = response.statusCode;
// if (response.statusCode >= 200 && response.statusCode < 300) {
// oldModel.fromGasRefillModel(newModel);
// notifyListeners();
// }
// return response.statusCode;
// } 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,14 +54,15 @@ 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
? DropdownButton<Buildings>(
value: _selectedBuilding, value: _selectedBuilding,
iconSize: 24, iconSize: 24,
icon: const Icon(Icons.keyboard_arrow_down_rounded), icon: const Icon(Icons.keyboard_arrow_down_rounded),
@ -69,7 +73,7 @@ class _BuildingTypeMenuState extends State<BuildingTypeMenu> {
style: Theme.of(context).textTheme.subtitle1, style: Theme.of(context).textTheme.subtitle1,
), ),
style: TextStyle(color: Theme.of(context).primaryColor), style: TextStyle(color: Theme.of(context).primaryColor),
underline: SizedBox.shrink(), underline: const SizedBox.shrink(),
onChanged: (Buildings newValue) { onChanged: (Buildings newValue) {
setState(() { setState(() {
_selectedBuilding = newValue; _selectedBuilding = newValue;
@ -90,6 +94,14 @@ class _BuildingTypeMenuState extends State<BuildingTypeMenu> {
); );
})?.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 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,7 +67,8 @@ class _DepartmentTypeMenuState extends State<DepartmentTypeMenu> {
// AppStyle.boxShadow // AppStyle.boxShadow
// ] // ]
), ),
child: DropdownButton<Departments>( child: widget.enabled
? DropdownButton<Departments>(
value: _selected, value: _selected,
iconSize: 24, iconSize: 24,
icon: const Icon(Icons.keyboard_arrow_down_rounded), icon: const Icon(Icons.keyboard_arrow_down_rounded),
@ -90,7 +100,10 @@ class _DepartmentTypeMenuState extends State<DepartmentTypeMenu> {
); );
})?.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,14 +60,15 @@ 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
? DropdownButton<Floors>(
value: _selected, value: _selected,
iconSize: 24, iconSize: 24,
icon: const Icon(Icons.keyboard_arrow_down_rounded), icon: const Icon(Icons.keyboard_arrow_down_rounded),
@ -69,7 +79,7 @@ class _FloorTypeMenuState extends State<FloorTypeMenu> {
style: Theme.of(context).textTheme.subtitle1, style: Theme.of(context).textTheme.subtitle1,
), ),
style: TextStyle(color: Theme.of(context).primaryColor), style: TextStyle(color: Theme.of(context).primaryColor),
underline: SizedBox.shrink(), underline: const SizedBox.shrink(),
onChanged: (Floors newValue) { onChanged: (Floors newValue) {
setState(() { setState(() {
_selected = newValue; _selected = newValue;
@ -90,6 +100,14 @@ class _FloorTypeMenuState extends State<FloorTypeMenu> {
); );
})?.toList() ?? })?.toList() ??
[], [],
)
: widget.initialValue == null
? const Padding(
padding: EdgeInsets.all(8.0),
child: ALoading(),
)
: ListTile(
title: Center(child: Text(widget.initialValue.name)),
), ),
); );
} }

Loading…
Cancel
Save