import 'package:flutter/material.dart'; import 'package:vitalapp/components/dialog_input.dart'; import 'package:vitalapp/pages/check/widgets/exam_configurable/exam_card.dart'; /// 尿常规 class ExamUrinalysis extends StatefulWidget { const ExamUrinalysis({ super.key, required this.currentValue, required this.urinalysis, }); final Map currentValue; final Function(Map) urinalysis; @override State createState() => _ExamUrinalysisState(); } class _ExamUrinalysisState extends State { List> urinalysis = [ {"name": '尿白细胞', "key": 'LEU'}, {"name": '红细胞/潜血', "key": 'BLD'}, {"name": '尿亚硝酸盐', "key": 'NIT'}, {"name": '酮体', "key": 'KET'}, {"name": '尿胆原', "key": 'UBG'}, {"name": '胆红素', "key": 'BIL'}, {"name": '尿蛋白', "key": 'PRO'}, {"name": '葡萄糖', "key": 'GLU'}, {"name": '酸碱度', "key": 'PH'}, {"name": '尿比重', "key": 'SG'}, {"name": '维生素C', "key": 'VC'}, ]; Map _value = {}; @override void initState() { initData(); super.initState(); } @override void didUpdateWidget(ExamUrinalysis oldWidget) { initData(); super.didUpdateWidget(oldWidget); } void initData() { _value = widget.currentValue; setState(() {}); } @override void dispose() { super.dispose(); } @override Widget build(BuildContext context) { return Stack( children: [ _buildUrinalysis(), ], ); } Widget _buildUrinalysis() { return ExamCard( title: '尿常规', // clickCard: () { // _input(); // }, content: Container( width: double.infinity, alignment: Alignment.center, padding: const EdgeInsets.only( bottom: 20, right: 30, left: 40, ), // constraints: const BoxConstraints(minHeight: 50), child: GridView.count( shrinkWrap: true, childAspectRatio: 12, crossAxisCount: 2, // 列数为2,即两列布局 children: urinalysis.map((item) { return _buildUrineItem(item); }).toList(), ), ), ); } Widget _buildUrineItem(Map urine) { return InkWell( onTap: () { _input(urine['name']!, urine['key']!); }, child: Container( child: Row( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.center, children: [ Container( alignment: Alignment.center, width: 180, child: Row( children: [ Text( urine['key']!, style: const TextStyle( fontSize: 22, color: Colors.black, ), ), Text( '(${urine['name']!})', // text: _value.isEmpty ? '--' : _value, textAlign: TextAlign.center, style: const TextStyle( fontSize: 22, ), ), ], ), ), Text( _value[urine['key']!] ?? '', // text: _value.isEmpty ? '--' : _value, style: const TextStyle( fontSize: 26, ), ) ], ), ), ); } Future _input(String name, String key) async { String? result = await VDialogInput( title: name, initialValue: _value[key], ).show(); if (result?.isNotEmpty ?? false) { _value[key] = result ?? ''; } widget.urinalysis(_value); setState(() {}); } }