import 'package:fis_common/event/event_type.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:vitalapp/pages/check/examination/controller.dart'; import 'package:vitalapp/pages/check/models/form.dart'; // import 'package:vitalapp/pages/check/widgets/configurable_card.dart'; import 'package:vitalapp/pages/check/widgets/new_configurable_card.dart'; class ExaminationPage extends StatefulWidget { const ExaminationPage({ Key? key, required this.idCard, required this.onSubmitEvent, required this.physicalExamNumber, this.examData, }) : super(key: key); final FEventHandler onSubmitEvent; final String idCard; final String physicalExamNumber; final String? examData; @override State createState() => _ExaminationPageState(); } class _ExaminationPageState extends State { final controller = Get.find(); String _cardKey = "ZZYBZK"; FEventHandler onChangeCurrentKeyEvent = FEventHandler(); @override void initState() { onChangeCurrentKeyEvent.addListener(changeCurrentKeyEvent); super.initState(); } @override void dispose() { onChangeCurrentKeyEvent.removeListener(changeCurrentKeyEvent); super.dispose(); } @override Widget build(BuildContext context) { return Scaffold( backgroundColor: const Color.fromRGBO(238, 238, 238, 1), body: DefaultTextStyle( style: TextStyle( fontFamily: "NotoSansSC", fontFamilyFallback: const ["NotoSansSC"], fontSize: 20.0, color: Colors.black, ), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ Stack( children: [ _buildExamList(), ], ), Expanded( child: NewConfigurableCard( key: UniqueKey(), onSubmitEvent: widget.onSubmitEvent, onChangeCurrentKeyEvent: onChangeCurrentKeyEvent, cardKey: _cardKey, callBack: (key, templateCode, data, isMuanual) async { await controller.createOrUpdateExam( key, templateCode, data, isMuanual, ); return true; }, patientCode: widget.idCard, physicalExamNumber: widget.physicalExamNumber, ), ), ], ), )); } Widget _buildExamList() { return Container( margin: EdgeInsets.symmetric(horizontal: 16, vertical: 16), child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: controller.menuList .map( (e) => InkWell( onTap: () { widget.onSubmitEvent.emit(this, false); _cardKey = e.value; setState(() {}); }, child: Container( margin: EdgeInsets.all(8), padding: EdgeInsets.all(8), width: 200, decoration: BoxDecoration( color: _cardKey == e.value ? Colors.blue : Colors.white, borderRadius: BorderRadius.all( Radius.circular(8), ), ), child: Text( e.label, style: TextStyle( fontSize: 20, color: _cardKey == e.value ? Colors.white : Colors.black, ), ), ), ), ) .toList(), ), ); } void changeCurrentKeyEvent(sender, e) { if (e) { MenuItem? currentKey = controller.menuList .firstWhereOrNull((element) => element.value == _cardKey); if (currentKey != null) { int currentIndex = controller.menuList.indexOf(currentKey); if (currentIndex < controller.menuList.length - 1) { widget.onSubmitEvent.emit(this, false); _cardKey = controller.menuList[currentIndex + 1].value; setState(() {}); } } } } }