view.dart 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140
  1. import 'package:fis_common/event/event_type.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:get/get.dart';
  4. import 'package:vitalapp/pages/check/examination/controller.dart';
  5. import 'package:vitalapp/pages/check/models/form.dart';
  6. // import 'package:vitalapp/pages/check/widgets/configurable_card.dart';
  7. import 'package:vitalapp/pages/check/widgets/new_configurable_card.dart';
  8. class ExaminationPage extends StatefulWidget {
  9. const ExaminationPage({
  10. Key? key,
  11. required this.idCard,
  12. required this.onSubmitEvent,
  13. required this.physicalExamNumber,
  14. this.examData,
  15. }) : super(key: key);
  16. final FEventHandler<bool> onSubmitEvent;
  17. final String idCard;
  18. final String physicalExamNumber;
  19. final String? examData;
  20. @override
  21. State<ExaminationPage> createState() => _ExaminationPageState();
  22. }
  23. class _ExaminationPageState extends State<ExaminationPage> {
  24. final controller = Get.find<ExaminationController>();
  25. String _cardKey = "ZZYBZK";
  26. FEventHandler<bool> onChangeCurrentKeyEvent = FEventHandler<bool>();
  27. @override
  28. void initState() {
  29. onChangeCurrentKeyEvent.addListener(changeCurrentKeyEvent);
  30. super.initState();
  31. }
  32. @override
  33. void dispose() {
  34. onChangeCurrentKeyEvent.removeListener(changeCurrentKeyEvent);
  35. super.dispose();
  36. }
  37. @override
  38. Widget build(BuildContext context) {
  39. return Scaffold(
  40. backgroundColor: const Color.fromRGBO(238, 238, 238, 1),
  41. body: DefaultTextStyle(
  42. style: TextStyle(
  43. fontFamily: "NotoSansSC",
  44. fontFamilyFallback: const ["NotoSansSC"],
  45. fontSize: 20.0,
  46. color: Colors.black,
  47. ),
  48. child: Row(
  49. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  50. children: [
  51. Stack(
  52. children: [
  53. _buildExamList(),
  54. ],
  55. ),
  56. Expanded(
  57. child: NewConfigurableCard(
  58. key: UniqueKey(),
  59. onSubmitEvent: widget.onSubmitEvent,
  60. onChangeCurrentKeyEvent: onChangeCurrentKeyEvent,
  61. cardKey: _cardKey,
  62. callBack: (key, templateCode, data, isMuanual) async {
  63. await controller.createOrUpdateExam(
  64. key,
  65. templateCode,
  66. data,
  67. isMuanual,
  68. );
  69. return true;
  70. },
  71. patientCode: widget.idCard,
  72. physicalExamNumber: widget.physicalExamNumber,
  73. ),
  74. ),
  75. ],
  76. ),
  77. ));
  78. }
  79. Widget _buildExamList() {
  80. return Container(
  81. margin: EdgeInsets.symmetric(horizontal: 16, vertical: 16),
  82. child: Column(
  83. crossAxisAlignment: CrossAxisAlignment.start,
  84. children: controller.menuList
  85. .map(
  86. (e) => InkWell(
  87. onTap: () {
  88. widget.onSubmitEvent.emit(this, false);
  89. _cardKey = e.value;
  90. setState(() {});
  91. },
  92. child: Container(
  93. margin: EdgeInsets.all(8),
  94. padding: EdgeInsets.all(8),
  95. width: 200,
  96. decoration: BoxDecoration(
  97. color: _cardKey == e.value ? Colors.blue : Colors.white,
  98. borderRadius: BorderRadius.all(
  99. Radius.circular(8),
  100. ),
  101. ),
  102. child: Text(
  103. e.label,
  104. style: TextStyle(
  105. fontSize: 20,
  106. color: _cardKey == e.value ? Colors.white : Colors.black,
  107. ),
  108. ),
  109. ),
  110. ),
  111. )
  112. .toList(),
  113. ),
  114. );
  115. }
  116. void changeCurrentKeyEvent(sender, e) {
  117. if (e) {
  118. MenuItem? currentKey = controller.menuList
  119. .firstWhereOrNull((element) => element.value == _cardKey);
  120. if (currentKey != null) {
  121. int currentIndex = controller.menuList.indexOf(currentKey);
  122. if (currentIndex < controller.menuList.length - 1) {
  123. widget.onSubmitEvent.emit(this, false);
  124. _cardKey = controller.menuList[currentIndex + 1].value;
  125. setState(() {});
  126. }
  127. }
  128. }
  129. }
  130. }