my_doctor.dart 12 KB

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