select_doctor.dart 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. import 'dart:convert';
  2. import 'dart:io';
  3. import 'package:eitc_erm_app/select_patient.dart';
  4. import 'package:eitc_erm_app/utils/Component.dart';
  5. import 'package:eitc_erm_app/utils/Constants.dart';
  6. import 'package:eitc_erm_app/utils/logger.dart';
  7. import 'package:eitc_erm_app/widget/loading.dart';
  8. import 'package:flutter/material.dart';
  9. import 'package:http/http.dart' as http;
  10. import 'bean/doctor_list.dart';
  11. String mFrom = "";
  12. // void main() {
  13. // WidgetsFlutterBinding.ensureInitialized();
  14. // runApp(SelectPatient());
  15. // }
  16. class SelectDoctor extends StatefulWidget {
  17. SelectDoctor(String from) {
  18. mFrom = from;
  19. }
  20. @override
  21. State<StatefulWidget> createState() => SelectDoctorState();
  22. }
  23. class SelectDoctorState extends State<SelectDoctor> {
  24. ValueNotifier<dynamic> result = ValueNotifier(null);
  25. late Future<DoctorListEntity?> _future;
  26. late BuildContext cxt;
  27. @override
  28. void initState() {
  29. super.initState();
  30. _future = fetchData();
  31. }
  32. Future<DoctorListEntity?> fetchData() async {
  33. Map<String, String> headers = {
  34. 'token': '${Global.token}',
  35. };
  36. final response =
  37. await http.get(Uri.parse('${Global.BaseUrl}doctor/list'), headers: jsonHeaders(withToken: true));
  38. if (response.statusCode == 200) {
  39. final json = decodeBodyToJson(response.bodyBytes);
  40. logd("医生列表=$json");
  41. DoctorListEntity mDoctorListEntity =
  42. new DoctorListEntity.fromJson(json);
  43. if (mDoctorListEntity.code == Global.responseSuccessCode) {
  44. return mDoctorListEntity;
  45. } else {
  46. Component.toast(mDoctorListEntity.msg.toString(), 0);
  47. }
  48. return null;
  49. } else {
  50. Component.toast("出错了,请稍后再试!", 0);
  51. return null;
  52. }
  53. }
  54. @override
  55. Widget build(BuildContext context) {
  56. cxt = context;
  57. return Scaffold(
  58. appBar: new AppBar(
  59. title: new Text('选择医生',
  60. style: TextStyle(
  61. color: Colors.white,
  62. )),
  63. centerTitle: true,
  64. elevation: 0.5,
  65. backgroundColor: Global.StatusBarColor,
  66. leading: new IconButton(
  67. tooltip: '返回上一页',
  68. icon: const Icon(
  69. Icons.arrow_back_ios,
  70. color: Colors.white,
  71. ),
  72. onPressed: () {
  73. Navigator.of(context).pop();
  74. //_nextPage(-1);
  75. },
  76. ),
  77. ),
  78. body: Column(children: [
  79. /*Text(
  80. '选择就诊人',
  81. style: const TextStyle(fontSize: 15),
  82. textAlign: TextAlign.start,
  83. overflow: TextOverflow.ellipsis,
  84. ),*/
  85. FutureBuilder<DoctorListEntity?>(
  86. future: _future,
  87. builder: (context, snapshot) {
  88. if (snapshot.hasData) {
  89. DoctorListEntity? data = snapshot.data;
  90. return Expanded(
  91. // wrap in Expanded
  92. child: ListView.builder(
  93. shrinkWrap: true,
  94. itemCount: data?.data?.length,
  95. itemBuilder: (context, index) {
  96. return ListTile(
  97. title: Padding(
  98. padding: const EdgeInsets.fromLTRB(0, 0, 0, 10),
  99. child: Row(children: [
  100. Text(
  101. data!.data![index].nickName as String,
  102. style: const TextStyle(fontSize: 18),
  103. ),
  104. data.data![index].nickName?.length == 2
  105. ? const SizedBox(width: 28.0)
  106. : const SizedBox(width: 10.0),
  107. /* if (data!.data![index].doctorBlurb != null)
  108. ElevatedButton(
  109. child: Text(" ${data!.data![index].doctorBlurb} ",
  110. style: TextStyle(
  111. color: Colors.indigo, fontSize: 16)),
  112. style: ButtonStyle(
  113. backgroundColor:
  114. MaterialStateProperty.resolveWith<Color>(
  115. (states) {
  116. return Colors
  117. .lightBlueAccent; // Regular color
  118. }),
  119. // fixedSize: MaterialStateProperty.all<Size>(
  120. // Size(70, 15),
  121. // ),
  122. padding:
  123. MaterialStateProperty.all(EdgeInsets.zero),
  124. minimumSize:
  125. MaterialStateProperty.all(Size.zero),
  126. ),
  127. onPressed: () {},
  128. ),*/
  129. ]),
  130. ),
  131. subtitle: Column(
  132. crossAxisAlignment: CrossAxisAlignment.start,
  133. children: <Widget>[
  134. Text(
  135. '${data.data![index].deptName??""} - ${data.data![index].postNames ?? ""}'),
  136. const Divider(),
  137. ]),
  138. onTap: () {
  139. Global.doctor = data;
  140. Global.selectDoctor = index;
  141. /*if (mFrom == "fromDoctorDetail") {
  142. Navigator.of(cxt).pop();
  143. } else if (mFrom == "fromRecordRegistration") {
  144. Navigator.pop(cxt, "success");
  145. } else */
  146. {
  147. // if(Global.selectPatient == -1)
  148. Navigator.push(
  149. context,
  150. MaterialPageRoute(
  151. builder: (context) =>
  152. SelectPatient("fromSelectDoctor")),
  153. );
  154. /*else
  155. Navigator.push(
  156. context,
  157. MaterialPageRoute(
  158. builder: (context) => ChatHome()),
  159. );*/
  160. }
  161. },
  162. );
  163. },
  164. ));
  165. } else if (snapshot.hasError) {
  166. return Text('Error: ${snapshot.error}');
  167. }
  168. return const Expanded(child: ColorLoader());
  169. },
  170. ),
  171. ]),
  172. );
  173. }
  174. }