123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168 |
- import 'dart:math';
- import 'package:flutter/material.dart';
- import 'package:get/get.dart';
- import 'package:vitalapp/components/alert_dialog.dart';
- import 'package:vitalapp/pages/check/models/form.dart';
- import 'package:vitalapp/pages/check/widgets/exam_configurable/exam_card.dart';
- class ExamNumberInput extends StatefulWidget {
- const ExamNumberInput({
- super.key,
- required this.currentFormObject,
- required this.currentInputValue,
- this.commonInput,
- this.specialInput,
- });
- final FormObject currentFormObject;
- final String currentInputValue;
- final Function? commonInput;
- final Function(String value)? specialInput;
- @override
- State<ExamNumberInput> createState() => _ExamNumberInputState();
- }
- class _ExamNumberInputState extends State<ExamNumberInput> {
- TextEditingController specialInputController = TextEditingController();
- @override
- Widget build(BuildContext context) {
- return ExamCard(
- title: widget.currentFormObject.label ?? '',
- clickCard: () {
- widget.commonInput?.call();
- },
- content: Container(
- alignment: Alignment.bottomRight,
- padding: const EdgeInsets.only(
- bottom: 20,
- right: 30,
- left: 40,
- ),
- constraints: const BoxConstraints(minHeight: 50),
- child: FittedBox(
- child: Row(
- mainAxisAlignment: MainAxisAlignment.end,
- crossAxisAlignment: CrossAxisAlignment.end,
- children: [
- RichText(
- text: TextSpan(
- style: TextStyle(
- fontSize: 26,
- color: Colors.black,
- fontFamily: "NotoSansSC",
- fontFamilyFallback: const ["NotoSansSC"],
- ),
- text: widget.currentInputValue,
- children: [
- TextSpan(
- text: widget.currentFormObject.append ?? '',
- style: const TextStyle(
- fontSize: 26,
- color: Colors.black,
- fontFamily: "Rubik",
- // fontFamilyFallback: const ["NotoSansSC"],
- ),
- )
- ],
- ),
- ),
- ],
- ),
- ),
- ),
- );
- }
- double generateRandomNumber() {
- Random random = Random();
- double randomNumber = 35.8 + random.nextDouble() * (38 - 35.8);
- return double.parse(randomNumber.toStringAsFixed(2));
- }
- void _buildSpecialInput(FormObject currentFormObject) {
- Future.delayed(const Duration(milliseconds: 3000), () {
- specialInputController.text = generateRandomNumber().toString();
- widget.specialInput?.call(specialInputController.text);
- setState(() {});
- });
- Get.dialog(VAlertDialog(
- title: currentFormObject.label ?? '',
- width: 600,
- contentPadding: const EdgeInsets.symmetric(vertical: 12, horizontal: 24),
- content: Row(
- children: [
- Container(
- width: 400,
- padding: const EdgeInsets.only(left: 15),
- child: TextFormField(
- keyboardType: TextInputType.number,
- style: const TextStyle(
- fontSize: 100, // 设置字体大小
- ),
- showCursor: false,
- controller: specialInputController,
- decoration: const InputDecoration(
- labelStyle: TextStyle(
- fontSize: 100, // 设置标签的字体大小
- ),
- ),
- ),
- ),
- specialInputController.text == ''
- ? Expanded(
- child: Row(children: const [
- Expanded(
- child: Text(
- '测量中',
- style: TextStyle(
- fontSize: 40,
- color: Colors.blue,
- ),
- ),
- ),
- CircularProgressIndicator(
- valueColor: AlwaysStoppedAnimation(
- Colors.blue,
- ),
- ),
- SizedBox(
- width: 20,
- ),
- ]),
- )
- : TextButton(
- onPressed: () {
- specialInputController.text = '';
- Future.delayed(const Duration(milliseconds: 3000), () {
- specialInputController.text =
- generateRandomNumber().toString();
- setState(() {});
- });
- },
- child: Container(
- padding: const EdgeInsets.symmetric(horizontal: 30),
- decoration: const BoxDecoration(
- borderRadius: BorderRadius.all(
- Radius.circular(
- 30,
- ),
- ),
- color: Colors.blue,
- ),
- child: const Text(
- '测量',
- style: TextStyle(fontSize: 40, color: Colors.white),
- ),
- ),
- ),
- ],
- ),
- showCancel: false,
- // onConfirm: () {
- // // Get.back(result: controller.text);
- // },
- ));
- }
- }
|