diff --git a/lib/src/model/pluto_column.dart b/lib/src/model/pluto_column.dart index 5dc568165..d0cadebc6 100644 --- a/lib/src/model/pluto_column.dart +++ b/lib/src/model/pluto_column.dart @@ -147,9 +147,13 @@ class PlutoColumn { /// A checkbox appears in the cell of the column. bool enableRowChecked; - int rowCheckBoxGroupDepth; // + + int rowCheckBoxGroupDepth; + bool enableTitleChecked; + bool Function(PlutoRow row)? disableRowCheckboxWhen; + /// Sort rows by tapping on the column heading. bool enableSorting; @@ -258,8 +262,7 @@ class PlutoColumn { this.enableAutoEditing = false, this.enableEditingMode = true, this.hide = false, - this.backgroundGradient, - this.filterWidgetBuilder, + this.disableRowCheckboxWhen, }) : _key = UniqueKey(), _checkReadOnly = checkReadOnly; diff --git a/lib/src/ui/cells/pluto_default_cell.dart b/lib/src/ui/cells/pluto_default_cell.dart index d68b955fd..1d584edde 100644 --- a/lib/src/ui/cells/pluto_default_cell.dart +++ b/lib/src/ui/cells/pluto_default_cell.dart @@ -100,6 +100,10 @@ class _PlutoDefaultCellState extends PlutoStateWithChange { @override void updateState(PlutoNotifierEvent event) { + final disable = + widget.column.disableRowCheckboxWhen?.call(widget.row) ?? false; + if (disable) return; + _hasFocus = update( _hasFocus, stateManager.hasFocus, @@ -354,6 +358,7 @@ class CheckboxSelectionWidgetState bool _tristate = false; bool? _checked; + bool _pureValue = false; @override PlutoGridStateManager get stateManager => widget.stateManager; @@ -361,12 +366,19 @@ class CheckboxSelectionWidgetState @override void initState() { super.initState(); - updateState(PlutoNotifierEventForceUpdate.instance); + _pureValue = widget.row.checked ?? false; } @override void updateState(PlutoNotifierEvent event) { + final disable = + widget.column.disableRowCheckboxWhen?.call(widget.row) ?? false; + if (disable) { + _checked = _pureValue; + return; + } + _tristate = update( _tristate, stateManager.enabledRowGroups && widget.row.type.isGroup, @@ -410,9 +422,12 @@ class CheckboxSelectionWidgetState @override Widget build(BuildContext context) { + final disable = + widget.column.disableRowCheckboxWhen?.call(widget.row) ?? false; + return PlutoScaledCheckbox( value: _checked, - handleOnChanged: _handleOnChanged, + handleOnChanged: disable ? null : _handleOnChanged, tristate: _tristate, scale: 0.86, unselectedColor: stateManager.configuration.style.cellUnselectedColor, diff --git a/lib/src/widgets/pluto_scaled_checkbox.dart b/lib/src/widgets/pluto_scaled_checkbox.dart index e98308546..1c3b00362 100644 --- a/lib/src/widgets/pluto_scaled_checkbox.dart +++ b/lib/src/widgets/pluto_scaled_checkbox.dart @@ -3,7 +3,7 @@ import 'package:flutter/material.dart'; class PlutoScaledCheckbox extends StatelessWidget { final bool? value; - final Function(bool? changed) handleOnChanged; + final Function(bool? changed)? handleOnChanged; final bool tristate;