import 'package:diplomaticquarterapp/models/Appointments/DoctorListResponse.dart'; import 'package:diplomaticquarterapp/services/appointment_services/GetDoctorsList.dart'; import 'package:diplomaticquarterapp/uitl/app_toast.dart'; import 'package:diplomaticquarterapp/uitl/gif_loader_dialog_utils.dart'; import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart'; import 'package:diplomaticquarterapp/widgets/transitions/fade_page.dart'; import 'package:flutter/material.dart'; import '../SearchResults.dart'; class SearchByDoctor extends StatefulWidget { @override _SearchByDoctorState createState() => _SearchByDoctorState(); } class _SearchByDoctorState extends State { TextEditingController doctorNameController = new TextEditingController(); bool _isButtonDisabled; @override void initState() { super.initState(); _isButtonDisabled = true; } @override Widget build(BuildContext context) { return Container( margin: EdgeInsets.all(20.0), child: Column( crossAxisAlignment: CrossAxisAlignment.start, mainAxisSize: MainAxisSize.max, children: [ Container( margin: EdgeInsets.only(top: 10.0, bottom: 15.0), child: Text(TranslationBase.of(context).searchByDocText, style: TextStyle(fontSize: 16.0, letterSpacing: 0.9)), ), Container( decoration: BoxDecoration(color: Colors.white), child: TextField( controller: doctorNameController, onChanged: (content) { _onDocTextChanged(content); }, decoration: InputDecoration( labelText: TranslationBase.of(context).enterDocName, fillColor: Colors.white, prefixIcon: Icon(Icons.search), border: OutlineInputBorder())), ), Expanded( child: Align( alignment: FractionalOffset.bottomCenter, child: _buildCounterButton(), ), ), ], ), ); } Widget _buildCounterButton() { return new ButtonTheme( shape: RoundedRectangleBorder( borderRadius: BorderRadius.circular(10.0), ), minWidth: MediaQuery.of(context).size.width, height: 45.0, child: RaisedButton( color: new Color(0xFF60686b), textColor: Colors.white, disabledTextColor: Colors.white, disabledColor: new Color(0xFFbcc2c4), onPressed: () { if (_isButtonDisabled == false) { _searchDoctor(context); } }, child: Text(TranslationBase.of(context).search, style: TextStyle(fontSize: 18.0)), ), ); } getDoctorsList(BuildContext context) { GifLoaderDialogUtils.showMyDialog(context); List doctorsList = []; DoctorsListService service = new DoctorsListService(); List _patientDoctorAppointmentListHospital = List(); service .getDoctorsListByName(doctorNameController.text, context) .then((res) { GifLoaderDialogUtils.hideDialog(context); if (res['MessageStatus'] == 1) { setState(() { if (res['DoctorList'].length != 0) { res['DoctorList'].forEach((v) { doctorsList.add(new DoctorList.fromJson(v)); }); doctorsList.forEach((element) { List doctorByHospital = _patientDoctorAppointmentListHospital .where( (elementClinic) => elementClinic.filterName == element.projectName, ) .toList(); if (doctorByHospital.length != 0) { _patientDoctorAppointmentListHospital[ _patientDoctorAppointmentListHospital .indexOf(doctorByHospital[0])] .patientDoctorAppointmentList .add(element); } else { _patientDoctorAppointmentListHospital.add( PatientDoctorAppointmentList( filterName: element.projectName, distanceInKMs: element.projectDistanceInKiloMeters.toString(), patientDoctorAppointment: element)); } }); } else { GifLoaderDialogUtils.hideDialog(context); AppToast.showErrorToast(message: res['ErrorSearchMsg']); } }); GifLoaderDialogUtils.hideDialog(context); navigateToSearchResults( context, doctorsList, _patientDoctorAppointmentListHospital); } else { GifLoaderDialogUtils.hideDialog(context); AppToast.showErrorToast(message: res['ErrorEndUserMessage']); } }).catchError((err) { GifLoaderDialogUtils.hideDialog(context); AppToast.showErrorToast(message: err); print(err); }); } _onDocTextChanged(content) { print(content); if (content.length >= 3) { setState(() { _isButtonDisabled = false; }); } else { setState(() { _isButtonDisabled = true; }); } print(_isButtonDisabled); } _searchDoctor(BuildContext context) { getDoctorsList(context); } Future navigateToSearchResults( context, List docList, List patientDoctorAppointmentListHospital) async { Navigator.push( context, FadePage( page: SearchResults( isLiveCareAppointment: false, doctorsList: docList, patientDoctorAppointmentListHospital: patientDoctorAppointmentListHospital))); } }