doctor_talk_list.dart 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. import 'dart:convert';
  2. import 'dart:io';
  3. import 'package:eitc_erm_app/select_department.dart';
  4. import 'package:eitc_erm_app/select_doctor.dart';
  5. import 'package:eitc_erm_app/utils/Component.dart';
  6. import 'package:eitc_erm_app/utils/Constants.dart';
  7. import 'package:eitc_erm_app/utils/DateUtils.dart';
  8. import 'package:eitc_erm_app/widget/loading.dart';
  9. import 'package:flutter/material.dart';
  10. import 'package:fluttertoast/fluttertoast.dart';
  11. import 'bean/chat_list.dart';
  12. import 'bean/doctor_chat_list.dart';
  13. import 'bean/pda_patrol_time_list.dart';
  14. import 'package:http/http.dart' as http;
  15. import 'bean/user_list.dart';
  16. import 'chat/chat_home.dart';
  17. import 'chat/chat_home_doctor.dart';
  18. import 'confirm_registration.dart';
  19. /*void main() => runApp(DoctorTalkList());*/
  20. class DoctorTalkList extends StatelessWidget {
  21. DateTime now = DateTime.now();
  22. ValueNotifier<dynamic> result = ValueNotifier(null);
  23. late Future<DoctorChatList?> _future = fetchData();
  24. Future<DoctorChatList?> fetchData() async {
  25. String url = '${Global.BaseUrl}chat/getChatPatientList?dockerId=${Global.user.data?.id}';
  26. final response = await http.get(
  27. Uri.parse(url),
  28. headers: {
  29. HttpHeaders.contentTypeHeader: "application/json; charset=utf-8",
  30. 'token': '${Global.token}',
  31. });
  32. print(url);
  33. print(Global.token);
  34. if (response.statusCode == 200) {
  35. final jsonString = utf8.decode(response.bodyBytes);
  36. final jsonResponse = jsonDecode(jsonString);
  37. print(jsonResponse);
  38. DoctorChatList mDoctorChatList = new DoctorChatList.fromJson(jsonResponse);
  39. if (mDoctorChatList.code == Global.responseSuccessCode) {
  40. } else {
  41. Component.toast(mDoctorChatList.msg.toString(), 0);
  42. }
  43. return mDoctorChatList;
  44. } else {
  45. Component.toast("出错了,请稍后再试!", 0);
  46. }
  47. }
  48. @override
  49. Widget build(BuildContext context) {
  50. return MaterialApp(
  51. home: Scaffold(
  52. appBar: new AppBar(
  53. title: new Text('患者沟通列表',
  54. style: TextStyle(
  55. color: Colors.white,
  56. )),
  57. centerTitle: true,
  58. elevation: 0.5,
  59. backgroundColor: Global.StatusBarColor,
  60. ),
  61. body: Column(children: [
  62. Expanded(
  63. child: FutureBuilder<DoctorChatList?>(
  64. future: _future,
  65. builder: (context, snapshot) {
  66. if (snapshot.hasData) {
  67. DoctorChatList? data = snapshot.data;
  68. return ListView.builder(
  69. shrinkWrap: true,
  70. itemCount: data?.data?.length,
  71. itemBuilder: (context, index) {
  72. return ListTile(
  73. shape: RoundedRectangleBorder(
  74. borderRadius: BorderRadius.only(
  75. topLeft: Radius.circular(5),
  76. topRight: Radius.circular(5),
  77. bottomRight: Radius.circular(5),
  78. bottomLeft: Radius.circular(5))),
  79. tileColor: Colors.white,
  80. iconColor: Colors.white,
  81. leading: Container(
  82. height: 55,
  83. child: Image.network(
  84. "${Global.ImageUrl}${data!.data?[index].avatar}",
  85. width: 55,
  86. fit: BoxFit.cover,
  87. excludeFromSemantics: true,
  88. errorBuilder: (context, error, stackTrace) => Icon(
  89. Icons.person_pin,
  90. size: 55,
  91. color: Colors.grey,
  92. ),
  93. ),
  94. ),
  95. title: Row(
  96. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  97. children: [
  98. Text(
  99. '与 ${data!.data?[index].phoneNumber} 的聊天记录',
  100. textAlign: TextAlign.center,
  101. style: const TextStyle(
  102. fontSize: 15, color: Colors.black),
  103. ),
  104. /*Text(
  105. '${data!.data?[index].updateDate}',
  106. textAlign: TextAlign.center,
  107. style: const TextStyle(
  108. fontSize: 13, color: Colors.grey),
  109. ),*/
  110. ]),
  111. subtitle: Text(
  112. '${data!.data?[index].updateDate}',
  113. style: const TextStyle(
  114. fontSize: 13, color: Colors.grey),
  115. ),
  116. onTap: () {
  117. Navigator.push(
  118. context,
  119. MaterialPageRoute(builder: (context) => ChatHomeDoctor(data!.data![index].id.toString(), data!.data![index].phoneNumber.toString())),
  120. );
  121. },
  122. );
  123. },
  124. );
  125. } else if (snapshot.hasError) {
  126. return Text('Error: ${snapshot.error}');
  127. }
  128. return ColorLoader();
  129. },
  130. ),
  131. ),
  132. ]),
  133. ),
  134. );
  135. }
  136. }