import 'package:flutter/material.dart'; import 'package:vitalapp/consts/styles.dart'; import '../dynamic_drawer.dart'; import 'group.dart'; class VDrawerCheckBoxCellGroup extends StatefulWidget { final GlobalKey scaffoldKey; final String? title; final List> source; /// 选项文本提取函数 final String Function(T data) labelGetter; /// 选项值提取函数 final TValue Function(T data) valueGetter; final VCheckBoxCellGroupCheckChanged? onChanged; final ValueChanged>? onConfirm; const VDrawerCheckBoxCellGroup({ super.key, this.title, required this.source, required this.labelGetter, required this.valueGetter, this.onChanged, required this.scaffoldKey, this.onConfirm, }); @override State createState() => _DrawerGroupState(); } class _DrawerGroupState extends State> { final ScrollController _scrollController = ScrollController(); @override Widget build(BuildContext context) { List values = widget.source .where((e) => e.isChecked) .map((e) => widget.valueGetter.call(e.data)) .toList(); return Drawer( shadowColor: Colors.black.withOpacity(.1), backgroundColor: Colors.white, shape: RoundedRectangleBorder( borderRadius: GlobalStyles.borderRadius, ), elevation: 0, width: 520, child: Container( alignment: Alignment.topLeft, padding: const EdgeInsets.symmetric(vertical: 12), child: Column( mainAxisSize: MainAxisSize.min, children: [ Container( padding: const EdgeInsets.symmetric(horizontal: 18, vertical: 4), child: Row( mainAxisSize: MainAxisSize.max, mainAxisAlignment: MainAxisAlignment.spaceBetween, children: [ widget.title != null ? Text( widget.title!, style: const TextStyle( color: Colors.black, fontSize: 24, ), ) : const SizedBox(width: 1), IconButton( onPressed: () { VDynamicDrawerWrapper.hide( scaffoldKey: widget.scaffoldKey); }, icon: Icon( Icons.close, color: Colors.grey.shade600, size: 36, ), // style: ButtonStyle( // shape: MaterialStatePropertyAll( // RoundedRectangleBorder( // side: BorderSide(color: Colors.grey.shade600), // borderRadius: BorderRadius.circular(48), // ), // ), // ), ), ], ), ), Expanded( child: Scrollbar( thumbVisibility: true, controller: _scrollController, child: VCheckBoxCellGroup( labelGetter: widget.labelGetter, controller: _scrollController, valueGetter: widget.valueGetter, source: widget.source, onChanged: (value, isChecked, data, checkedValues) { values = checkedValues; widget.onChanged ?.call(value, isChecked, data, checkedValues); }, isScrollable: true, ), ), ), Container( padding: const EdgeInsets.symmetric(horizontal: 18).copyWith(top: 8), alignment: Alignment.center, child: TextButton( onPressed: () { widget.onConfirm?.call(values); VDynamicDrawerWrapper.hide(scaffoldKey: widget.scaffoldKey); }, child: Container( width: double.infinity, height: 38, alignment: Alignment.center, child: const Text( "确定", style: TextStyle(fontSize: 20), ), ), ), ), ], ), ), ); } }