123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131 |
- import 'package:fis_common/index.dart';
- import 'package:flutter/cupertino.dart';
- import 'package:flutter/foundation.dart';
- import 'package:flutter/material.dart';
- import 'package:get/get.dart';
- import 'package:intl/intl.dart';
- import 'package:vitalapp/components/dialog_date.dart';
- import 'package:vitalapp/components/dialog_time.dart';
- import 'package:vitalapp/pages/check/models/form.dart';
- import 'package:vitalapp/pages/form/form_info.dart';
- import 'exam_card.dart';
- class ExamDate extends StatefulWidget {
- final FormObject currentFormObject;
- final String? currentInputValue;
- const ExamDate({
- required this.currentFormObject,
- this.currentInputValue,
- });
- @override
- State<StatefulWidget> createState() {
- return ExamDateState();
- }
- }
- class ExamDateState extends State<ExamDate> {
- String _currentValue = '';
- bool _isDisabledValue = false;
- @override
- void initState() {
- _currentValue = widget.currentInputValue ?? '';
- 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) {
- 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: Text(
- _currentValue,
- style: TextStyle(
- fontSize: 26,
- color: Colors.black,
- fontFamily: "NotoSansSC",
- fontFamilyFallback: const ["NotoSansSC"],
- ),
- ),
- ),
- );
- }
- Future<void> _clickCard() async {
- if (_isDisabledValue) {
- return;
- }
- DateTime now = DateTime.now();
- DateTime? result;
- DateTime initialDate = now;
- if (_currentValue.isNotNullOrEmpty) {
- initialDate = DateTime.parse(_currentValue);
- }
- if (kIsWeb) {
- result = await showDatePicker(
- context: Get.context!,
- initialDate: initialDate,
- firstDate: DateTime(1900),
- lastDate: DateTime(2100),
- );
- } else {
- result = await VDialogDate(
- minimumDate: DateTime(1900),
- initialValue: initialDate,
- ).show();
- }
- if (result != null) {
- final DateFormat formatter = DateFormat('yyyy-MM-dd');
- var value = formatter.format(result);
- setState(() {
- _currentValue = value;
- });
- FormInfo.instance.formValue[widget.currentFormObject.key!] = value;
- FormInfo.instance.onValueChange.emit(
- this,
- UpdateFormArgs(
- sourceKey: widget.currentFormObject.key ?? '',
- sourceValue: value,
- ),
- );
- }
- }
- void _onChangeTargetValue(Object sender, TargetFormArgs e) {
- if (e.targetKey != widget.currentFormObject.key) {
- return;
- }
- if (e.isDisabledValue) {
- setState(() {
- _isDisabledValue = true;
- });
- } else if (!e.isDisabledValue) {
- setState(() {
- _isDisabledValue = false;
- });
- }
- setState(() {
- _currentValue = e.targetValue;
- });
- }
- }
|