patient_talk_list.dart 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152
  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/pda_patrol_time_list.dart';
  13. import 'package:http/http.dart' as http;
  14. import 'chat/chat_home.dart';
  15. import 'confirm_registration.dart';
  16. /*void main() => runApp(DoctorTalkList());*/
  17. class PatientTalkList extends StatelessWidget {
  18. DateTime now = DateTime.now();
  19. ValueNotifier<dynamic> result = ValueNotifier(null);
  20. late Future<ChatList?> _future = fetchData();
  21. Future<ChatList?> fetchData() async {
  22. String url = '${Global.BaseUrl}chat/getChatList?userId=${Global.userId}';
  23. final response = await http.get(
  24. Uri.parse(url),
  25. headers: {
  26. HttpHeaders.contentTypeHeader: "application/json; charset=utf-8",
  27. 'token': '${Global.token}',
  28. });
  29. print(url);
  30. print(Global.token);
  31. if (response.statusCode == 200) {
  32. final jsonString = utf8.decode(response.bodyBytes);
  33. final jsonResponse = jsonDecode(jsonString);
  34. print(jsonResponse);
  35. ChatList mChatList = new ChatList.fromJson(jsonResponse);
  36. if (mChatList.code == Global.responseSuccessCode) {
  37. } else {
  38. Component.toast(mChatList.msg.toString(), 0);
  39. }
  40. return mChatList;
  41. } else {
  42. Component.toast("出错了,请稍后再试!", 0);
  43. }
  44. }
  45. @override
  46. Widget build(BuildContext context) {
  47. return MaterialApp(
  48. home: Scaffold(
  49. appBar: new AppBar(
  50. title: new Text('医生沟通列表',
  51. style: TextStyle(
  52. color: Colors.white,
  53. )),
  54. centerTitle: true,
  55. elevation: 0.5,
  56. backgroundColor: Global.StatusBarColor,
  57. leading: new IconButton(
  58. tooltip: '返回上一页',
  59. icon: const Icon(
  60. Icons.arrow_back_ios,
  61. color: Colors.white,
  62. ),
  63. onPressed: () {
  64. Navigator.of(context).pop();
  65. //_nextPage(-1);
  66. },
  67. ),
  68. ),
  69. body: Column(children: [
  70. Expanded(
  71. child: FutureBuilder<ChatList?>(
  72. future: _future,
  73. builder: (context, snapshot) {
  74. if (snapshot.hasData) {
  75. ChatList? data = snapshot.data;
  76. return ListView.builder(
  77. shrinkWrap: true,
  78. itemCount: data?.data?.length,
  79. itemBuilder: (context, index) {
  80. return ListTile(
  81. shape: RoundedRectangleBorder(
  82. borderRadius: BorderRadius.only(
  83. topLeft: Radius.circular(5),
  84. topRight: Radius.circular(5),
  85. bottomRight: Radius.circular(5),
  86. bottomLeft: Radius.circular(5))),
  87. tileColor: Colors.white,
  88. iconColor: Colors.white,
  89. leading: Container(
  90. height: 55,
  91. child: Image.network(
  92. "${Global.ImageUrl}${data!.data?[index].avatar}",
  93. width: 55,
  94. fit: BoxFit.cover,
  95. excludeFromSemantics: true,
  96. errorBuilder: (context, error, stackTrace) => Icon(
  97. Icons.person_pin,
  98. size: 55,
  99. color: Colors.grey,
  100. ),
  101. ),
  102. ),
  103. title: Row(
  104. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  105. children: [
  106. Text(
  107. '${data!.data?[index].nickName} ${data!.data?[index].remark}',
  108. textAlign: TextAlign.center,
  109. style: const TextStyle(
  110. fontSize: 13, color: Colors.black54),
  111. ),
  112. Text(
  113. '${data!.data?[index].createTime}',
  114. textAlign: TextAlign.center,
  115. style: const TextStyle(
  116. fontSize: 13, color: Colors.grey),
  117. ),
  118. ]),
  119. subtitle: Column(
  120. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  121. children: [
  122. Text('您有什么问题,可以留言,我将第一时间回复。 '),
  123. ]),
  124. onTap: () {
  125. Navigator.push(
  126. context,
  127. MaterialPageRoute(builder: (context) => ChatHome(data!.data![index].userId.toString())),
  128. );
  129. },
  130. );
  131. },
  132. );
  133. } else if (snapshot.hasError) {
  134. return Text('Error: ${snapshot.error}');
  135. }
  136. return ColorLoader();
  137. },
  138. ),
  139. ),
  140. ]),
  141. ),
  142. );
  143. }
  144. }