import 'package:diplomaticquarterapp/config/shared_pref_kay.dart'; import 'package:diplomaticquarterapp/core/enum/viewstate.dart'; import 'package:diplomaticquarterapp/core/model/AlHabibMedicalService/EReferral/get_ereferral_response_model.dart'; import 'package:diplomaticquarterapp/core/model/AlHabibMedicalService/EReferral/search_criteria_model.dart'; import 'package:diplomaticquarterapp/core/model/AlHabibMedicalService/EReferral/search_e_referral_request_model.dart'; import 'package:diplomaticquarterapp/core/service/AlHabibMedicalService/e_referral_service.dart'; import 'package:diplomaticquarterapp/core/viewModels/all_habib_medical_services/e_referral_view_model.dart'; import 'package:diplomaticquarterapp/models/Authentication/authenticated_user.dart'; import 'package:diplomaticquarterapp/pages/AlHabibMedicalService/E-Referral/referral_details.dart'; import 'package:diplomaticquarterapp/pages/base/base_view.dart'; import 'package:diplomaticquarterapp/pages/medical/balance/new_text_Field.dart'; import 'package:diplomaticquarterapp/uitl/app_shared_preferences.dart'; import 'package:diplomaticquarterapp/uitl/date_uitl.dart'; import 'package:diplomaticquarterapp/uitl/gif_loader_dialog_utils.dart'; import 'package:diplomaticquarterapp/widgets/buttons/secondary_button.dart'; import 'package:diplomaticquarterapp/widgets/data_display/text.dart'; import 'package:diplomaticquarterapp/widgets/others/app_scaffold_widget.dart'; import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import '../../../locator.dart'; import 'New_E_Referral/new_e_referral_step_one_page.dart'; import 'dialogs/select_country_ingo_Dialog.dart'; import 'dialogs/select_search_criteria_dialog.dart'; class SearchForReferralsPage extends StatefulWidget { SearchForReferralsPage({Key key}); @override _SearchForReferralsPageState createState() => _SearchForReferralsPageState(); } class _SearchForReferralsPageState extends State { TextEditingController _searchTextController = TextEditingController(); TextEditingController _mobileTextController = TextEditingController(); bool _isSubmitted = false; AuthenticatedUser authUser; List allReferrals = List(); dynamic _selectedCountry = { "name": "Saudi Arabia", "name_ar": "المملكة العربية السعودية", "code": "+966", "countryCode": "SA", "pattern": "5xxxxxxxx", "maxLength": 9 }; SearchCriteriaModel selectedCriteria = SearchCriteriaModel( name: "Identification Number", nameAr: "رقم المحول", value: 1); @override void initState() { authUser = new AuthenticatedUser(); WidgetsBinding.instance.addPostFrameCallback((_) => getPatientData()); super.initState(); } @override Widget build(BuildContext context) { return BaseView( onModelReady: (model) => model.getAllCities(), builder: (_, model, widget) => AppScaffold( isShowAppBar: false, body: SingleChildScrollView( physics: ScrollPhysics(), child: Container( margin: EdgeInsets.all(12), child: Center( child: FractionallySizedBox( widthFactor: 0.94, child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ SizedBox( height: 77, ), InkWell( onTap: () => selectSearchCriteriaDialog(), child: Container( padding: EdgeInsets.all(12), width: double.infinity, height: 65, decoration: BoxDecoration( borderRadius: BorderRadius.circular(12), color: Colors.white), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Texts(getSearchCriteriaName()), Icon(Icons.arrow_drop_down) ], ), ), ), SizedBox( height: 12, ), NewTextFields( hintText: selectedCriteria.value == 1 ? "Enter Patient Identification No" : "Enter Referral Number", controller: _searchTextController, ), SizedBox( height: 12, ), InkWell( onTap: () => confirmSelectCountryTypeDialog(), child: Container( padding: EdgeInsets.all(12), width: double.infinity, height: 65, decoration: BoxDecoration( borderRadius: BorderRadius.circular(12), color: Colors.white), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Texts(getCountryName()), Icon(Icons.arrow_drop_down) ], ), ), ), SizedBox( height: 12, ), MobileNumberTextFiled( controller: _mobileTextController, code: _selectedCountry == null ? "11" : _selectedCountry["code"], ), allReferrals.length != 0 ? Container( transform: Matrix4.translationValues(0.0, -40.0, 0.0), child: ListView.builder( shrinkWrap: true, scrollDirection: Axis.vertical, physics: ScrollPhysics(), itemCount: allReferrals.length, itemBuilder: (BuildContext context, int index) { return Container( child: InkWell( onTap: () { navigateToReferralDetails( allReferrals[index]); }, child: Card( margin: EdgeInsets.only(bottom: 10.0), color: Colors.white, shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(10), ), child: Container( margin: EdgeInsets.only( left: 10.0, right: 10.0), padding: EdgeInsets.all(5.0), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ Container( margin: EdgeInsets.all(5.0), child: Text( allReferrals[index] .status, style: TextStyle( fontSize: 16.0))), Container( margin: EdgeInsets.all(5.0), child: Text( allReferrals[index] .patientName, style: TextStyle( fontSize: 16.0, color: Colors .grey[600]))), Container( margin: EdgeInsets.all(5.0), child: Text( allReferrals[index] .preferredBranchName, style: TextStyle( fontSize: 16.0, color: Colors .grey[600]))), Container( margin: EdgeInsets.all(5.0), child: Text( DateUtil.getMonthDayYearDateFormatted( DateUtil.convertStringToDateNoTimeZone( allReferrals[ index] .referralDate)), style: TextStyle( fontSize: 16.0, color: Colors .grey[600]))), ], ), Container( child: Icon(Icons.arrow_forward, size: 20.0, color: Colors.grey[700]), ), ], ), ), ), )); }, ), ) : Container(), SizedBox( height: 70.0, ) ], ), ), ), ), ), bottomSheet: Container( height: MediaQuery.of(context).size.height * 0.1, width: double.infinity, padding: EdgeInsets.all(9), child: SecondaryButton( textColor: Colors.white, label: "Search", onTap: () async { GifLoaderDialogUtils.showMyDialog(context); SearchEReferralRequestModel searchEReferralRequestModel = new SearchEReferralRequestModel( patientMobileNumber: _selectedCountry['code'] .toString() .replaceFirst("+", "") + _mobileTextController.text, ); if (selectedCriteria.value == 1) { searchEReferralRequestModel.identificationNo = _searchTextController.text; searchEReferralRequestModel.referralNumber = 0; } else { searchEReferralRequestModel.referralNumber = int.parse(_searchTextController.text); searchEReferralRequestModel.identificationNo = ''; } await model .getEReferrals(searchEReferralRequestModel) .then((response) { GifLoaderDialogUtils.hideDialog(context); print(response['List_EReferrals']); allReferrals.clear(); setState(() { response['List_EReferrals'].forEach((data) { allReferrals .add(GetEReferralResponseModel.fromJson(data)); _isSubmitted = true; }); }); }); }, loading: model.state == ViewState.BusyLocal, disabled: _searchTextController.text.isEmpty || _mobileTextController.text.isEmpty, ), ))); } void getEreferralsIsLogin() { EReferralService _eReferralService = locator(); String mobileNumber; String zipCode; if (authUser.mobileNumber.length > 9) { mobileNumber = authUser.mobileNumber.substring(1, authUser.mobileNumber.length); } else { mobileNumber = authUser.mobileNumber; } if (authUser.outSA == 0) { zipCode = "966"; } else { zipCode = "971"; } _eReferralService .getEReferralsIfLogin(zipCode + mobileNumber) .then((response) { allReferrals.clear(); setState(() { response['List_EReferrals'].forEach((data) { allReferrals.add(GetEReferralResponseModel.fromJson(data)); }); }); }).catchError(() {}); } getPatientData() async { AppSharedPreferences sharedPref = AppSharedPreferences(); if (await sharedPref.getObject(USER_PROFILE) != null) { var data = AuthenticatedUser.fromJson(await sharedPref.getObject(USER_PROFILE)); setState(() { authUser = data; getEreferralsIsLogin(); }); } } void confirmSelectCountryTypeDialog() { showDialog( context: context, child: SelectCountryDialog( selectedCountry: _selectedCountry, onValueSelected: (value) { setState(() { _selectedCountry = value; }); }, ), ); } navigateToReferralDetails( GetEReferralResponseModel getEReferralResponseModel) { Navigator.push( context, FadePage( page: ReferralDetails( getEReferralResponseModel: getEReferralResponseModel))); } String getCountryName() { if (_selectedCountry != null) return _selectedCountry["name"]; else return "Country"; } void selectSearchCriteriaDialog() { showDialog( context: context, child: SelectSearchCriteriaDialog( selectedCriteria: selectedCriteria, onValueSelected: (value) { setState(() { selectedCriteria = value; }); }, ), ); } String getSearchCriteriaName() { return selectedCriteria.name; } }