import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:vitalapp/components/cell.dart'; import 'package:vitalapp/components/dialog_input.dart'; import 'package:vitalapp/components/dialog_number.dart'; import 'package:vitalapp/pages/check/models/form.dart'; import 'alert_dialog.dart'; class VDialogGxyMedication extends StatefulWidget { final String? title; final String? description; final String? placeholder; final int? maxLines; final double? inputHeight; final bool Function(String)? onConfirmVerification; final bool showCancel; final MedicationModel? medicationModel; const VDialogGxyMedication({ Key? key, this.title, this.description, this.placeholder, this.maxLines = 1, this.inputHeight = 56, this.onConfirmVerification, this.showCancel = false, this.medicationModel, }) : super(key: key); Future show() => VAlertDialog.showDialog(this); @override _VDialogGxyMedicationState createState() => _VDialogGxyMedicationState(); } class _VDialogGxyMedicationState extends State { MedicationModel medicationModel = MedicationModel(); @override void initState() { super.initState(); if (widget.medicationModel != null) { medicationModel = widget.medicationModel!; } } @override Widget build(BuildContext context) { return VAlertDialog( title: "主要用药情况填写", width: 600, content: Container( height: 280, padding: const EdgeInsets.symmetric(horizontal: 24), alignment: Alignment.center, child: VListFormCellGroup( children: [ _buildFormCell( label: '药物名称', content: medicationModel.name, onTap: () async { final result = await _showInputDialog( title: '药物名称', initialValue: medicationModel.name ?? '', ); setState(() { medicationModel.name = result; }); }, ), _buildFormCell( label: '用法(每日次数)', content: medicationModel.usage, onTap: () async { final result = await _showNumberDialog( title: '用法(每日次数)', initialValue: medicationModel.usage ?? '', ); setState(() { medicationModel.usage = result; }); }, ), // _buildFormCell( // label: '频率:每日(月)', // content: medicationModel.monthOrDay, // onTap: () async { // String? result = await VDialogSelect( // source: [ // "每月", // "每日", // ], // labelGetter: (data) => data, // valueGetter: (data) => data, // ).show(); // setState(() { // medicationModel.monthOrDay = result; // }); // }, // ), _buildFormCell( label: '每次', content: medicationModel.dosages, onTap: () async { final result = await _showInputDialog( title: '每次', initialValue: medicationModel.dosages ?? '', ); setState(() { medicationModel.dosages = result; }); }, ), ], ), ), onConfirm: () { Get.back(result: medicationModel); }, ); } Future _showInputDialog({ required String title, required String initialValue, }) async { final result = await VDialogInput( title: title, initialValue: initialValue, ).show(); return result; } Future _showNumberDialog({ required String title, required String initialValue, }) async { final result = await VDialogNumber( title: title, initialValue: initialValue, ).show(); return result; } Widget _buildFormCell({ required String label, String? content, required VoidCallback onTap, }) { return VListFormCell( label: label, content: content ?? '', onTap: onTap, ); } }