dialog_label_select.dart 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. import 'package:fis_jsonrpc/rpc.dart';
  2. import 'package:fis_ui/index.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:get/get.dart';
  5. import 'package:vitalapp/components/alert_dialog.dart';
  6. import 'package:vitalapp/managers/interfaces/models/crowd_labels.dart';
  7. class VDialogLabelSelect extends StatefulWidget {
  8. final List<String> selectedLabels;
  9. final String title;
  10. final List<LabelDTO> allLabels;
  11. VDialogLabelSelect({
  12. this.selectedLabels = const [],
  13. this.title = "人群分类",
  14. this.allLabels = const [],
  15. });
  16. @override
  17. State<StatefulWidget> createState() {
  18. return VDialogLabelSelectState();
  19. }
  20. }
  21. class VDialogLabelSelectState extends State<VDialogLabelSelect> {
  22. final List<String> _currentSelectedLabels = [];
  23. @override
  24. void initState() {
  25. for (var i in widget.selectedLabels) {
  26. _currentSelectedLabels.add(i);
  27. }
  28. super.initState();
  29. }
  30. @override
  31. Widget build(BuildContext context) {
  32. return VAlertDialog(
  33. title: widget.title,
  34. width: 440,
  35. contentPadding: const EdgeInsets.symmetric(vertical: 12, horizontal: 24),
  36. content: _buildContent(context),
  37. showCancel: true,
  38. onConfirm: () {
  39. Get.back(result: _currentSelectedLabels);
  40. },
  41. );
  42. }
  43. Widget _buildContent(BuildContext context) {
  44. return Wrap(
  45. children: [
  46. ...widget.allLabels.map(
  47. (e) => _buildLabel(e),
  48. ),
  49. ],
  50. );
  51. }
  52. void selectRaidoChange(LabelDTO e) {
  53. var name = e.labelName!;
  54. if (_currentSelectedLabels.contains(name)) {
  55. _currentSelectedLabels.remove(name);
  56. } else {
  57. _currentSelectedLabels.add(name);
  58. }
  59. setState(() {});
  60. }
  61. Widget _buildLabel(LabelDTO e) {
  62. return Container(
  63. padding: const EdgeInsets.all(7),
  64. child: InkWell(
  65. onTap: () => selectRaidoChange(e),
  66. borderRadius: BorderRadius.circular(50),
  67. child: Ink(
  68. decoration: BoxDecoration(
  69. border: Border.all(
  70. color: _currentSelectedLabels.contains(e.labelName)
  71. ? Colors.blue
  72. : Colors.black26,
  73. ),
  74. borderRadius: const BorderRadius.all(
  75. Radius.circular(50),
  76. ),
  77. color: _currentSelectedLabels.contains(e)
  78. ? Colors.blue
  79. : Colors.transparent,
  80. ),
  81. child: Container(
  82. padding: const EdgeInsets.all(15),
  83. alignment: Alignment.center,
  84. width: 200,
  85. child: FittedBox(
  86. child: Text(
  87. e.labelName ?? '',
  88. style: TextStyle(
  89. fontSize: 20,
  90. color: _currentSelectedLabels.contains(e)
  91. ? Colors.white
  92. : Colors.black54,
  93. ),
  94. ),
  95. ),
  96. ),
  97. ),
  98. ),
  99. );
  100. }
  101. }