123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106 |
- import 'package:flutter/material.dart';
- typedef VCheckBoxCellChangeCallback<T> = void Function(
- T? value, bool isChecked);
- class VCheckBoxCell<T> extends StatefulWidget {
- final String label;
- final T? value;
- final bool isChecked;
- final bool isDisabled;
- final VCheckBoxCellChangeCallback<T>? onChanged;
- const VCheckBoxCell({
- super.key,
- required this.label,
- required this.value,
- required this.isChecked,
- required this.isDisabled,
- this.onChanged,
- });
- @override
- State<StatefulWidget> createState() => _VCheckBoxCellState<T>();
- }
- class _VCheckBoxCellState<T> extends State<VCheckBoxCell<T>> {
- static const _horizontalPadding = 24.0;
- late bool _isChecked;
- static const _height = 56.0;
- @override
- void initState() {
- _isChecked = widget.isChecked;
- super.initState();
- }
- @override
- Widget build(BuildContext context) {
- final iconWidget = _CheckStatusIcon(
- isChecked: _isChecked,
- isDisabled: widget.isDisabled,
- );
- final labelWidget = Text(
- widget.label,
- style: TextStyle(
- color: _isChecked ? Theme.of(context).primaryColor : Colors.black87,
- fontSize: 20,
- ),
- );
- return Material(
- child: Ink(
- child: InkWell(
- onTap: widget.isDisabled ? null : _onClick,
- child: Container(
- height: _height,
- padding: const EdgeInsets.symmetric(horizontal: _horizontalPadding),
- color: _isChecked ? Theme.of(context).secondaryHeaderColor : null,
- child: Row(
- mainAxisAlignment: MainAxisAlignment.spaceBetween,
- children: [
- labelWidget,
- iconWidget,
- ],
- ),
- ),
- ),
- ),
- );
- }
- void _onClick() {
- setState(() {
- _isChecked = !_isChecked;
- widget.onChanged?.call(widget.value, _isChecked);
- });
- }
- }
- class _CheckStatusIcon extends StatelessWidget {
- final bool isChecked;
- final bool isDisabled;
- const _CheckStatusIcon({
- super.key,
- required this.isChecked,
- required this.isDisabled,
- });
- @override
- Widget build(BuildContext context) {
- if (isChecked) {
- return Icon(
- Icons.check_outlined,
- color: Theme.of(context).primaryColor,
- size: 24,
- );
- } else {
- return const Icon(
- Icons.check_box_outline_blank_outlined,
- color: Colors.grey,
- size: 24,
- );
- }
- }
- }
|