import 'package:flutter/material.dart'; import 'package:get/get.dart'; import '../alert_dialog.dart'; import 'group.dart'; class VDialogCheckBoxCellGroup extends StatefulWidget { final String? title; final List> source; /// 选项文本提取函数 final String Function(T data) labelGetter; /// 选项值提取函数 final TValue Function(T data) valueGetter; final VCheckBoxCellGroupCheckChanged? onChanged; const VDialogCheckBoxCellGroup({ super.key, this.title, required this.source, required this.labelGetter, required this.valueGetter, this.onChanged, }); Future> show() async { final result = await VAlertDialog.showDialog>(this); return result!; } @override State createState() => _DialogGroupState(); } class _DialogGroupState extends State> { late List _values; @override void initState() { _values = widget.source .where((e) => e.isChecked) .map((e) => widget.valueGetter.call(e.data)) .toList(); super.initState(); } @override Widget build(BuildContext context) { return VAlertDialog( title: widget.title, // contentPadding: EdgeInsets.symmetric(horizontal: 20), content: Scrollbar( thumbVisibility: true, child: VCheckBoxCellGroup( labelGetter: widget.labelGetter, valueGetter: widget.valueGetter, source: widget.source, onChanged: (value, isChecked, data, checkedValues) { _values = checkedValues; widget.onChanged?.call(value, isChecked, data, checkedValues); }, isScrollable: true, ), ), onConfirm: () { Get.back(result: _values); }, ); } }