From 64d9305b846ba65bc157121a4bcd05bc839de547 Mon Sep 17 00:00:00 2001 From: zaid_daoud Date: Tue, 1 Aug 2023 16:19:31 +0300 Subject: [PATCH] Site Field locked and the data retrieved from user info --- .../user/gas_refill/request_gas_refill.dart | 15 +++-- .../hospital_auto_complete_field_new.dart | 64 +++++++++++-------- 2 files changed, 46 insertions(+), 33 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 cb186466..38f97f40 100644 --- a/lib/views/pages/user/gas_refill/request_gas_refill.dart +++ b/lib/views/pages/user/gas_refill/request_gas_refill.dart @@ -151,13 +151,13 @@ class _RequestGasRefillState extends State { _gasRefillProvider = Provider.of(context, listen: false); _gasRefillProvider.reset(); } - if (widget.gasRefillModel != null && _firstTime) { - _formModel = widget.gasRefillModel; - _formModel.status = const Lookup(value: 0); - HospitalsProvider().getHospitalsListByVal(searchVal: widget.gasRefillModel.clientName).then((value) { - _gasRefillProvider.hospital = value?.firstWhere((element) => element.name == widget.gasRefillModel.clientName, orElse: () => null); - print(_gasRefillProvider.hospital?.buildings?.length); - print(widget.gasRefillModel?.building?.name); + if (_firstTime) { + if (widget.gasRefillModel != null) { + _formModel = widget.gasRefillModel; + _formModel.status = const Lookup(value: 0); + } + 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); @@ -232,6 +232,7 @@ class _RequestGasRefillState extends State { height: 4, ), HospitalAutoCompleteField( + enabled: false, initialValue: _gasRefillProvider.hospital?.name, // onSave: (value){ // _search.hospital = value; diff --git a/lib/views/widgets/hospitals/hospital_auto_complete_field_new.dart b/lib/views/widgets/hospitals/hospital_auto_complete_field_new.dart index 1bc29fd6..6ca612a4 100644 --- a/lib/views/widgets/hospitals/hospital_auto_complete_field_new.dart +++ b/lib/views/widgets/hospitals/hospital_auto_complete_field_new.dart @@ -8,10 +8,12 @@ import 'package:test_sa/models/hospital.dart'; import 'package:test_sa/models/subtitle.dart'; import 'package:test_sa/views/app_style/colors.dart'; import 'package:test_sa/views/app_style/sizing.dart'; +import 'package:test_sa/views/widgets/loaders/app_loading.dart'; class HospitalAutoCompleteField extends StatefulWidget { final String initialValue; final Function(Hospital) onSearch; + final bool enabled; //final Function(Hospital) onSave; @@ -19,6 +21,7 @@ class HospitalAutoCompleteField extends StatefulWidget { Key key, this.onSearch, this.initialValue, + this.enabled = true, }) : super(key: key); @override @@ -66,32 +69,41 @@ class _HospitalAutoCompleteFieldState extends State { // AppStyle.boxShadow // ] ), - child: TypeAheadField( - textFieldConfiguration: TextFieldConfiguration( - style: Theme.of(context).textTheme.headline6, - controller: _controller, - textAlign: TextAlign.center, - decoration: InputDecoration( - hintText: _subtitle.hospital, - border: InputBorder.none, - disabledBorder: InputBorder.none, - focusedBorder: InputBorder.none, - enabledBorder: InputBorder.none, - ), - textInputAction: TextInputAction.search, - ), - suggestionsCallback: (vale) async { - return await HospitalsProvider().getHospitalsListByVal(searchVal: _controller.text); - }, - itemBuilder: (context, hospital) { - return ListTile( - title: Text(hospital.name), - ); - }, - onSuggestionSelected: (hospital) { - widget.onSearch(hospital); - }, - ), + child: widget.enabled + ? TypeAheadField( + textFieldConfiguration: TextFieldConfiguration( + style: Theme.of(context).textTheme.headline6, + controller: _controller, + textAlign: TextAlign.center, + decoration: InputDecoration( + hintText: _subtitle.hospital, + border: InputBorder.none, + disabledBorder: InputBorder.none, + focusedBorder: InputBorder.none, + enabledBorder: InputBorder.none, + ), + textInputAction: TextInputAction.search, + ), + suggestionsCallback: (vale) async { + return await HospitalsProvider().getHospitalsListByVal(searchVal: _controller.text); + }, + itemBuilder: (context, hospital) { + return ListTile( + title: Text(hospital.name), + ); + }, + onSuggestionSelected: (hospital) { + widget.onSearch(hospital); + }, + ) + : widget.initialValue == null + ? const Padding( + padding: EdgeInsets.all(8.0), + child: ALoading(), + ) + : ListTile( + title: Center(child: Text(widget.initialValue)), + ), ); } }