ConsultationList.dart 8.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213
  1. import 'dart:convert';
  2. import 'package:flutter/material.dart';
  3. import 'package:flutter/widgets.dart';
  4. import 'package:get_it/get_it.dart';
  5. import 'package:sprintf/sprintf.dart';
  6. import 'package:http/http.dart' as http;
  7. import 'Services/ConsultationService.dart';
  8. class ConsultationList extends StatefulWidget {
  9. ConsultationList({Key? key, required this.token, required this.consultations})
  10. : super();
  11. final String token;
  12. final List<Consultation> consultations;
  13. @override
  14. _ConsultationListState createState() => _ConsultationListState();
  15. }
  16. class _ConsultationListState extends State<ConsultationList> {
  17. @override
  18. Widget build(BuildContext context) {
  19. return Scaffold(
  20. body: Container(
  21. height: 600,
  22. child: Row(
  23. children: [
  24. Container(
  25. height: 500,
  26. width: 400,
  27. child: ListView(
  28. restorationId: 'list_demo_list_view',
  29. padding: const EdgeInsets.symmetric(vertical: 0),
  30. children: [
  31. for (int index = 0;
  32. index < widget.consultations.length;
  33. index++)
  34. Row(
  35. children: [
  36. Expanded(
  37. child: Container(
  38. child: ListTile(
  39. leading: ExcludeSemantics(
  40. child: Icon(Icons.person),
  41. ),
  42. title: Text(widget.consultations[index].id +
  43. " - " +
  44. widget.consultations[index].expertName),
  45. subtitle:
  46. Text(widget.consultations[index].patientName),
  47. onTap: (() =>
  48. onTabPatient(widget.consultations[index].id)),
  49. ),
  50. )),
  51. Container(
  52. alignment: Alignment.topRight,
  53. child: Container(
  54. child: Column(
  55. children: [
  56. ClipRRect(
  57. borderRadius: BorderRadius.circular(2),
  58. child: Container(
  59. color: Colors.amber[50],
  60. child: Row(children: [
  61. Icon(
  62. Icons.star,
  63. color: Colors.amber[500],
  64. size: 12,
  65. ),
  66. Text(
  67. "5.0",
  68. style: TextStyle(
  69. color: Colors.amber[900],
  70. fontSize: 9),
  71. ),
  72. ]))),
  73. Container(
  74. child: TextButton(
  75. child: Text("Start"),
  76. onPressed: (() =>
  77. OnStartLiveConsultation(widget
  78. .consultations[index].id))))
  79. ],
  80. ),
  81. )),
  82. Container(
  83. alignment: Alignment.topRight,
  84. child: Container(
  85. child: Column(
  86. children: [
  87. ClipRRect(
  88. borderRadius: BorderRadius.circular(2),
  89. child: Container(
  90. color: Colors.amber[50],
  91. child: Row(children: [
  92. Icon(
  93. Icons.phone_callback,
  94. color: Colors.amber[500],
  95. size: 12,
  96. ),
  97. ]))),
  98. Container(
  99. child: TextButton(
  100. child: Text("Accept"),
  101. onPressed: (() =>
  102. OnAcceptLiveConsultation(widget
  103. .consultations[index].id))))
  104. ],
  105. ),
  106. )),
  107. Container(
  108. alignment: Alignment.topRight,
  109. child: Container(
  110. child: Column(
  111. children: [
  112. ClipRRect(
  113. borderRadius: BorderRadius.circular(2),
  114. child: Container(
  115. color: Colors.amber[50],
  116. child: Row(children: [
  117. Icon(
  118. Icons.phone_callback_outlined,
  119. color:
  120. Color.fromARGB(255, 255, 0, 0),
  121. size: 12,
  122. ),
  123. ]))),
  124. Container(
  125. child: TextButton(
  126. child: Text("Reject"),
  127. onPressed: (() =>
  128. OnRejectLiveConsultation(widget
  129. .consultations[index].id))))
  130. ],
  131. ),
  132. )),
  133. ],
  134. ),
  135. ],
  136. ),
  137. ),
  138. ],
  139. ),
  140. ));
  141. }
  142. void onTabPatient(String id) async {}
  143. void OnStartLiveConsultation(id) async {
  144. try {
  145. var service = GetIt.instance.get<ConsultationService>();
  146. var result = await service.InitiateLiveConsultationAsync(id);
  147. print("InitiateLiveConsultationAsync");
  148. } catch (ex) {
  149. print('OnStartLiveConsultation.to ex' + ex.toString());
  150. }
  151. }
  152. void OnAcceptLiveConsultation(id) async {
  153. try {
  154. var service = GetIt.instance.get<ConsultationService>();
  155. var result = await service.AcceptLiveConsultationAsync(id);
  156. print("AcceptLiveConsultationAsync");
  157. } catch (ex) {
  158. print('OnAcceptLiveConsultation.to ex' + ex.toString());
  159. }
  160. }
  161. void OnRejectLiveConsultation(id) async {
  162. try {
  163. var service = GetIt.instance.get<ConsultationService>();
  164. var result = await service.RejectLiveConsultationAsync(id);
  165. print("RejectLiveConsultationAsync");
  166. } catch (ex) {
  167. print('OnRejectLiveConsultation.to ex' + ex.toString());
  168. }
  169. }
  170. }
  171. class Consultation {
  172. final String id;
  173. final String patientName;
  174. final String expertName;
  175. Consultation(
  176. {required this.id, required this.patientName, required this.expertName});
  177. factory Consultation.fromJson(Map<String, dynamic> json) {
  178. var item = Consultation(
  179. id: json['ConsultationCode'] as String,
  180. patientName: json['PatientName'] as String,
  181. expertName: json['ExpertUserName'] as String);
  182. return item;
  183. }
  184. Map<String, dynamic> toMap() {
  185. return {
  186. 'ConsultationCode': id,
  187. 'PatientName': patientName,
  188. 'ExpertUserName': expertName,
  189. };
  190. }
  191. @override
  192. String toString() {
  193. return 'Patient{id: $id}';
  194. }
  195. }