crowd_select_label.dart 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. import 'package:fis_jsonrpc/rpc.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:get/get.dart';
  4. import 'package:vitalapp/pages/controllers/crowd_labels.dart';
  5. class CrowdSelectLabelView extends StatefulWidget {
  6. final CrowdLabelsController controller;
  7. const CrowdSelectLabelView({super.key, required this.controller});
  8. @override
  9. State<StatefulWidget> createState() => _CrowdSelectLabelState();
  10. }
  11. class _CrowdSelectLabelState extends State<CrowdSelectLabelView> {
  12. late CrowdLabelsController controller;
  13. @override
  14. void initState() {
  15. super.initState();
  16. controller = widget.controller;
  17. }
  18. @override
  19. Widget build(BuildContext context) {
  20. final state = controller.state;
  21. return Obx(() => Wrap(
  22. spacing: 16,
  23. runSpacing: 12,
  24. children: [
  25. buildItem(LabelDTO(code: "0", labelName: "全选"), context),
  26. ...state.normalOptions
  27. .where((element) => [
  28. "RQFL_ET",
  29. "RQFL_YF",
  30. "RQFL_LNR",
  31. ].contains(element.code))
  32. .map((LabelDTO e) => buildItem(e, context))
  33. .toList(),
  34. ...state.diseaseOptions
  35. .where((element) => [
  36. "CJJB_GXY",
  37. "CJJB_TNB",
  38. "CJJB_YZJSBZA",
  39. "CJJB_FJH",
  40. ].contains(element.code))
  41. .map((LabelDTO e) => buildItem(e, context))
  42. .toList(),
  43. ...state.specialCareOptions
  44. .where((element) => [].contains(element.code))
  45. .map((LabelDTO e) => buildItem(e, context))
  46. .toList(),
  47. ],
  48. ));
  49. }
  50. Widget buildItem(LabelDTO dto, BuildContext context) {
  51. return InkWell(
  52. child: VCheckBoxButton(
  53. key: GlobalKey(),
  54. label: dto.labelName ?? '',
  55. isChecked: controller.state.isAllSelect
  56. ? controller.state.isAllSelect
  57. : controller.state.selectedCodes.contains(dto.code),
  58. onChanged: (value) {
  59. controller.onItemCheckChanged(dto.code!);
  60. if (controller.state.selectedCodes.length == 7) {
  61. controller.state.isAllSelect = true;
  62. }
  63. setState(() {});
  64. },
  65. ),
  66. );
  67. }
  68. }
  69. /// 按钮式多选框
  70. class VCheckBoxButton extends StatefulWidget {
  71. /// 文本
  72. final String label;
  73. /// 是否默认选中
  74. final bool? isChecked;
  75. /// 选中状态变更
  76. final ValueChanged<bool>? onChanged;
  77. const VCheckBoxButton({
  78. super.key,
  79. required this.label,
  80. this.isChecked,
  81. this.onChanged,
  82. });
  83. @override
  84. State<StatefulWidget> createState() => _VCheckBoxState();
  85. }
  86. class _VCheckBoxState extends State<VCheckBoxButton> {
  87. bool _isChecked = false;
  88. @override
  89. void initState() {
  90. if (widget.isChecked != null) {
  91. _isChecked = widget.isChecked!;
  92. }
  93. super.initState();
  94. }
  95. @override
  96. Widget build(BuildContext context) {
  97. const height = 40.0;
  98. const borderRadius = height / 3;
  99. final primaryColor = Theme.of(context).primaryColor;
  100. return Material(
  101. child: Ink(
  102. child: InkWell(
  103. borderRadius: BorderRadius.circular(borderRadius),
  104. onTap: () {
  105. setState(() {
  106. _isChecked = !_isChecked;
  107. widget.onChanged?.call(_isChecked);
  108. });
  109. },
  110. child: IntrinsicWidth(
  111. child: Container(
  112. padding: const EdgeInsets.only(left: 10, right: 10),
  113. constraints: const BoxConstraints(minWidth: 150),
  114. alignment: Alignment.center,
  115. height: height,
  116. decoration: BoxDecoration(
  117. color: _isChecked ? primaryColor : Colors.white,
  118. borderRadius: BorderRadius.circular(borderRadius),
  119. border: _isChecked ? null : Border.all(color: primaryColor),
  120. ),
  121. child: Row(
  122. mainAxisSize: MainAxisSize.min,
  123. crossAxisAlignment: CrossAxisAlignment.center,
  124. children: [
  125. Text(
  126. widget.label,
  127. style: TextStyle(
  128. color: _isChecked ? Colors.white : primaryColor,
  129. fontSize: 16,
  130. ),
  131. ),
  132. ],
  133. ),
  134. ),
  135. ),
  136. ),
  137. ),
  138. );
  139. }
  140. }