123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110 |
- 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<String> selectedLabels;
- final String title;
- final List<LabelDTO> allLabels;
- VDialogLabelSelect({
- this.selectedLabels = const [],
- this.title = "人群分类",
- this.allLabels = const [],
- });
- @override
- State<StatefulWidget> createState() {
- return VDialogLabelSelectState();
- }
- }
- class VDialogLabelSelectState extends State<VDialogLabelSelect> {
- final List<String> _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,
- ),
- ),
- ),
- ),
- ),
- ),
- );
- }
- }
|