exam_number_input.dart 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161
  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. text: widget.currentInputValue,
  47. style: const TextStyle(
  48. fontSize: 26,
  49. color: Colors.black,
  50. ),
  51. children: [
  52. TextSpan(
  53. text: widget.currentFormObject.append ?? '',
  54. style: const TextStyle(fontSize: 25),
  55. )
  56. ],
  57. ),
  58. ),
  59. ],
  60. ),
  61. ),
  62. ),
  63. );
  64. }
  65. double generateRandomNumber() {
  66. Random random = Random();
  67. double randomNumber = 35.8 + random.nextDouble() * (38 - 35.8);
  68. return double.parse(randomNumber.toStringAsFixed(2));
  69. }
  70. void _buildSpecialInput(FormObject currentFormObject) {
  71. Future.delayed(const Duration(milliseconds: 3000), () {
  72. specialInputController.text = generateRandomNumber().toString();
  73. widget.specialInput?.call(specialInputController.text);
  74. setState(() {});
  75. });
  76. Get.dialog(VAlertDialog(
  77. title: currentFormObject.label ?? '',
  78. width: 600,
  79. contentPadding: const EdgeInsets.symmetric(vertical: 12, horizontal: 24),
  80. content: Row(
  81. children: [
  82. Container(
  83. width: 400,
  84. padding: const EdgeInsets.only(left: 15),
  85. child: TextFormField(
  86. keyboardType: TextInputType.number,
  87. style: const TextStyle(
  88. fontSize: 100, // 设置字体大小
  89. ),
  90. showCursor: false,
  91. controller: specialInputController,
  92. decoration: const InputDecoration(
  93. labelStyle: TextStyle(
  94. fontSize: 100, // 设置标签的字体大小
  95. ),
  96. ),
  97. ),
  98. ),
  99. specialInputController.text == ''
  100. ? Expanded(
  101. child: Row(children: const [
  102. Expanded(
  103. child: Text(
  104. '测量中',
  105. style: TextStyle(
  106. fontSize: 40,
  107. color: Colors.blue,
  108. ),
  109. ),
  110. ),
  111. CircularProgressIndicator(
  112. valueColor: AlwaysStoppedAnimation(
  113. Colors.blue,
  114. ),
  115. ),
  116. SizedBox(
  117. width: 20,
  118. ),
  119. ]),
  120. )
  121. : TextButton(
  122. onPressed: () {
  123. specialInputController.text = '';
  124. Future.delayed(const Duration(milliseconds: 3000), () {
  125. specialInputController.text =
  126. generateRandomNumber().toString();
  127. setState(() {});
  128. });
  129. },
  130. child: Container(
  131. padding: const EdgeInsets.symmetric(horizontal: 30),
  132. decoration: const BoxDecoration(
  133. borderRadius: BorderRadius.all(
  134. Radius.circular(
  135. 30,
  136. ),
  137. ),
  138. color: Colors.blue,
  139. ),
  140. child: const Text(
  141. '测量',
  142. style: TextStyle(fontSize: 40, color: Colors.white),
  143. ),
  144. ),
  145. ),
  146. ],
  147. ),
  148. showCancel: false,
  149. // onConfirm: () {
  150. // // Get.back(result: controller.text);
  151. // },
  152. ));
  153. }
  154. }