patient_talk_list.dart 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. import 'package:eitc_erm_app/utils/Component.dart';
  2. import 'package:eitc_erm_app/utils/Constants.dart';
  3. import 'package:eitc_erm_app/utils/logger.dart';
  4. import 'package:eitc_erm_app/widget/loading.dart';
  5. import 'package:eitc_erm_app/widget/user_header.dart';
  6. import 'package:flutter/material.dart';
  7. import 'package:http/http.dart' as http;
  8. import 'bean/chat_list.dart';
  9. import 'chat/chat_home.dart';
  10. /*void main() => runApp(DoctorTalkList());*/
  11. class PatientTalkList extends StatelessWidget {
  12. DateTime now = DateTime.now();
  13. ValueNotifier<dynamic> result = ValueNotifier(null);
  14. late final Future<ChatList?> _future = fetchData();
  15. Future<ChatList?> fetchData() async {
  16. String url = '${Global.BaseUrl}chat/getChatList?userId=${Global.userId}';
  17. final response =
  18. await http.get(Uri.parse(url), headers: jsonHeaders(withToken: true));
  19. logd(url);
  20. logd(Global.token);
  21. if (response.statusCode == 200) {
  22. final json = decodeBodyToJson(response.bodyBytes);
  23. logd("患者聊天列表=$json");
  24. ChatList mChatList = ChatList.fromJson(json);
  25. if (mChatList.code == Global.responseSuccessCode) {
  26. } else {
  27. Component.toast(mChatList.msg.toString(), 0);
  28. }
  29. return mChatList;
  30. } else {
  31. Component.toast("出错了,请稍后再试!", 0);
  32. }
  33. }
  34. @override
  35. Widget build(BuildContext context) {
  36. return Scaffold(
  37. appBar: AppBar(
  38. title: const Text('医生沟通列表',
  39. style: TextStyle(
  40. color: Colors.white,
  41. )),
  42. centerTitle: true,
  43. elevation: 0.5,
  44. backgroundColor: Global.StatusBarColor,
  45. leading: IconButton(
  46. tooltip: '返回上一页',
  47. icon: const Icon(
  48. Icons.arrow_back_ios,
  49. color: Colors.white,
  50. ),
  51. onPressed: () {
  52. Navigator.of(context).pop();
  53. //_nextPage(-1);
  54. },
  55. ),
  56. ),
  57. body: Column(children: [
  58. Expanded(
  59. child: FutureBuilder<ChatList?>(
  60. future: _future,
  61. builder: (context, snapshot) {
  62. if (snapshot.hasData) {
  63. ChatList? data = snapshot.data;
  64. return ListView.builder(
  65. shrinkWrap: true,
  66. itemCount: data?.data?.length,
  67. itemBuilder: (context, index) {
  68. return ListTile(
  69. shape: const RoundedRectangleBorder(
  70. borderRadius: BorderRadius.only(
  71. topLeft: Radius.circular(5),
  72. topRight: Radius.circular(5),
  73. bottomRight: Radius.circular(5),
  74. bottomLeft: Radius.circular(5))),
  75. tileColor: Colors.white,
  76. iconColor: Colors.white,
  77. leading: UserHeader(
  78. url: "${Global.ImageUrl}${data!.data?[index].avatar}",
  79. ),
  80. title: Row(children: [
  81. Expanded(
  82. child: Text(
  83. '${data.data?[index].nickName} ${data.data?[index].remark ?? ""}',
  84. overflow: TextOverflow.ellipsis,
  85. style: const TextStyle(
  86. fontSize: 13, color: Colors.black54),
  87. )),
  88. Text(
  89. '${data!.data?[index].createTime}',
  90. textAlign: TextAlign.center,
  91. style:
  92. const TextStyle(fontSize: 13, color: Colors.grey),
  93. ),
  94. ]),
  95. subtitle: const Column(
  96. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  97. children: [
  98. Text('您有什么问题,可以留言,我将第一时间回复。 '),
  99. ]),
  100. onTap: () {
  101. Navigator.push(
  102. context,
  103. MaterialPageRoute(
  104. builder: (context) => ChatHome(
  105. doctorId:
  106. data.data![index].userId.toString(),
  107. doctorName: data.data![index].nickName,
  108. )),
  109. );
  110. },
  111. );
  112. },
  113. );
  114. } else if (snapshot.hasError) {
  115. return Text('Error: ${snapshot.error}');
  116. }
  117. return const ColorLoader();
  118. },
  119. ),
  120. ),
  121. ]),
  122. );
  123. }
  124. }