diff --git a/lib/controllers/providers/api/gas_refill_provider.dart b/lib/controllers/providers/api/gas_refill_provider.dart index 1c567e31..40a96203 100644 --- a/lib/controllers/providers/api/gas_refill_provider.dart +++ b/lib/controllers/providers/api/gas_refill_provider.dart @@ -1,4 +1,5 @@ import 'dart:convert'; +import 'dart:developer'; import 'package:flutter/cupertino.dart'; import 'package:http/http.dart'; @@ -113,10 +114,10 @@ class GasRefillProvider extends ChangeNotifier { "floor": {"id": floor?.id, "name": floor?.name, "value": floor?.value}, if (expectedDateTime != null) "expectedDate": expectedDateTime?.toIso8601String(), if (expectedDateTime != null) "expectedTime": expectedDateTime?.toIso8601String(), - if (startDate != null) "startDate": startDate?.toIso8601String(), - if (startDate != null) "startTime": startDate?.toIso8601String(), - if (endDate != null) "endDate": endDate?.toIso8601String(), - if (endDate != null) "endTime": endDate?.toIso8601String(), + if (timer?.startAt != null) "startDate": timer.startAt.toIso8601String(), + if (timer?.startAt != null) "startTime": timer.startAt.toIso8601String(), + if (timer?.endAt != null) "endDate": timer.endAt.toIso8601String(), + if (timer?.endAt != null) "endTime": timer.endAt.toIso8601String(), "department": {"id": department?.id, "departmentName": department?.name, "departmentCode": "", "ntCode": ""}, "GazRefillNo": "GR-${DateTime.now().toString().split(" ").first}", "status": model.status.toMap(), @@ -159,12 +160,12 @@ class GasRefillProvider extends ChangeNotifier { "status": newModel.status.toMap(), "expectedDate": newModel.expectedDate?.toIso8601String(), "expectedTime": newModel.expectedDate?.toIso8601String(), - "startDate": newModel.startDate?.toIso8601String(), - "startTime": newModel.startDate?.toIso8601String(), - "endDate": newModel.endDate?.toIso8601String(), - "endTime": newModel.endDate?.toIso8601String(), + if (timer?.startAt != null) "startDate": timer.startAt.toIso8601String(), + if (timer?.startAt != null) "startTime": timer.startAt.toIso8601String(), + if (timer?.endAt != null) "endDate": timer.endAt.toIso8601String(), + if (timer?.endAt != null) "endTime": timer.endAt.toIso8601String(), // "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(), "site": hospital?.toMap(), "building": building?.toJson(includeFloors: false), @@ -183,24 +184,25 @@ class GasRefillProvider extends ChangeNotifier { "deliverdQty": model.deliveredQuantity, }) .toList(); - - 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; - } + log(body.toString()); + 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; @@ -208,7 +210,5 @@ class GasRefillProvider extends ChangeNotifier { Floors floor; Departments department; DateTime expectedDateTime; - DateTime startDate; - DateTime endDate; TimerModel timer; } diff --git a/lib/views/pages/user/gas_refill/request_gas_refill.dart b/lib/views/pages/user/gas_refill/request_gas_refill.dart index abcb5efe..1278df23 100644 --- a/lib/views/pages/user/gas_refill/request_gas_refill.dart +++ b/lib/views/pages/user/gas_refill/request_gas_refill.dart @@ -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/lookup.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/widgets/app_text_form_field.dart'; import 'package:test_sa/views/widgets/buttons/app_button.dart'; @@ -156,14 +157,15 @@ class _RequestGasRefillState extends State { if (widget.gasRefillModel != null) { _formModel.status = const Lookup(value: 0); _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) { _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.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.startDate = widget.gasRefillModel?.startDate; - _gasRefillProvider.endDate = widget.gasRefillModel?.endDate; _firstTime = false; setState(() {}); }); @@ -252,6 +254,7 @@ class _RequestGasRefillState extends State { BuildingTypeMenu( initialValue: _gasRefillProvider?.building, building: _gasRefillProvider?.hospital?.buildings, + enabled: widget.gasRefillModel == null, onSelect: (status) { _gasRefillProvider.building = status; setState(() {}); @@ -261,6 +264,7 @@ class _RequestGasRefillState extends State { FloorTypeMenu( initialValue: _gasRefillProvider?.floor, floors: _gasRefillProvider?.building?.floors, + enabled: widget.gasRefillModel == null, onSelect: (status) { _gasRefillProvider.floor = status; setState(() {}); @@ -270,6 +274,7 @@ class _RequestGasRefillState extends State { DepartmentTypeMenu( initialValue: _gasRefillProvider?.department, departments: _gasRefillProvider?.floor?.departments, + enabled: widget.gasRefillModel == null, onSelect: (status) { _gasRefillProvider.department = status; setState(() {}); @@ -286,8 +291,6 @@ class _RequestGasRefillState extends State { timer: _gasRefillProvider.timer, onChange: (timer) async { _gasRefillProvider.timer = timer; - _formModel.startDate ??= timer.startAt; - _gasRefillProvider.endDate = timer.endAt; _formModel.workingHours = num.tryParse((((timer?.durationInSecond ?? 0) / 60) / 60)?.toStringAsFixed(2) ?? "0"); return true; }, diff --git a/lib/views/widgets/gas_refill/building_type_menu.dart b/lib/views/widgets/gas_refill/building_type_menu.dart index afccd900..7509fe4d 100644 --- a/lib/views/widgets/gas_refill/building_type_menu.dart +++ b/lib/views/widgets/gas_refill/building_type_menu.dart @@ -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/sizing.dart'; +import '../loaders/app_loading.dart'; + class BuildingTypeMenu extends StatefulWidget { final Function(Buildings) onSelect; Buildings initialValue; List 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 _BuildingTypeMenuState createState() { @@ -51,46 +54,55 @@ class _BuildingTypeMenuState extends State { decoration: BoxDecoration( color: AColors.inputFieldBackgroundColor, border: Border.all( - color: Color(0xffefefef), + color: const Color(0xffefefef), ), borderRadius: BorderRadius.circular(AppStyle.borderRadius * AppStyle.getScaleFactor(context)), // boxShadow: const [ // AppStyle.boxShadow // ] ), - child: DropdownButton( - value: _selectedBuilding, - iconSize: 24, - icon: const Icon(Icons.keyboard_arrow_down_rounded), - elevation: 0, - isExpanded: true, - hint: Text( - "Select Building", - style: Theme.of(context).textTheme.subtitle1, - ), - style: TextStyle(color: Theme.of(context).primaryColor), - underline: SizedBox.shrink(), - onChanged: (Buildings newValue) { - setState(() { - _selectedBuilding = newValue; - }); - widget.onSelect(newValue); - }, - items: _building?.map>((Buildings value) { - return DropdownMenuItem( - value: value, - child: Text( - value.name ?? "", - style: Theme.of(context).textTheme.subtitle1.copyWith( - color: Theme.of(context).primaryColor, - fontSize: 11, - //fontWeight: FontWeight.bold + child: widget.enabled + ? DropdownButton( + value: _selectedBuilding, + iconSize: 24, + icon: const Icon(Icons.keyboard_arrow_down_rounded), + elevation: 0, + isExpanded: true, + hint: Text( + "Select Building", + style: Theme.of(context).textTheme.subtitle1, + ), + style: TextStyle(color: Theme.of(context).primaryColor), + underline: const SizedBox.shrink(), + onChanged: (Buildings newValue) { + setState(() { + _selectedBuilding = newValue; + }); + widget.onSelect(newValue); + }, + items: _building?.map>((Buildings value) { + return DropdownMenuItem( + value: value, + child: Text( + value.name ?? "", + style: Theme.of(context).textTheme.subtitle1.copyWith( + color: Theme.of(context).primaryColor, + 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() ?? - [], - ), ); } } diff --git a/lib/views/widgets/gas_refill/department_type_menu.dart b/lib/views/widgets/gas_refill/department_type_menu.dart index 1b58c200..bd887c74 100644 --- a/lib/views/widgets/gas_refill/department_type_menu.dart +++ b/lib/views/widgets/gas_refill/department_type_menu.dart @@ -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/sizing.dart'; +import '../loaders/app_loading.dart'; + class DepartmentTypeMenu extends StatefulWidget { final Function(Departments) onSelect; Departments initialValue; List 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 _DepartmentTypeMenuState createState() { @@ -58,39 +67,43 @@ class _DepartmentTypeMenuState extends State { // AppStyle.boxShadow // ] ), - child: DropdownButton( - value: _selected, - iconSize: 24, - icon: const Icon(Icons.keyboard_arrow_down_rounded), - elevation: 0, - isExpanded: true, - hint: Text( - "Select Department", - style: Theme.of(context).textTheme.subtitle1, - ), - style: TextStyle(color: Theme.of(context).primaryColor), - underline: SizedBox.shrink(), - onChanged: (Departments newValue) { - setState(() { - _selected = newValue; - }); - widget.onSelect(newValue); - }, - items: widget?.departments?.map>((Departments value) { - return DropdownMenuItem( - value: value, - child: Text( - value.name, - style: Theme.of(context).textTheme.subtitle1.copyWith( - color: Theme.of(context).primaryColor, - fontSize: 11, - //fontWeight: FontWeight.bold + child: widget.enabled + ? DropdownButton( + value: _selected, + iconSize: 24, + icon: const Icon(Icons.keyboard_arrow_down_rounded), + elevation: 0, + isExpanded: true, + hint: Text( + "Select Department", + style: Theme.of(context).textTheme.subtitle1, + ), + style: TextStyle(color: Theme.of(context).primaryColor), + underline: SizedBox.shrink(), + onChanged: (Departments newValue) { + setState(() { + _selected = newValue; + }); + widget.onSelect(newValue); + }, + items: widget?.departments?.map>((Departments value) { + return DropdownMenuItem( + value: value, + child: Text( + value.name, + style: Theme.of(context).textTheme.subtitle1.copyWith( + color: Theme.of(context).primaryColor, + 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))), ); } } diff --git a/lib/views/widgets/gas_refill/floor_type_menu.dart b/lib/views/widgets/gas_refill/floor_type_menu.dart index df5d3325..5c29fac1 100644 --- a/lib/views/widgets/gas_refill/floor_type_menu.dart +++ b/lib/views/widgets/gas_refill/floor_type_menu.dart @@ -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/sizing.dart'; +import '../loaders/app_loading.dart'; + class FloorTypeMenu extends StatefulWidget { final Function(Floors) onSelect; Floors initialValue; List 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 _FloorTypeMenuState createState() { @@ -51,46 +60,55 @@ class _FloorTypeMenuState extends State { decoration: BoxDecoration( color: AColors.inputFieldBackgroundColor, border: Border.all( - color: Color(0xffefefef), + color: const Color(0xffefefef), ), borderRadius: BorderRadius.circular(AppStyle.borderRadius * AppStyle.getScaleFactor(context)), // boxShadow: const [ // AppStyle.boxShadow // ] ), - child: DropdownButton( - value: _selected, - iconSize: 24, - icon: const Icon(Icons.keyboard_arrow_down_rounded), - elevation: 0, - isExpanded: true, - hint: Text( - "Select Floor", - style: Theme.of(context).textTheme.subtitle1, - ), - style: TextStyle(color: Theme.of(context).primaryColor), - underline: SizedBox.shrink(), - onChanged: (Floors newValue) { - setState(() { - _selected = newValue; - }); - widget.onSelect(newValue); - }, - items: _floors?.map>((Floors value) { - return DropdownMenuItem( - value: value, - child: Text( - value.name ?? "", - style: Theme.of(context).textTheme.subtitle1.copyWith( - color: Theme.of(context).primaryColor, - fontSize: 11, - //fontWeight: FontWeight.bold + child: widget.enabled + ? DropdownButton( + value: _selected, + iconSize: 24, + icon: const Icon(Icons.keyboard_arrow_down_rounded), + elevation: 0, + isExpanded: true, + hint: Text( + "Select Floor", + style: Theme.of(context).textTheme.subtitle1, + ), + style: TextStyle(color: Theme.of(context).primaryColor), + underline: const SizedBox.shrink(), + onChanged: (Floors newValue) { + setState(() { + _selected = newValue; + }); + widget.onSelect(newValue); + }, + items: _floors?.map>((Floors value) { + return DropdownMenuItem( + value: value, + child: Text( + value.name ?? "", + style: Theme.of(context).textTheme.subtitle1.copyWith( + color: Theme.of(context).primaryColor, + 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() ?? - [], - ), ); } }