stop loading on null values

main_design2.0
zaid_daoud 3 years ago
parent 4cbedc0b60
commit 6c2480edd2

@ -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/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';
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/building_type_menu.dart';
import 'package:test_sa/views/widgets/gas_refill/department_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'; 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/localization/localization.dart';
import '../../../../controllers/providers/api/hospitals_provider.dart'; import '../../../../controllers/providers/api/hospitals_provider.dart';
import '../../../../models/enums/user_types.dart';
import '../../../widgets/e_signature/e_signature.dart'; import '../../../widgets/e_signature/e_signature.dart';
import '../../../widgets/timer/app_timer.dart'; import '../../../widgets/timer/app_timer.dart';
@ -107,7 +105,7 @@ class _RequestGasRefillState extends State<RequestGasRefill> {
msg: _subtitle.requestCompleteSuccessfully, msg: _subtitle.requestCompleteSuccessfully,
); );
Navigator.of(context).pop(_formModel.status); Navigator.of(context).pop(_formModel.status);
setState(() { }); setState(() {});
} else { } else {
String errorMessage = HttpStatusManger.getStatusMessage(status: status, subtitle: _subtitle); String errorMessage = HttpStatusManger.getStatusMessage(status: status, subtitle: _subtitle);
ScaffoldMessenger.of(context).showSnackBar(SnackBar( ScaffoldMessenger.of(context).showSnackBar(SnackBar(
@ -255,6 +253,7 @@ class _RequestGasRefillState extends State<RequestGasRefill> {
BuildingTypeMenu( BuildingTypeMenu(
initialValue: _gasRefillProvider?.building, initialValue: _gasRefillProvider?.building,
building: _gasRefillProvider?.hospital?.buildings, building: _gasRefillProvider?.hospital?.buildings,
loading: _firstTime,
enabled: widget.gasRefillModel == null, enabled: widget.gasRefillModel == null,
onSelect: (status) { onSelect: (status) {
_gasRefillProvider.building = status; _gasRefillProvider.building = status;
@ -266,6 +265,7 @@ class _RequestGasRefillState extends State<RequestGasRefill> {
initialValue: _gasRefillProvider?.floor, initialValue: _gasRefillProvider?.floor,
floors: _gasRefillProvider?.building?.floors, floors: _gasRefillProvider?.building?.floors,
enabled: widget.gasRefillModel == null, enabled: widget.gasRefillModel == null,
loading: _firstTime,
onSelect: (status) { onSelect: (status) {
_gasRefillProvider.floor = status; _gasRefillProvider.floor = status;
setState(() {}); setState(() {});
@ -275,6 +275,7 @@ class _RequestGasRefillState extends State<RequestGasRefill> {
DepartmentTypeMenu( DepartmentTypeMenu(
initialValue: _gasRefillProvider?.department, initialValue: _gasRefillProvider?.department,
departments: _gasRefillProvider?.floor?.departments, departments: _gasRefillProvider?.floor?.departments,
loading: _firstTime,
enabled: widget.gasRefillModel == null, enabled: widget.gasRefillModel == null,
onSelect: (status) { onSelect: (status) {
_gasRefillProvider.department = status; _gasRefillProvider.department = status;

@ -9,9 +9,16 @@ class BuildingTypeMenu extends StatefulWidget {
final Function(Buildings) onSelect; final Function(Buildings) onSelect;
Buildings initialValue; Buildings initialValue;
List<Buildings> building; List<Buildings> 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 @override
_BuildingTypeMenuState createState() { _BuildingTypeMenuState createState() {
@ -50,59 +57,55 @@ class _BuildingTypeMenuState extends State<BuildingTypeMenu> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Container( return Container(
padding: const EdgeInsets.symmetric(horizontal: 16), padding: const EdgeInsets.symmetric(horizontal: 16),
decoration: BoxDecoration( decoration: BoxDecoration(
color: AColors.inputFieldBackgroundColor, color: AColors.inputFieldBackgroundColor,
border: Border.all( border: Border.all(
color: const Color(0xffefefef), color: const Color(0xffefefef),
),
borderRadius: BorderRadius.circular(AppStyle.borderRadius * AppStyle.getScaleFactor(context)),
// boxShadow: const [
// AppStyle.boxShadow
// ]
), ),
borderRadius: BorderRadius.circular(AppStyle.borderRadius * AppStyle.getScaleFactor(context)), child: widget.loading
// boxShadow: const [ ? const Padding(padding: EdgeInsets.all(8.0), child: ALoading())
// AppStyle.boxShadow : (widget.enabled && (_building?.isEmpty ?? false)) || (!widget.enabled)
// ] ? ListTile(
), title: Center(child: Text(widget.initialValue?.name ?? "")),
child: widget.enabled )
? DropdownButton<Buildings>( : 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),
elevation: 0, elevation: 0,
isExpanded: true, isExpanded: true,
hint: Text( hint: Text(
"Select Building", "Select Building",
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: const SizedBox.shrink(), underline: const SizedBox.shrink(),
onChanged: (Buildings newValue) { onChanged: (Buildings newValue) {
setState(() { setState(() {
_selectedBuilding = newValue; _selectedBuilding = newValue;
}); });
widget.onSelect(newValue); widget.onSelect(newValue);
}, },
items: _building?.map<DropdownMenuItem<Buildings>>((Buildings value) { items: _building?.map<DropdownMenuItem<Buildings>>((Buildings value) {
return DropdownMenuItem<Buildings>( return DropdownMenuItem<Buildings>(
value: value, value: value,
child: Text( child: Text(
value.name ?? "", value.name ?? "",
style: Theme.of(context).textTheme.subtitle1.copyWith( style: Theme.of(context).textTheme.subtitle1.copyWith(
color: Theme.of(context).primaryColor, color: Theme.of(context).primaryColor,
fontSize: 11, fontSize: 11,
//fontWeight: FontWeight.bold //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)),
),
);
} }
} }

@ -9,7 +9,7 @@ class DepartmentTypeMenu extends StatefulWidget {
final Function(Departments) onSelect; final Function(Departments) onSelect;
Departments initialValue; Departments initialValue;
List<Departments> departments; List<Departments> departments;
bool enabled; bool enabled, loading;
DepartmentTypeMenu({ DepartmentTypeMenu({
Key key, Key key,
@ -17,6 +17,7 @@ class DepartmentTypeMenu extends StatefulWidget {
this.initialValue, this.initialValue,
this.departments = const [], this.departments = const [],
this.enabled = true, this.enabled = true,
this.loading = false,
}) : super(key: key); }) : super(key: key);
@override @override
@ -67,43 +68,45 @@ class _DepartmentTypeMenuState extends State<DepartmentTypeMenu> {
// AppStyle.boxShadow // AppStyle.boxShadow
// ] // ]
), ),
child: widget.enabled child: widget.loading
? DropdownButton<Departments>( ? const Padding(padding: EdgeInsets.all(8.0), child: ALoading())
value: _selected, : (widget.enabled && (_departments?.isEmpty ?? false)) || (!widget.enabled)
iconSize: 24, ? ListTile(
icon: const Icon(Icons.keyboard_arrow_down_rounded), title: Center(child: Text(widget.initialValue?.name ?? "")),
elevation: 0, )
isExpanded: true, : DropdownButton<Departments>(
hint: Text( value: _selected,
"Select Department", iconSize: 24,
style: Theme.of(context).textTheme.subtitle1, icon: const Icon(Icons.keyboard_arrow_down_rounded),
), elevation: 0,
style: TextStyle(color: Theme.of(context).primaryColor), isExpanded: true,
underline: SizedBox.shrink(), hint: Text(
onChanged: (Departments newValue) { "Select Department",
setState(() { style: Theme.of(context).textTheme.subtitle1,
_selected = newValue; ),
}); style: TextStyle(color: Theme.of(context).primaryColor),
widget.onSelect(newValue); underline: SizedBox.shrink(),
}, onChanged: (Departments newValue) {
items: widget?.departments?.map<DropdownMenuItem<Departments>>((Departments value) { setState(() {
return DropdownMenuItem<Departments>( _selected = newValue;
value: value, });
child: Text( widget.onSelect(newValue);
value?.name ?? "", },
style: Theme.of(context).textTheme.subtitle1.copyWith( items: widget?.departments?.map<DropdownMenuItem<Departments>>((Departments value) {
color: Theme.of(context).primaryColor, return DropdownMenuItem<Departments>(
fontSize: 11, value: value,
//fontWeight: FontWeight.bold child: Text(
), value?.name ?? "",
), style: Theme.of(context).textTheme.subtitle1.copyWith(
); color: Theme.of(context).primaryColor,
})?.toList() ?? fontSize: 11,
[], //fontWeight: FontWeight.bold
) ),
: widget.initialValue == null ),
? const Padding(padding: EdgeInsets.all(8.0), child: ALoading()) );
: ListTile(title: Center(child: Text(widget.initialValue.name))), })?.toList() ??
[],
),
); );
} }
} }

@ -10,6 +10,7 @@ class FloorTypeMenu extends StatefulWidget {
Floors initialValue; Floors initialValue;
List<Floors> floors; List<Floors> floors;
bool enabled; bool enabled;
bool loading;
FloorTypeMenu({ FloorTypeMenu({
Key key, Key key,
@ -17,6 +18,7 @@ class FloorTypeMenu extends StatefulWidget {
this.initialValue, this.initialValue,
this.floors = const [], this.floors = const [],
this.enabled = true, this.enabled = true,
this.loading = false,
}) : super(key: key); }) : super(key: key);
@override @override
@ -67,47 +69,44 @@ class _FloorTypeMenuState extends State<FloorTypeMenu> {
// AppStyle.boxShadow // AppStyle.boxShadow
// ] // ]
), ),
child: widget.enabled child: widget.loading
? DropdownButton<Floors>( ? const Padding(padding: EdgeInsets.all(8.0), child: ALoading())
value: _selected, : (widget.enabled && (_floors?.isEmpty ?? false)) || (!widget.enabled)
iconSize: 24, ? ListTile(
icon: const Icon(Icons.keyboard_arrow_down_rounded), title: Center(child: Text(widget.initialValue?.name ?? "")),
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<DropdownMenuItem<Floors>>((Floors value) {
return DropdownMenuItem<Floors>(
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( : DropdownButton<Floors>(
title: Center(child: Text(widget.initialValue.name)), 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<DropdownMenuItem<Floors>>((Floors value) {
return DropdownMenuItem<Floors>(
value: value,
child: Text(
value.name ?? "",
style: Theme.of(context).textTheme.subtitle1.copyWith(
color: Theme.of(context).primaryColor,
fontSize: 11,
//fontWeight: FontWeight.bold
),
),
);
})?.toList() ??
[],
), ),
); );
} }

@ -22,7 +22,7 @@ class ServiceReportFaultDescription extends StatelessWidget {
UserProvider userProvider = Provider.of<UserProvider>(context); UserProvider userProvider = Provider.of<UserProvider>(context);
ServiceRequestFaultDescriptionProvider menuProvider = Provider.of<ServiceRequestFaultDescriptionProvider>(context); ServiceRequestFaultDescriptionProvider menuProvider = Provider.of<ServiceRequestFaultDescriptionProvider>(context);
return LoadingManager( return LoadingManager(
isLoading: (menuProvider?.isLoading ?? false) || (enabled && (menuProvider.items?.isEmpty ?? true) || (!enabled && (initialValue?.defectName?.isEmpty ?? true))), isLoading: menuProvider.isLoading,
isFailedLoading: menuProvider.items == null, isFailedLoading: menuProvider.items == null,
stateCode: menuProvider.stateCode, stateCode: menuProvider.stateCode,
onRefresh: () async { onRefresh: () async {

Loading…
Cancel
Save