my_doctor.dart 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304
  1. import 'dart:convert';
  2. import 'dart:io';
  3. import 'dart:typed_data';
  4. import 'package:eitc_erm_app/utils/Component.dart';
  5. import 'package:eitc_erm_app/utils/Constants.dart';
  6. import 'package:eitc_erm_app/widget/loading.dart';
  7. import 'package:flutter/material.dart';
  8. import 'package:fluttertoast/fluttertoast.dart';
  9. import 'package:http/http.dart' as http;
  10. import 'bean/favourite_doctor_list.dart';
  11. import 'bean/message_box_s_list_entity.dart';
  12. import 'bean/normal_response.dart';
  13. import 'bean/pda_patrol_time_list.dart';
  14. import 'doctor_detail.dart';
  15. void main() {
  16. WidgetsFlutterBinding.ensureInitialized();
  17. runApp(MyDoctor());
  18. }
  19. class MyDoctor extends StatefulWidget {
  20. @override
  21. State<StatefulWidget> createState() => MyDoctorState();
  22. }
  23. class MyDoctorState extends State<MyDoctor> {
  24. ValueNotifier<dynamic> result = ValueNotifier(null);
  25. late Future<FavouriteDoctorListEntity?> _future;
  26. @override
  27. void initState() {
  28. super.initState();
  29. _future = fetchData();
  30. }
  31. Future<FavouriteDoctorListEntity?> fetchData() async {
  32. Map<String, String> headers = {
  33. 'token': '${Global.token}',
  34. };
  35. final response = await http.get(
  36. Uri.parse(Global.BaseUrl + 'collection-doctor/list'),
  37. headers: headers);
  38. print(response.body.toString());
  39. if (response.statusCode == 200) {
  40. final jsonString = utf8.decode(response.bodyBytes);
  41. final jsonResponse = jsonDecode(jsonString);
  42. print(jsonString);
  43. FavouriteDoctorListEntity mFavouriteDoctorListEntity =
  44. new FavouriteDoctorListEntity.fromJson(jsonResponse);
  45. if (mFavouriteDoctorListEntity.code == Global.responseSuccessCode) {
  46. return mFavouriteDoctorListEntity;
  47. } else {
  48. Component.toast(mFavouriteDoctorListEntity.msg.toString(), 0);
  49. }
  50. return null;
  51. } else {
  52. Component.toast("出错了,请稍后再试!", 0);
  53. return null;
  54. }
  55. }
  56. @override
  57. Widget build(BuildContext context) {
  58. return MaterialApp(
  59. home: Scaffold(
  60. appBar: new AppBar(
  61. title: new Text('收藏的医生',
  62. style: TextStyle(
  63. color: Colors.white,
  64. )),
  65. centerTitle: true,
  66. elevation: 0.5,
  67. backgroundColor: Global.StatusBarColor,
  68. leading: new IconButton(
  69. tooltip: '返回上一页',
  70. icon: const Icon(
  71. Icons.arrow_back_ios,
  72. color: Colors.white,
  73. ),
  74. onPressed: () {
  75. Navigator.of(context).pop();
  76. //_nextPage(-1);
  77. },
  78. ),
  79. ),
  80. body: Center(
  81. child: FutureBuilder<FavouriteDoctorListEntity?>(
  82. future: _future,
  83. builder: (context, snapshot) {
  84. if (snapshot.hasData) {
  85. FavouriteDoctorListEntity? data = snapshot.data;
  86. return ListView.builder(
  87. itemCount: data?.data?.length,
  88. itemBuilder: (context, index) {
  89. return
  90. Container(
  91. margin: const EdgeInsets.all(8),
  92. width: double.infinity,
  93. decoration: BoxDecoration(
  94. color: Colors.white,
  95. borderRadius: BorderRadius.circular(3.0),
  96. boxShadow: [
  97. BoxShadow(
  98. color: Colors.black54,
  99. offset: Offset(5.0, 5.0),
  100. blurRadius: 5.0,
  101. ),
  102. ],
  103. ),
  104. child: ListTile(
  105. title: Row(mainAxisSize: MainAxisSize.max, children: [
  106. Padding(
  107. padding: const EdgeInsets.all(10),
  108. child: Image.network(
  109. // 图片地址
  110. "${Global.ImageUrl}${data!.data![index].avatar}",
  111. width: 60,
  112. fit: BoxFit.cover,
  113. excludeFromSemantics: true,
  114. errorBuilder: (context, error, stackTrace) => Icon(
  115. Icons.person_pin,
  116. size: 60,
  117. color: Colors.grey,
  118. ),
  119. ),
  120. ),
  121. Expanded(
  122. flex: 4,
  123. child:
  124. Column(
  125. mainAxisAlignment: MainAxisAlignment.start,
  126. mainAxisSize: MainAxisSize.max,
  127. children: [
  128. SizedBox(
  129. height: 20,
  130. ),
  131. Row(
  132. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  133. children: [
  134. Row(
  135. mainAxisAlignment:
  136. MainAxisAlignment.spaceBetween,
  137. textBaseline: TextBaseline.alphabetic,
  138. children: [
  139. Text(
  140. data!.data![index].doctorName
  141. .toString(),
  142. style:
  143. const TextStyle(fontSize: 18),
  144. ),
  145. SizedBox(
  146. width: 5,
  147. ),
  148. Text(
  149. data!.data![index].postName
  150. .toString(),
  151. style: const TextStyle(
  152. fontSize: 15,
  153. color: Colors.grey),
  154. ),
  155. ]),
  156. SizedBox(width: 75),
  157. GestureDetector(
  158. child: Icon(
  159. Icons.favorite,
  160. color: Colors.red,
  161. ),
  162. onTap: () {
  163. cancelCollectDoctor(data, mWhich);
  164. }),
  165. ]),
  166. Row(children: [
  167. ElevatedButton(
  168. style: ButtonStyle(
  169. padding: MaterialStateProperty.all(
  170. EdgeInsets.all(3)),
  171. minimumSize:
  172. MaterialStateProperty.all(Size.zero),
  173. backgroundColor:
  174. MaterialStateProperty.all(Colors.blue),
  175. ),
  176. child: Text(
  177. '传统整形',
  178. style: const TextStyle(
  179. fontSize: 8, color: Colors.white),
  180. ),
  181. onPressed: () {},
  182. ),
  183. ElevatedButton(
  184. style: ButtonStyle(
  185. padding: MaterialStateProperty.all(
  186. EdgeInsets.all(3)),
  187. minimumSize:
  188. MaterialStateProperty.all(Size.zero),
  189. backgroundColor:
  190. MaterialStateProperty.all(Colors.blue),
  191. ),
  192. child: Text(
  193. '隐形校正',
  194. style: const TextStyle(
  195. fontSize: 8, color: Colors.white),
  196. ),
  197. onPressed: () {},
  198. ),
  199. ElevatedButton(
  200. style: ButtonStyle(
  201. backgroundColor:
  202. MaterialStateProperty.all(Colors.blue),
  203. padding: MaterialStateProperty.all(
  204. EdgeInsets.all(3)),
  205. minimumSize:
  206. MaterialStateProperty.all(Size.zero),
  207. ),
  208. child: Text(
  209. '反颌(地包天)',
  210. style: const TextStyle(
  211. fontSize: 8, color: Colors.white),
  212. ),
  213. onPressed: () {},
  214. ),
  215. ]),
  216. ]),),
  217. ]),
  218. subtitle: Padding(
  219. padding: EdgeInsets.fromLTRB(20, 0, 20, 0),
  220. child:
  221. Text(
  222. data!.data![index].briefIntroduction == null ? "简介:暂无。" : data!.data![index].briefIntroduction
  223. .toString(),
  224. style: const TextStyle(
  225. fontSize: 10, color: Colors.grey),
  226. ),
  227. ),
  228. onTap: () {
  229. /*Navigator.push(
  230. context,
  231. MaterialPageRoute(builder: (context) => DoctorDetail()),
  232. );*/
  233. },
  234. ),
  235. );
  236. },
  237. );
  238. } else if (snapshot.hasError) {
  239. return Text('Error: ${snapshot.error}');
  240. }
  241. return ColorLoader();
  242. },
  243. ),
  244. ),
  245. ),
  246. );
  247. }
  248. Future<void> cancelCollectDoctor(
  249. FavouriteDoctorListEntity mFavouriteDoctorListEntity, int mWhich) async {
  250. var params = {
  251. "avatar": mFavouriteDoctorListEntity.data?[mWhich].avatar,
  252. "briefIntroduction":
  253. mFavouriteDoctorListEntity.data?[mWhich].briefIntroduction,
  254. "doctorId": mFavouriteDoctorListEntity.data?[mWhich].doctorId,
  255. "doctorName": mFavouriteDoctorListEntity.data?[mWhich].doctorName,
  256. "label": mFavouriteDoctorListEntity.data?[mWhich].label,
  257. "postName": mFavouriteDoctorListEntity.data?[mWhich].postName
  258. };
  259. Map<String, String> headers = {
  260. HttpHeaders.contentTypeHeader: "application/json; charset=utf-8",
  261. 'token': '${Global.token}',
  262. };
  263. var response = await http.post(
  264. Uri.parse(Global.BaseUrl +
  265. 'collection-doctor/cancel-collect-doctor?doctorId=' +
  266. mFavouriteDoctorListEntity.data![mWhich].doctorId.toString()),
  267. body: jsonEncode(params),
  268. headers: headers);
  269. print(response.body.toString());
  270. if (response.statusCode == 200) {
  271. final jsonString = utf8.decode(response.bodyBytes);
  272. final jsonResponse = jsonDecode(jsonString);
  273. print(jsonString);
  274. NormalResponse mNormalResponse =
  275. new NormalResponse.fromJson(jsonResponse);
  276. if (mNormalResponse.code == Global.responseSuccessCode) {
  277. Component.toast("取消成功!", 2);
  278. Navigator.of(context).pop();
  279. Navigator.push(
  280. context,
  281. MaterialPageRoute(builder: (context) => MyDoctor()),
  282. );
  283. } else {
  284. Component.toast(mNormalResponse.msg.toString(), 0);
  285. }
  286. } else {
  287. Component.toast("出错了,请稍后再试!", 0);
  288. return null;
  289. }
  290. }
  291. }