SignInScreen.dart 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335
  1. import 'package:flutter/material.dart';
  2. import 'package:get_it/get_it.dart';
  3. import 'package:ustest/Services/UserService.dart';
  4. import 'package:web_socket_channel/web_socket_channel.dart';
  5. import 'dart:convert';
  6. import 'dart:typed_data';
  7. import 'package:flutter/services.dart';
  8. class SignInScreen extends StatelessWidget {
  9. const SignInScreen();
  10. @override
  11. Widget build(BuildContext context) {
  12. return Scaffold(
  13. backgroundColor: Colors.grey[200],
  14. body: const Center(
  15. child: SizedBox(
  16. width: 400,
  17. child: Card(
  18. child: SignInForm(),
  19. ),
  20. ),
  21. ),
  22. );
  23. }
  24. }
  25. class SignInForm extends StatefulWidget {
  26. const SignInForm();
  27. @override
  28. _SignInFormState createState() => _SignInFormState();
  29. }
  30. class _SignInFormState extends State<SignInForm> {
  31. final _serverUrlTextController =
  32. TextEditingController(text: "http://192.168.6.20:8303");
  33. final _userNameTextController = TextEditingController(text: "fly01");
  34. final _userPasswordTextController =
  35. TextEditingController(text: "fb6414d24e3c347d46032b0496f1c4e4");
  36. final _statusContoller = Text('');
  37. double _formProgress = 0;
  38. @override
  39. Widget build(BuildContext context) {
  40. print("build Signin");
  41. return Form(
  42. child: Column(
  43. mainAxisSize: MainAxisSize.min,
  44. children: [
  45. LinearProgressIndicator(value: _formProgress),
  46. Text('Sign In', style: Theme.of(context).textTheme.headline4),
  47. Padding(
  48. padding: const EdgeInsets.all(8.0),
  49. child: TextFormField(
  50. controller: _serverUrlTextController,
  51. decoration: const InputDecoration(hintText: 'Server Url'),
  52. ),
  53. ),
  54. Padding(
  55. padding: const EdgeInsets.all(8.0),
  56. child: TextFormField(
  57. controller: _userNameTextController,
  58. decoration: const InputDecoration(hintText: 'User Name'),
  59. ),
  60. ),
  61. Padding(
  62. padding: const EdgeInsets.all(8.0),
  63. child: TextFormField(
  64. controller: _userPasswordTextController,
  65. decoration: const InputDecoration(hintText: 'Password'),
  66. ),
  67. ),
  68. Padding(
  69. padding: const EdgeInsets.all(8.0),
  70. child: Row(
  71. mainAxisAlignment: MainAxisAlignment.center,
  72. children: [
  73. TextButton(
  74. style: ButtonStyle(
  75. foregroundColor: MaterialStateProperty.resolveWith(
  76. (Set<MaterialState> states) {
  77. return states.contains(MaterialState.disabled)
  78. ? null
  79. : Colors.white;
  80. }),
  81. backgroundColor: MaterialStateProperty.resolveWith(
  82. (Set<MaterialState> states) {
  83. return states.contains(MaterialState.disabled)
  84. ? null
  85. : Colors.blue;
  86. }),
  87. ),
  88. onPressed: _showWelcomeScreen,
  89. child: const Text('Sign In'),
  90. ),
  91. Padding(
  92. padding: const EdgeInsets.all(8.0),
  93. child: TextButton(
  94. style: ButtonStyle(
  95. foregroundColor: MaterialStateProperty.resolveWith(
  96. (Set<MaterialState> states) {
  97. return states.contains(MaterialState.disabled)
  98. ? null
  99. : Colors.white;
  100. }),
  101. backgroundColor: MaterialStateProperty.resolveWith(
  102. (Set<MaterialState> states) {
  103. return states.contains(MaterialState.disabled)
  104. ? null
  105. : Colors.blue;
  106. }),
  107. ),
  108. onPressed: () => {Navigator.of(context).pop()},
  109. child: const Text('Cancel'),
  110. ),
  111. ),
  112. ],
  113. )),
  114. ],
  115. ),
  116. );
  117. }
  118. void _showWelcomeScreen() async {
  119. try {
  120. var service = GetIt.instance.get<UserService>();
  121. var userName = _userNameTextController.text;
  122. var password = _userPasswordTextController.text;
  123. var host = _serverUrlTextController.text;
  124. var result = await service.signInAsync(host, userName, password);
  125. if (result != null) {
  126. Navigator.of(context).pushNamed('/');
  127. }
  128. } catch (e) {
  129. print('signInAsync ex: $e');
  130. }
  131. }
  132. }
  133. enum NotificationTypeEnum {
  134. /// <summary>
  135. /// Unknown|0| 未知
  136. /// </summary>
  137. Unknown,
  138. /// <summary>
  139. /// ChatMsgNotification|1| 聊天通知
  140. /// </summary>
  141. ChatMsgNotification,
  142. /// <summary>
  143. /// TokenReplacedNotification|2| 账号被替换登出通知
  144. /// </summary>
  145. TokenReplacedNotification,
  146. /// <summary>
  147. /// DisconnectNotification| 3|与服务器断开连接通知
  148. /// </summary>
  149. DisconnectNotification,
  150. /// <summary>
  151. /// ConnectionNotification| 4| 与服务器已连接通知
  152. /// </summary>
  153. ConnectionNotification,
  154. /// <summary>
  155. /// ExamRecordsFinishedNotification| 5 | 完成检查通知
  156. /// </summary>
  157. ExamRecordsFinishedNotification,
  158. /// <summary>
  159. /// RejectApplyConsultationNotification| 6 | 拒绝预约申请的通知
  160. /// </summary>
  161. RejectApplyConsultationNotification,
  162. /// <summary>
  163. /// CancelInvitingInLiveConsultationNotification| 7 | 取消会诊过程中邀请其他成员的通知
  164. /// </summary>
  165. CancelInvitingInLiveConsultationNotification,
  166. /// <summary>
  167. /// InviteInLiveConsultationNotification| 8 | 会诊过程中邀请其他成员的通知
  168. /// </summary>
  169. InviteInLiveConsultationNotification,
  170. /// <summary>
  171. /// InviteInLiveConsultationNotification| 9 | 会诊开始前提醒的通知
  172. /// </summary>
  173. ConsultationRemindNotification,
  174. /// <summary>
  175. /// PasswordExpiredWarningNotification| 10 | 用户密码过期预警通知
  176. /// </summary>
  177. PasswordExpiredWarningNotification,
  178. /// <summary>
  179. /// InviteLiveConsultationNotification| 11 | 开始会诊的通知
  180. /// </summary>
  181. InviteLiveConsultationNotification,
  182. /// <summary>
  183. /// AcceptLiveConsultationNotification| 12 | 接受会诊的通知
  184. /// </summary>
  185. AcceptLiveConsultationNotification,
  186. /// <summary>
  187. /// RejectLiveConsultationNotification| 13 | 拒绝会诊的通知
  188. /// </summary>
  189. RejectLiveConsultationNotification,
  190. /// <summary>
  191. /// InviteLiveConsultationToDeviceNotification| 14 | 开始会诊通知 to 设备端
  192. /// </summary>
  193. InviteLiveConsultationToDeviceNotification,
  194. /// <summary>
  195. /// CancelLiveConsultationNotification| 15 | 取消会诊通知
  196. /// </summary>
  197. CancelLiveConsultationNotification,
  198. /// <summary>
  199. /// CloseLiveConsultationNotification| 16 | 关闭会诊通知
  200. /// </summary>
  201. CloseLiveConsultationNotification,
  202. /// <summary>
  203. /// JoinLiveConsultationNotification| 17 | 进入会诊通知
  204. /// </summary>
  205. JoinLiveConsultationNotification,
  206. /// <summary>
  207. /// NetworkErrConsultationNotification| 18 | 网络质量不佳会诊通知
  208. /// </summary>
  209. NetworkErrConsultationNotification,
  210. /// <summary>
  211. /// LeaveConsultationNotification| 19 | 离开会诊通知
  212. /// </summary>
  213. LeaveConsultationNotification,
  214. /// <summary>
  215. /// JoinInLiveConsultationNotification| 20 | 会诊中加入房间
  216. /// </summary>
  217. JoinInLiveConsultationNotification,
  218. /// <summary>
  219. /// RejectLiveConsultationNotification| 21 | 拒绝会诊的通知
  220. /// </summary>
  221. RejectInviteLiveConsultationNotification,
  222. /// <summary>
  223. /// ApplyConsultationNotification| 22 | 会诊申请通知
  224. /// </summary>
  225. ApplyConsultationNotification,
  226. /// <summary>
  227. /// ApprovalApplyConsultationNotification| 23 | 批准申请会诊通知
  228. /// </summary>
  229. ApprovalApplyConsultationNotification,
  230. /// <summary>
  231. /// InviteeConsultationNotification| 24 | 会诊受邀请人通知
  232. /// </summary>
  233. InviteeConsultationNotification,
  234. /// <summary>
  235. /// InviteeApproveApplyConsultationNotification| 25 | 会诊受邀请参与人同意通知
  236. /// </summary>
  237. InviteeApproveApplyConsultationNotification,
  238. /// <summary>
  239. /// InviteeRejectApplyConsultationNotification| 26 | 会诊受邀请参与人拒绝通知
  240. /// </summary>
  241. InviteeRejectApplyConsultationNotification,
  242. /// <summary>
  243. /// MuteLiveConsultationNotification| 27 | 开启关闭静音
  244. /// </summary>
  245. MuteLiveConsultationNotification,
  246. /// <summary>
  247. /// SwitchLiveConsultationVideoNotification| 28 | 开启关闭视频
  248. /// </summary>
  249. SwitchLiveConsultationVideoNotification,
  250. /// <summary>
  251. /// HeartRateJoinConsultationNotification| 29 | 会诊心跳,进入房间
  252. /// </summary>
  253. HeartRateJoinConsultationNotification,
  254. /// <summary>
  255. /// HeartRateLeaveConsultationNotification| 30 | 会诊心跳,离开房间
  256. /// </summary>
  257. HeartRateLeaveConsultationNotification,
  258. /// <summary>
  259. /// CloseLiveConsultationToDeviceNotification| 31 | 关闭会诊通知 to 设备端
  260. /// </summary>
  261. CloseLiveConsultationToDeviceNotification,
  262. /// <summary>
  263. /// CancelLiveConsultationToDeviceNotification| 32 | 取消会诊通知 to 设备端
  264. /// </summary>
  265. CancelLiveConsultationToDeviceNotification
  266. }
  267. class ConnectionNotification {
  268. NotificationTypeEnum notificationType;
  269. ConnectionNotification({
  270. this.notificationType = NotificationTypeEnum.Unknown,
  271. });
  272. factory ConnectionNotification.fromJson(Map<String, dynamic> map) {
  273. return ConnectionNotification(
  274. notificationType: NotificationTypeEnum.values
  275. .firstWhere((e) => e.index == map['NotificationType']),
  276. );
  277. }
  278. }
  279. class DisconnectNotification {
  280. NotificationTypeEnum notificationType;
  281. DisconnectNotification({
  282. this.notificationType = NotificationTypeEnum.Unknown,
  283. });
  284. factory DisconnectNotification.fromJson(Map<String, dynamic> map) {
  285. return DisconnectNotification(
  286. notificationType: NotificationTypeEnum.values
  287. .firstWhere((e) => e.index == map['NotificationType']),
  288. );
  289. }
  290. }
  291. class FinishNotifyRecordsMessage {}