import 'package:fis_jsonrpc/rpc.dart'; import 'package:fis_ui/index.dart'; import 'package:flutter/material.dart'; import 'package:get/get.dart'; import 'package:vitalapp/components/alert_dialog.dart'; import 'package:vitalapp/managers/interfaces/models/crowd_labels.dart'; class VDialogLabelSelect extends StatefulWidget { final List selectedLabels; final String title; final List allLabels; VDialogLabelSelect({ this.selectedLabels = const [], this.title = "人群分类", this.allLabels = const [], }); @override State createState() { return VDialogLabelSelectState(); } } class VDialogLabelSelectState extends State { final List _currentSelectedLabels = []; @override void initState() { for (var i in widget.selectedLabels) { _currentSelectedLabels.add(i); } super.initState(); } @override Widget build(BuildContext context) { return VAlertDialog( title: widget.title, width: 440, contentPadding: const EdgeInsets.symmetric(vertical: 12, horizontal: 24), content: _buildContent(context), showCancel: true, onConfirm: () { Get.back(result: _currentSelectedLabels); }, ); } Widget _buildContent(BuildContext context) { return Wrap( children: [ ...widget.allLabels.map( (e) => _buildLabel(e), ), ], ); } void selectRaidoChange(LabelDTO e) { var name = e.labelName!; if (_currentSelectedLabels.contains(name)) { _currentSelectedLabels.remove(name); } else { _currentSelectedLabels.add(name); } setState(() {}); } Widget _buildLabel(LabelDTO e) { return Container( padding: const EdgeInsets.all(7), child: InkWell( onTap: () => selectRaidoChange(e), borderRadius: BorderRadius.circular(50), child: Ink( decoration: BoxDecoration( border: Border.all( color: _currentSelectedLabels.contains(e.labelName) ? Colors.blue : Colors.black26, ), borderRadius: const BorderRadius.all( Radius.circular(50), ), color: _currentSelectedLabels.contains(e) ? Colors.blue : Colors.transparent, ), child: Container( padding: const EdgeInsets.all(15), alignment: Alignment.center, width: 200, child: FittedBox( child: Text( e.labelName ?? '', style: TextStyle( fontSize: 20, color: _currentSelectedLabels.contains(e) ? Colors.white : Colors.black54, ), ), ), ), ), ), ); } }