|
|
|
import 'dart:convert';
|
|
|
|
|
|
|
|
import 'package:diplomaticquarterapp/models/Appointments/DoctorListResponse.dart';
|
|
|
|
import 'package:diplomaticquarterapp/models/Clinics/ClinicListResponse.dart';
|
|
|
|
import 'package:diplomaticquarterapp/pages/BookAppointment/widgets/BranchView.dart';
|
|
|
|
import 'package:diplomaticquarterapp/services/appointment_services/GetDoctorsList.dart';
|
|
|
|
import 'package:diplomaticquarterapp/services/clinic_services/get_clinic_service.dart';
|
|
|
|
import 'package:diplomaticquarterapp/services/robo_search/event_provider.dart';
|
|
|
|
import 'package:diplomaticquarterapp/services/robo_search/search_provider.dart';
|
|
|
|
import 'package:diplomaticquarterapp/uitl/app_toast.dart';
|
|
|
|
import 'package:diplomaticquarterapp/uitl/translations_delegate_base.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
import 'package:smart_progress_bar/smart_progress_bar.dart';
|
|
|
|
|
|
|
|
import '../SearchResults.dart';
|
|
|
|
import "dart:collection";
|
|
|
|
|
|
|
|
class SearchByClinic extends StatefulWidget {
|
|
|
|
@override
|
|
|
|
_SearchByClinicState createState() => _SearchByClinicState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _SearchByClinicState extends State<SearchByClinic> {
|
|
|
|
bool nearestAppo = false;
|
|
|
|
String dropdownValue;
|
|
|
|
var event = RobotProvider();
|
|
|
|
List<ListClinicCentralized> clinicsList = [];
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
WidgetsBinding.instance.addPostFrameCallback((_) => getClinicsList());
|
|
|
|
// event.controller.stream.listen((p) {
|
|
|
|
// if (p['clinic_id'] != null) {
|
|
|
|
// // setState(() {
|
|
|
|
// dropdownValue = p['clinic_id'].toString();
|
|
|
|
// //});
|
|
|
|
// getDoctorsList(context);
|
|
|
|
// }
|
|
|
|
// });
|
|
|
|
super.initState();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Container(
|
|
|
|
margin: EdgeInsets.all(10.0),
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: <Widget>[
|
|
|
|
Row(
|
|
|
|
children: <Widget>[
|
|
|
|
Checkbox(
|
|
|
|
activeColor: new Color(0xFFc5272d),
|
|
|
|
value: nearestAppo,
|
|
|
|
onChanged: (bool value) {
|
|
|
|
setState(() {
|
|
|
|
nearestAppo = value;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
),
|
|
|
|
Text(TranslationBase.of(context).nearestAppo,
|
|
|
|
style: TextStyle(fontSize: 16.0, letterSpacing: 0.9)),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
Container(
|
|
|
|
height: 60.0,
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: Colors.white,
|
|
|
|
border: Border.all(
|
|
|
|
color: Colors.grey[400],
|
|
|
|
width: 1.0,
|
|
|
|
),
|
|
|
|
borderRadius: BorderRadius.circular(10),
|
|
|
|
),
|
|
|
|
// margin: EdgeInsets.fromLTRB(10.0, 20.0, 10.0, 20.0),
|
|
|
|
padding: EdgeInsets.all(8.0),
|
|
|
|
width: MediaQuery.of(context).size.width,
|
|
|
|
child: DropdownButtonHideUnderline(
|
|
|
|
child: DropdownButton<String>(
|
|
|
|
hint: new Text("Select Clinic"),
|
|
|
|
value: dropdownValue,
|
|
|
|
items: clinicsList.map((item) {
|
|
|
|
return new DropdownMenuItem<String>(
|
|
|
|
value: item.clinicID.toString(),
|
|
|
|
child: new Text(item.clinicDescription),
|
|
|
|
);
|
|
|
|
}).toList(),
|
|
|
|
onChanged: (newValue) {
|
|
|
|
setState(() {
|
|
|
|
dropdownValue = newValue;
|
|
|
|
|
|
|
|
getDoctorsList(context);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
),
|
|
|
|
)),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
getClinicsList() {
|
|
|
|
ClinicListService service = new ClinicListService();
|
|
|
|
service.getClinicsList(context).then((res) {
|
|
|
|
if (res['MessageStatus'] == 1) {
|
|
|
|
setState(() {
|
|
|
|
res['ListClinicCentralized'].forEach((v) {
|
|
|
|
clinicsList.add(new ListClinicCentralized.fromJson(v));
|
|
|
|
});
|
|
|
|
});
|
|
|
|
} else {}
|
|
|
|
}).catchError((err) {
|
|
|
|
print(err);
|
|
|
|
}).showProgressBar(
|
|
|
|
text: "Loading", backgroundColor: Colors.blue.withOpacity(0.6));
|
|
|
|
}
|
|
|
|
|
|
|
|
getDoctorsList(BuildContext context) {
|
|
|
|
List<DoctorList> doctorsList = [];
|
|
|
|
//========================
|
|
|
|
|
|
|
|
List<String> arr = [];
|
|
|
|
var distinctIds;
|
|
|
|
List<String> result;
|
|
|
|
int numAll;
|
|
|
|
//=========================
|
|
|
|
DoctorsListService service = new DoctorsListService();
|
|
|
|
service.getDoctorsList(int.parse(dropdownValue), 0, context).then((res) {
|
|
|
|
if (res['MessageStatus'] == 1) {
|
|
|
|
setState(() {
|
|
|
|
if (res['DoctorList'].length != 0) {
|
|
|
|
doctorsList.clear();
|
|
|
|
res['DoctorList'].forEach((v) {
|
|
|
|
doctorsList.add(new DoctorList.fromJson(v));
|
|
|
|
|
|
|
|
arr.add(new DoctorList.fromJson(v).projectName);
|
|
|
|
// print(DoctorList.fromJson(v).projectName);
|
|
|
|
// print(DoctorList.fromJson(v).projectDistanceInKiloMeters);
|
|
|
|
// distinctIds = result.toSet().toList();
|
|
|
|
});
|
|
|
|
} else {}
|
|
|
|
});
|
|
|
|
|
|
|
|
result = LinkedHashSet<String>.from(arr).toList();
|
|
|
|
numAll = result.length;
|
|
|
|
// print(result);
|
|
|
|
print("numAll=" + numAll.toString());
|
|
|
|
|
|
|
|
navigateToSearchResults(context, doctorsList, result, numAll);
|
|
|
|
} else {
|
|
|
|
AppToast.showErrorToast(message: res['ErrorEndUserMessage']);
|
|
|
|
}
|
|
|
|
}).catchError((err) {
|
|
|
|
print(err);
|
|
|
|
}).showProgressBar(
|
|
|
|
text: "Loading", backgroundColor: Colors.blue.withOpacity(0.6));
|
|
|
|
}
|
|
|
|
|
|
|
|
Future navigateToSearchResults(context, docList, result, numAll) async {
|
|
|
|
Navigator.push(
|
|
|
|
context,
|
|
|
|
MaterialPageRoute(
|
|
|
|
builder: (context) =>
|
|
|
|
BranchView(doctorsList: docList, result: result, num: numAll),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
//builder: (context) => SearchResults(doctorsList: docList)));
|
|
|
|
}
|
|
|
|
}
|