123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153 |
- import 'package:fis_jsonrpc/rpc.dart';
- import 'package:flutter/material.dart';
- import 'package:get/get.dart';
- import 'package:vitalapp/pages/controllers/crowd_labels.dart';
- class CrowdSelectLabelView extends StatefulWidget {
- final CrowdLabelsController controller;
- const CrowdSelectLabelView({super.key, required this.controller});
- @override
- State<StatefulWidget> createState() => _CrowdSelectLabelState();
- }
- class _CrowdSelectLabelState extends State<CrowdSelectLabelView> {
- late CrowdLabelsController controller;
- @override
- void initState() {
- super.initState();
- controller = widget.controller;
- }
- @override
- Widget build(BuildContext context) {
- final state = controller.state;
- return Obx(() => Wrap(
- spacing: 16,
- runSpacing: 12,
- children: [
- buildItem(LabelDTO(code: "0", labelName: "全选"), context),
- ...state.normalOptions
- .where((element) => [
- "RQFL_ET",
- "RQFL_YF",
- "RQFL_LNR",
- ].contains(element.code))
- .map((LabelDTO e) => buildItem(e, context))
- .toList(),
- ...state.diseaseOptions
- .where((element) => [
- "CJJB_GXY",
- "CJJB_TNB",
- "CJJB_YZJSBZA",
- "CJJB_FJH",
- ].contains(element.code))
- .map((LabelDTO e) => buildItem(e, context))
- .toList(),
- ...state.specialCareOptions
- .where((element) => [].contains(element.code))
- .map((LabelDTO e) => buildItem(e, context))
- .toList(),
- ],
- ));
- }
- Widget buildItem(LabelDTO dto, BuildContext context) {
- return InkWell(
- child: VCheckBoxButton(
- key: GlobalKey(),
- label: dto.labelName ?? '',
- isChecked: controller.state.isAllSelect
- ? controller.state.isAllSelect
- : controller.state.selectedCodes.contains(dto.code),
- onChanged: (value) {
- controller.onItemCheckChanged(dto.code!);
- if (controller.state.selectedCodes.length == 7) {
- controller.state.isAllSelect = true;
- }
- setState(() {});
- },
- ),
- );
- }
- }
- class VCheckBoxButton extends StatefulWidget {
-
- final String label;
-
- final bool? isChecked;
-
- final ValueChanged<bool>? onChanged;
- const VCheckBoxButton({
- super.key,
- required this.label,
- this.isChecked,
- this.onChanged,
- });
- @override
- State<StatefulWidget> createState() => _VCheckBoxState();
- }
- class _VCheckBoxState extends State<VCheckBoxButton> {
- bool _isChecked = false;
- @override
- void initState() {
- if (widget.isChecked != null) {
- _isChecked = widget.isChecked!;
- }
- super.initState();
- }
- @override
- Widget build(BuildContext context) {
- const height = 40.0;
- const borderRadius = height / 3;
- final primaryColor = Theme.of(context).primaryColor;
- return Material(
- child: Ink(
- child: InkWell(
- borderRadius: BorderRadius.circular(borderRadius),
- onTap: () {
- setState(() {
- _isChecked = !_isChecked;
- widget.onChanged?.call(_isChecked);
- });
- },
- child: IntrinsicWidth(
- child: Container(
- padding: const EdgeInsets.only(left: 10, right: 10),
- constraints: const BoxConstraints(minWidth: 150),
- alignment: Alignment.center,
- height: height,
- decoration: BoxDecoration(
- color: _isChecked ? primaryColor : Colors.white,
- borderRadius: BorderRadius.circular(borderRadius),
- border: _isChecked ? null : Border.all(color: primaryColor),
- ),
- child: Row(
- mainAxisSize: MainAxisSize.min,
- crossAxisAlignment: CrossAxisAlignment.center,
- children: [
- Text(
- widget.label,
- style: TextStyle(
- color: _isChecked ? Colors.white : primaryColor,
- fontSize: 16,
- ),
- ),
- ],
- ),
- ),
- ),
- ),
- ),
- );
- }
- }
|