123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142 |
- import 'package:flutter/material.dart';
- import 'package:get/get.dart';
- import 'package:vitalapp/consts/styles.dart';
- import '../dynamic_drawer.dart';
- import 'group.dart';
- class VDrawerRadioCellGroup<T, TValue> extends StatefulWidget {
- final GlobalKey<ScaffoldState> scaffoldKey;
- final String? title;
- final List<RadioCellGroupItem<T>> source;
- /// 选项文本提取函数
- final String Function(T data) labelGetter;
- /// 选项值提取函数
- final TValue Function(T data) valueGetter;
- final VRadioCellGroupCheckChanged<T, TValue>? onChanged;
- final ValueChanged<TValue?>? onConfirm;
- const VDrawerRadioCellGroup({
- super.key,
- this.title,
- required this.source,
- required this.labelGetter,
- required this.valueGetter,
- this.onChanged,
- required this.scaffoldKey,
- this.onConfirm,
- });
- @override
- State<StatefulWidget> createState() => _DrawerGroupState<T, TValue>();
- }
- class _DrawerGroupState<T, TValue>
- extends State<VDrawerRadioCellGroup<T, TValue>> {
- final ScrollController _scrollController = ScrollController();
- @override
- Widget build(BuildContext context) {
- T? data = widget.source.firstWhereOrNull((e) => e.isChecked)?.data;
- TValue? radioValue;
- if (data != null) {
- radioValue = widget.valueGetter.call(data);
- }
- 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: VRadioCellGroup<T, TValue>(
- labelGetter: widget.labelGetter,
- controller: _scrollController,
- valueGetter: widget.valueGetter,
- source: widget.source,
- onChanged: (value, isChecked, data, checkedValue) {
- radioValue = checkedValue;
- widget.onChanged
- ?.call(value, isChecked, data, checkedValue);
- },
- isScrollable: true,
- ),
- ),
- ),
- Container(
- padding:
- const EdgeInsets.symmetric(horizontal: 18).copyWith(top: 8),
- alignment: Alignment.center,
- child: TextButton(
- onPressed: () {
- widget.onConfirm?.call(radioValue);
- VDynamicDrawerWrapper.hide(scaffoldKey: widget.scaffoldKey);
- },
- child: Container(
- width: double.infinity,
- height: 38,
- alignment: Alignment.center,
- child: const Text(
- "确定",
- style: TextStyle(fontSize: 20),
- ),
- ),
- ),
- ),
- ],
- ),
- ),
- );
- }
- }
|