exam_number_input.dart 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. import 'dart:math';
  2. import 'package:flutter/material.dart';
  3. import 'package:get/get.dart';
  4. import 'package:vitalapp/components/alert_dialog.dart';
  5. import 'package:vitalapp/pages/check/models/form.dart';
  6. import 'package:vitalapp/pages/check/widgets/exam_configurable/exam_card.dart';
  7. class ExamNumberInput extends StatefulWidget {
  8. const ExamNumberInput({
  9. super.key,
  10. required this.currentFormObject,
  11. required this.currentInputValue,
  12. this.commonInput,
  13. this.specialInput,
  14. });
  15. final FormObject currentFormObject;
  16. final String currentInputValue;
  17. final Function? commonInput;
  18. final Function(String value)? specialInput;
  19. @override
  20. State<ExamNumberInput> createState() => _ExamNumberInputState();
  21. }
  22. class _ExamNumberInputState extends State<ExamNumberInput> {
  23. TextEditingController specialInputController = TextEditingController();
  24. @override
  25. Widget build(BuildContext context) {
  26. return ExamCard(
  27. title: widget.currentFormObject.label ?? '',
  28. clickCard: () {
  29. widget.commonInput?.call();
  30. },
  31. content: Container(
  32. alignment: Alignment.bottomRight,
  33. padding: const EdgeInsets.only(
  34. bottom: 20,
  35. right: 30,
  36. left: 40,
  37. ),
  38. constraints: const BoxConstraints(minHeight: 50),
  39. child: FittedBox(
  40. child: Row(
  41. mainAxisAlignment: MainAxisAlignment.end,
  42. crossAxisAlignment: CrossAxisAlignment.end,
  43. children: [
  44. RichText(
  45. text: TextSpan(
  46. style: TextStyle(
  47. fontSize: 26,
  48. color: Colors.black,
  49. fontFamily: "NotoSansSC",
  50. fontFamilyFallback: const ["NotoSansSC"],
  51. ),
  52. text: widget.currentInputValue,
  53. children: [
  54. TextSpan(
  55. text: widget.currentFormObject.append ?? '',
  56. style: const TextStyle(
  57. fontSize: 26,
  58. color: Colors.black,
  59. fontFamily: "Rubik",
  60. // fontFamilyFallback: const ["NotoSansSC"],
  61. ),
  62. )
  63. ],
  64. ),
  65. ),
  66. ],
  67. ),
  68. ),
  69. ),
  70. );
  71. }
  72. double generateRandomNumber() {
  73. Random random = Random();
  74. double randomNumber = 35.8 + random.nextDouble() * (38 - 35.8);
  75. return double.parse(randomNumber.toStringAsFixed(2));
  76. }
  77. void _buildSpecialInput(FormObject currentFormObject) {
  78. Future.delayed(const Duration(milliseconds: 3000), () {
  79. specialInputController.text = generateRandomNumber().toString();
  80. widget.specialInput?.call(specialInputController.text);
  81. setState(() {});
  82. });
  83. Get.dialog(VAlertDialog(
  84. title: currentFormObject.label ?? '',
  85. width: 600,
  86. contentPadding: const EdgeInsets.symmetric(vertical: 12, horizontal: 24),
  87. content: Row(
  88. children: [
  89. Container(
  90. width: 400,
  91. padding: const EdgeInsets.only(left: 15),
  92. child: TextFormField(
  93. keyboardType: TextInputType.number,
  94. style: const TextStyle(
  95. fontSize: 100, // 设置字体大小
  96. ),
  97. showCursor: false,
  98. controller: specialInputController,
  99. decoration: const InputDecoration(
  100. labelStyle: TextStyle(
  101. fontSize: 100, // 设置标签的字体大小
  102. ),
  103. ),
  104. ),
  105. ),
  106. specialInputController.text == ''
  107. ? Expanded(
  108. child: Row(children: const [
  109. Expanded(
  110. child: Text(
  111. '测量中',
  112. style: TextStyle(
  113. fontSize: 40,
  114. color: Colors.blue,
  115. ),
  116. ),
  117. ),
  118. CircularProgressIndicator(
  119. valueColor: AlwaysStoppedAnimation(
  120. Colors.blue,
  121. ),
  122. ),
  123. SizedBox(
  124. width: 20,
  125. ),
  126. ]),
  127. )
  128. : TextButton(
  129. onPressed: () {
  130. specialInputController.text = '';
  131. Future.delayed(const Duration(milliseconds: 3000), () {
  132. specialInputController.text =
  133. generateRandomNumber().toString();
  134. setState(() {});
  135. });
  136. },
  137. child: Container(
  138. padding: const EdgeInsets.symmetric(horizontal: 30),
  139. decoration: const BoxDecoration(
  140. borderRadius: BorderRadius.all(
  141. Radius.circular(
  142. 30,
  143. ),
  144. ),
  145. color: Colors.blue,
  146. ),
  147. child: const Text(
  148. '测量',
  149. style: TextStyle(fontSize: 40, color: Colors.white),
  150. ),
  151. ),
  152. ),
  153. ],
  154. ),
  155. showCancel: false,
  156. // onConfirm: () {
  157. // // Get.back(result: controller.text);
  158. // },
  159. ));
  160. }
  161. }