From 6c2480edd28b688f622d34d2e1ec2aa3bf618ca8 Mon Sep 17 00:00:00 2001 From: zaid_daoud Date: Wed, 23 Aug 2023 13:06:38 +0300 Subject: [PATCH] stop loading on null values --- .../user/gas_refill/request_gas_refill.dart | 7 +- .../gas_refill/building_type_menu.dart | 111 +++++++++--------- .../gas_refill/department_type_menu.dart | 79 +++++++------ .../widgets/gas_refill/floor_type_menu.dart | 79 ++++++------- .../service_report_fault_description.dart | 2 +- 5 files changed, 142 insertions(+), 136 deletions(-) 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 83fb8f47..944be588 100644 --- a/lib/views/pages/user/gas_refill/request_gas_refill.dart +++ b/lib/views/pages/user/gas_refill/request_gas_refill.dart @@ -16,7 +16,6 @@ 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'; -import 'package:test_sa/views/widgets/date_and_time/time_picker.dart'; import 'package:test_sa/views/widgets/gas_refill/building_type_menu.dart'; import 'package:test_sa/views/widgets/gas_refill/department_type_menu.dart'; import 'package:test_sa/views/widgets/gas_refill/floor_type_menu.dart'; @@ -31,7 +30,6 @@ import 'package:test_sa/views/widgets/titles/app_sub_title.dart'; import '../../../../controllers/localization/localization.dart'; import '../../../../controllers/providers/api/hospitals_provider.dart'; -import '../../../../models/enums/user_types.dart'; import '../../../widgets/e_signature/e_signature.dart'; import '../../../widgets/timer/app_timer.dart'; @@ -107,7 +105,7 @@ class _RequestGasRefillState extends State { msg: _subtitle.requestCompleteSuccessfully, ); Navigator.of(context).pop(_formModel.status); - setState(() { }); + setState(() {}); } else { String errorMessage = HttpStatusManger.getStatusMessage(status: status, subtitle: _subtitle); ScaffoldMessenger.of(context).showSnackBar(SnackBar( @@ -255,6 +253,7 @@ class _RequestGasRefillState extends State { BuildingTypeMenu( initialValue: _gasRefillProvider?.building, building: _gasRefillProvider?.hospital?.buildings, + loading: _firstTime, enabled: widget.gasRefillModel == null, onSelect: (status) { _gasRefillProvider.building = status; @@ -266,6 +265,7 @@ class _RequestGasRefillState extends State { initialValue: _gasRefillProvider?.floor, floors: _gasRefillProvider?.building?.floors, enabled: widget.gasRefillModel == null, + loading: _firstTime, onSelect: (status) { _gasRefillProvider.floor = status; setState(() {}); @@ -275,6 +275,7 @@ class _RequestGasRefillState extends State { DepartmentTypeMenu( initialValue: _gasRefillProvider?.department, departments: _gasRefillProvider?.floor?.departments, + loading: _firstTime, enabled: widget.gasRefillModel == null, onSelect: (status) { _gasRefillProvider.department = status; diff --git a/lib/views/widgets/gas_refill/building_type_menu.dart b/lib/views/widgets/gas_refill/building_type_menu.dart index 7509fe4d..b11b48d2 100644 --- a/lib/views/widgets/gas_refill/building_type_menu.dart +++ b/lib/views/widgets/gas_refill/building_type_menu.dart @@ -9,9 +9,16 @@ class BuildingTypeMenu extends StatefulWidget { final Function(Buildings) onSelect; Buildings initialValue; List building; - bool enabled; + bool enabled, loading; - BuildingTypeMenu({Key key, this.onSelect, this.initialValue, this.building = const [], this.enabled = true}) : super(key: key); + BuildingTypeMenu({ + Key key, + this.onSelect, + this.initialValue, + this.building = const [], + this.enabled = true, + this.loading = false, + }) : super(key: key); @override _BuildingTypeMenuState createState() { @@ -50,59 +57,55 @@ class _BuildingTypeMenuState extends State { @override Widget build(BuildContext context) { return Container( - padding: const EdgeInsets.symmetric(horizontal: 16), - decoration: BoxDecoration( - color: AColors.inputFieldBackgroundColor, - border: Border.all( - color: const Color(0xffefefef), + padding: const EdgeInsets.symmetric(horizontal: 16), + decoration: BoxDecoration( + color: AColors.inputFieldBackgroundColor, + border: Border.all( + color: const Color(0xffefefef), + ), + borderRadius: BorderRadius.circular(AppStyle.borderRadius * AppStyle.getScaleFactor(context)), + // boxShadow: const [ + // AppStyle.boxShadow + // ] ), - borderRadius: BorderRadius.circular(AppStyle.borderRadius * AppStyle.getScaleFactor(context)), - // boxShadow: const [ - // AppStyle.boxShadow - // ] - ), - 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 + child: widget.loading + ? const Padding(padding: EdgeInsets.all(8.0), child: ALoading()) + : (widget.enabled && (_building?.isEmpty ?? false)) || (!widget.enabled) + ? ListTile( + title: Center(child: Text(widget.initialValue?.name ?? "")), + ) + : 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 3ea429b8..06cdfcdf 100644 --- a/lib/views/widgets/gas_refill/department_type_menu.dart +++ b/lib/views/widgets/gas_refill/department_type_menu.dart @@ -9,7 +9,7 @@ class DepartmentTypeMenu extends StatefulWidget { final Function(Departments) onSelect; Departments initialValue; List departments; - bool enabled; + bool enabled, loading; DepartmentTypeMenu({ Key key, @@ -17,6 +17,7 @@ class DepartmentTypeMenu extends StatefulWidget { this.initialValue, this.departments = const [], this.enabled = true, + this.loading = false, }) : super(key: key); @override @@ -67,43 +68,45 @@ class _DepartmentTypeMenuState extends State { // AppStyle.boxShadow // ] ), - 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() ?? - [], - ) - : widget.initialValue == null - ? const Padding(padding: EdgeInsets.all(8.0), child: ALoading()) - : ListTile(title: Center(child: Text(widget.initialValue.name))), + child: widget.loading + ? const Padding(padding: EdgeInsets.all(8.0), child: ALoading()) + : (widget.enabled && (_departments?.isEmpty ?? false)) || (!widget.enabled) + ? ListTile( + title: Center(child: Text(widget.initialValue?.name ?? "")), + ) + : 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() ?? + [], + ), ); } } diff --git a/lib/views/widgets/gas_refill/floor_type_menu.dart b/lib/views/widgets/gas_refill/floor_type_menu.dart index 5c29fac1..dcc80c81 100644 --- a/lib/views/widgets/gas_refill/floor_type_menu.dart +++ b/lib/views/widgets/gas_refill/floor_type_menu.dart @@ -10,6 +10,7 @@ class FloorTypeMenu extends StatefulWidget { Floors initialValue; List floors; bool enabled; + bool loading; FloorTypeMenu({ Key key, @@ -17,6 +18,7 @@ class FloorTypeMenu extends StatefulWidget { this.initialValue, this.floors = const [], this.enabled = true, + this.loading = false, }) : super(key: key); @override @@ -67,47 +69,44 @@ class _FloorTypeMenuState extends State { // AppStyle.boxShadow // ] ), - 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(), + child: widget.loading + ? const Padding(padding: EdgeInsets.all(8.0), child: ALoading()) + : (widget.enabled && (_floors?.isEmpty ?? false)) || (!widget.enabled) + ? ListTile( + title: Center(child: Text(widget.initialValue?.name ?? "")), ) - : ListTile( - title: Center(child: Text(widget.initialValue.name)), + : 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() ?? + [], ), ); } diff --git a/lib/views/widgets/status/report/service_report_fault_description.dart b/lib/views/widgets/status/report/service_report_fault_description.dart index d9fc5331..facda9dd 100644 --- a/lib/views/widgets/status/report/service_report_fault_description.dart +++ b/lib/views/widgets/status/report/service_report_fault_description.dart @@ -22,7 +22,7 @@ class ServiceReportFaultDescription extends StatelessWidget { UserProvider userProvider = Provider.of(context); ServiceRequestFaultDescriptionProvider menuProvider = Provider.of(context); return LoadingManager( - isLoading: (menuProvider?.isLoading ?? false) || (enabled && (menuProvider.items?.isEmpty ?? true) || (!enabled && (initialValue?.defectName?.isEmpty ?? true))), + isLoading: menuProvider.isLoading, isFailedLoading: menuProvider.items == null, stateCode: menuProvider.stateCode, onRefresh: () async {