123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- import 'package:fis_common/index.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter/services.dart';
- import 'package:vitalapp/components/dialog_input.dart';
- import 'package:vitalapp/pages/check/models/form.dart';
- import 'package:vitalapp/pages/check/widgets/exam_configurable/exam_card.dart';
- import 'package:vitalapp/pages/form/form_info.dart';
- ///输入组件,和ExamText的弹窗放在了内部
- class ExamTextInput extends StatefulWidget {
- const ExamTextInput({
- super.key,
- required this.currentFormObject,
- this.isNumber = false,
- });
- final FormObject currentFormObject;
- final bool isNumber;
- @override
- State<ExamTextInput> createState() => _ExamInputState();
- }
- class _ExamInputState extends State<ExamTextInput> {
- String _currentValue = '';
- bool _isDisabledValue = false;
- bool _isHidden = false;
- @override
- void initState() {
- if (FormInfo.instance.formValue.containsKey(widget.currentFormObject.key)) {
- _currentValue = FormInfo.instance.formValue[widget.currentFormObject.key];
- }
- super.initState();
- FormInfo.instance.onChangeTargetValue.addListener(_onChangeTargetValue);
- }
- @override
- void dispose() {
- FormInfo.instance.onChangeTargetValue.removeListener(_onChangeTargetValue);
- super.dispose();
- }
- @override
- Widget build(BuildContext context) {
- if (_isHidden) {
- return SizedBox();
- }
- return ExamCard(
- title: widget.currentFormObject.label ?? '',
- color: _isDisabledValue ? Colors.grey[300]! : Colors.white,
- clickCard: _clickCard,
- content: Container(
- alignment: Alignment.bottomRight,
- padding: const EdgeInsets.only(
- right: 30,
- left: 40,
- ),
- child: Column(mainAxisAlignment: MainAxisAlignment.center, children: [
- RichText(
- text: TextSpan(
- style: TextStyle(
- fontSize: 26,
- color: Colors.black,
- fontFamily: "NotoSansSC",
- fontFamilyFallback: const ["NotoSansSC"],
- ),
- text: _currentValue,
- children: [
- TextSpan(
- text: widget.currentFormObject.append ?? '',
- style: const TextStyle(
- fontSize: 26,
- fontFamily: "NotoSansSC",
- fontFamilyFallback: const ["NotoSansSC"],
- ),
- )
- ],
- ),
- ),
- ])),
- );
- }
- Future<void> _clickCard() async {
- if (_isDisabledValue) {
- return;
- }
- List<TextInputFormatter>? inputFormatters;
- TextInputType? keyboardType;
- if (widget.isNumber) {
- inputFormatters = [
- FilteringTextInputFormatter.allow(RegExp(r'^\d*\.?\d*')),
- ];
- keyboardType = TextInputType.numberWithOptions(decimal: true);
- }
- String? result = await VDialogInput(
- title: widget.currentFormObject.label,
- initialValue: _currentValue,
- inputFormatters: inputFormatters,
- keyboardType: keyboardType,
- ).show();
- if (result?.isNotEmpty ?? false) {
- FormInfo.instance.formValue[widget.currentFormObject.key!] = result;
- setState(() {
- _currentValue = result!;
- });
- FormInfo.instance.onValueChange.emit(
- this,
- UpdateFormArgs(
- sourceKey: widget.currentFormObject.key ?? '',
- sourceValue: result,
- ),
- );
- }
- }
- void _onChangeTargetValue(Object sender, TargetFormArgs e) {
- if (e.targetKey != widget.currentFormObject.key) {
- return;
- }
- if (e.isHidden) {
- setState(() {
- _isHidden = true;
- });
- } else {
- setState(() {
- _isHidden = false;
- });
- }
- if (e.isDisabledValue) {
- setState(() {
- _isDisabledValue = true;
- _currentValue = e.targetValue;
- });
- } else if (!e.isDisabledValue && _isDisabledValue) {
- setState(() {
- _isDisabledValue = false;
- });
- }
- if (e.targetValue.isNotNullOrEmpty) {
- setState(() {
- _currentValue = e.targetValue;
- });
- }
- }
- }
|