doctor_talk_list.dart 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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:flutter/services.dart';
  9. import 'package:http/http.dart' as http;
  10. import 'bean/doctor_chat_list.dart';
  11. import 'chat/chat_home_doctor.dart';
  12. /*void main() => runApp(DoctorTalkList());*/
  13. class DoctorTalkList extends StatelessWidget {
  14. DateTime now = DateTime.now();
  15. ValueNotifier<dynamic> result = ValueNotifier(null);
  16. late final Future<DoctorChatList?> _future = fetchData();
  17. int lastExitTime = 0;
  18. Future<DoctorChatList?> fetchData() async {
  19. String url =
  20. '${Global.BaseUrl}chat/getChatPatientList?dockerId=${Global.user.data?.id}';
  21. final response = await http.get(Uri.parse(url), headers: jsonHeaders(withToken: true));
  22. if (response.statusCode == 200) {
  23. final json = decodeBodyToJson(response.bodyBytes);
  24. logd("医生聊天列表=$json");
  25. DoctorChatList mDoctorChatList = new DoctorChatList.fromJson(json);
  26. if (mDoctorChatList.code == Global.responseSuccessCode) {
  27. } else {
  28. Component.toast(mDoctorChatList.msg.toString(), 0);
  29. }
  30. return mDoctorChatList;
  31. } else {
  32. Component.toast("出错了,请稍后再试!", 0);
  33. }
  34. }
  35. @override
  36. Widget build(BuildContext context) {
  37. return PopScope(
  38. canPop: !Platform.isAndroid,
  39. onPopInvokedWithResult: _onPopInvoke,
  40. child: Scaffold(
  41. appBar: AppBar(
  42. title: const Text('患者沟通列表',
  43. style: TextStyle(
  44. color: Colors.white,
  45. )),
  46. centerTitle: true,
  47. elevation: 0.5,
  48. backgroundColor: Global.StatusBarColor,
  49. ),
  50. body: Column(children: [
  51. Expanded(
  52. child: FutureBuilder<DoctorChatList?>(
  53. future: _future,
  54. builder: (context, snapshot) {
  55. if (snapshot.hasData) {
  56. DoctorChatList? data = snapshot.data;
  57. return ListView.builder(
  58. shrinkWrap: true,
  59. itemCount: data?.data?.length,
  60. itemBuilder: (context, index) {
  61. return ListTile(
  62. shape: const RoundedRectangleBorder(
  63. borderRadius: BorderRadius.only(
  64. topLeft: Radius.circular(5),
  65. topRight: Radius.circular(5),
  66. bottomRight: Radius.circular(5),
  67. bottomLeft: Radius.circular(5))),
  68. tileColor: Colors.white,
  69. iconColor: Colors.white,
  70. leading: UserHeader(
  71. url:
  72. "${Global.ImageUrl}${data!.data?[index].avatar}",
  73. ),
  74. title: Row(
  75. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  76. children: [
  77. Text(
  78. '与 ${data!.data?[index].phoneNumber} 的聊天记录',
  79. textAlign: TextAlign.center,
  80. style: const TextStyle(
  81. fontSize: 15, color: Colors.black),
  82. ),
  83. /*Text(
  84. '${data!.data?[index].updateDate}',
  85. textAlign: TextAlign.center,
  86. style: const TextStyle(
  87. fontSize: 13, color: Colors.grey),
  88. ),*/
  89. ]),
  90. subtitle: Text(
  91. '${data!.data?[index].updateDate}',
  92. style: const TextStyle(
  93. fontSize: 13, color: Colors.grey),
  94. ),
  95. onTap: () {
  96. Navigator.push(
  97. context,
  98. MaterialPageRoute(
  99. builder: (context) => ChatHomeDoctor(
  100. data.data![index].id.toString(),
  101. data.data![index].phoneNumber
  102. .toString())),
  103. );
  104. },
  105. );
  106. },
  107. );
  108. } else if (snapshot.hasError) {
  109. return Text('Error: ${snapshot.error}');
  110. }
  111. return const ColorLoader();
  112. },
  113. ),
  114. ),
  115. ]),
  116. ));
  117. }
  118. void _onPopInvoke(bool didPop, dynamic result) {
  119. if (didPop) {
  120. return;
  121. }
  122. int now = DateTime.now().millisecondsSinceEpoch;
  123. if (lastExitTime == 0 || now - lastExitTime > 2000) {
  124. Component.toast("再次点击退出应用", 2);
  125. lastExitTime = now;
  126. return;
  127. }
  128. SystemNavigator.pop(animated: true);
  129. }
  130. }