lab_dialog.dart 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  1. import 'dart:async';
  2. import 'package:fis_jsonrpc/rpc.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:flyinsono/lab/color/lab_colors.dart';
  5. import 'package:flyinsono/lab/manager/interfaces/task.dart';
  6. import 'package:flyinsono/managers/interfaces/entities/urm_dialog_result.dart';
  7. import 'package:get/get.dart';
  8. class LabDialog extends StatefulWidget {
  9. const LabDialog({
  10. Key? key,
  11. required this.title,
  12. required this.content,
  13. this.confirmText = "确定",
  14. this.cancelText = "取消",
  15. this.maxWidth = 500,
  16. this.showLoading = false,
  17. this.showCloseIcon = true,
  18. this.showCancelButton = true,
  19. this.confirmLabWidth = 100,
  20. this.mainTaskCode,
  21. }) : super(key: key);
  22. final double confirmLabWidth;
  23. final String title;
  24. final String content;
  25. final String confirmText;
  26. final String cancelText;
  27. final String? mainTaskCode;
  28. final double maxWidth;
  29. final bool showLoading;
  30. final bool showCloseIcon;
  31. final bool showCancelButton;
  32. @override
  33. State<StatefulWidget> createState() {
  34. return LabDialogState();
  35. }
  36. static Future<T?> showDialog<T>(
  37. Widget child, [
  38. bool barrierDismissible = false,
  39. ]) async {
  40. return await Get.dialog<T>(
  41. child,
  42. barrierDismissible: barrierDismissible,
  43. barrierColor: LabColors.base100.withOpacity(0.1),
  44. );
  45. }
  46. }
  47. class LabDialogState extends State<LabDialog> {
  48. Timer? timer;
  49. static ButtonStyle buttonStyle = ElevatedButton.styleFrom(
  50. elevation: 0.0,
  51. backgroundColor: LabColors.dialogHeaderColor,
  52. padding: EdgeInsets.symmetric(
  53. horizontal: 12,
  54. vertical: 5,
  55. ),
  56. );
  57. static const TextStyle buttonTextStyle = TextStyle(
  58. fontSize: 15,
  59. height: 1,
  60. color: LabColors.text200,
  61. );
  62. @override
  63. void initState() {
  64. if (widget.mainTaskCode != null) {
  65. timer = Timer.periodic(Duration(seconds: 1), (Timer timer) async {
  66. MainTaskDTO? serverTaskInfo = await Get.find<IServerTaskManager>()
  67. .getMainTaskDetailAsync(widget.mainTaskCode ?? '');
  68. if (serverTaskInfo != null &&
  69. serverTaskInfo.status == VTaskStatus.Completed) {
  70. var task = serverTaskInfo.taskDetailList?.first;
  71. if (task?.result ?? false) {
  72. timer.cancel();
  73. Get.back(result: UrmDialogResult.Complate);
  74. } else {
  75. timer.cancel();
  76. Get.back(result: UrmDialogResult.AnalysisFailed);
  77. }
  78. }
  79. });
  80. }
  81. super.initState();
  82. }
  83. @override
  84. void dispose() {
  85. timer?.cancel();
  86. super.dispose();
  87. }
  88. @override
  89. Widget build(BuildContext context) {
  90. return Dialog(
  91. backgroundColor: Colors.transparent,
  92. insetPadding: EdgeInsets.all(0),
  93. child: Container(
  94. clipBehavior: Clip.antiAlias,
  95. constraints: BoxConstraints(maxWidth: widget.maxWidth),
  96. decoration: BoxDecoration(
  97. borderRadius: BorderRadius.circular(5),
  98. // border: Border.all(
  99. // color: LabColors.dialogHeaderColor,
  100. // width: 2,
  101. // strokeAlign: 0.0,
  102. // ),
  103. color: LabColors.base200,
  104. ),
  105. child: Column(
  106. mainAxisSize: MainAxisSize.min,
  107. children: [
  108. Container(
  109. color: LabColors.dialogHeaderColor,
  110. padding: EdgeInsets.symmetric(vertical: 5),
  111. child: SizedBox(
  112. height: 40,
  113. child: Row(
  114. mainAxisAlignment: MainAxisAlignment.center,
  115. children: [
  116. SizedBox(width: 15),
  117. Text(
  118. widget.title,
  119. style: TextStyle(
  120. fontSize: 18,
  121. color: LabColors.text200,
  122. ),
  123. ),
  124. Expanded(child: Container()),
  125. if (widget.showCloseIcon)
  126. IconButton(
  127. icon: Icon(
  128. Icons.close_rounded,
  129. color: LabColors.text200,
  130. size: 20,
  131. ),
  132. onPressed: () {
  133. Get.back(result: false);
  134. },
  135. ),
  136. ],
  137. ),
  138. ),
  139. ),
  140. SizedBox(height: 30),
  141. Align(
  142. alignment: Alignment.centerLeft,
  143. child: Padding(
  144. padding: const EdgeInsets.symmetric(horizontal: 15),
  145. child: Row(
  146. children: [
  147. Text(
  148. widget.content,
  149. style: TextStyle(
  150. fontSize: 18,
  151. color: LabColors.text800,
  152. ),
  153. ),
  154. if (widget.showLoading)
  155. SizedBox.square(
  156. dimension: 40,
  157. child: Center(
  158. child: Padding(
  159. padding: const EdgeInsets.all(12.0),
  160. child: CircularProgressIndicator(
  161. strokeWidth: 2.5,
  162. color: LabColors.base600,
  163. ),
  164. ),
  165. ),
  166. ),
  167. ],
  168. ),
  169. ),
  170. ),
  171. SizedBox(height: 40),
  172. Container(
  173. height: 40,
  174. child: Row(
  175. mainAxisAlignment: MainAxisAlignment.center,
  176. crossAxisAlignment: CrossAxisAlignment.stretch,
  177. children: [
  178. Container(
  179. width: widget.confirmLabWidth,
  180. child: ElevatedButton(
  181. style: buttonStyle,
  182. child: Text(widget.confirmText, style: buttonTextStyle),
  183. onPressed: () {
  184. Get.back(result: true);
  185. },
  186. ),
  187. ),
  188. if (widget.showCancelButton) SizedBox(width: 20),
  189. if (widget.showCancelButton)
  190. Container(
  191. width: 100,
  192. child: ElevatedButton(
  193. style: buttonStyle,
  194. child: Text(widget.cancelText, style: buttonTextStyle),
  195. onPressed: () {
  196. Get.back(result: false);
  197. },
  198. ),
  199. ),
  200. ],
  201. ),
  202. ),
  203. SizedBox(height: 15),
  204. ],
  205. ),
  206. ),
  207. );
  208. }
  209. }