Skip to content

Commit

Permalink
Merge pull request doonfrs#99 from yeikel16/disable-row-checkbox-unde…
Browse files Browse the repository at this point in the history
…r-condition

feat: allow disable row checkbox under condition
  • Loading branch information
doonfrs authored Dec 14, 2024
2 parents 45d0925 + f3c055b commit 894ede9
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
9 changes: 6 additions & 3 deletions lib/src/model/pluto_column.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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;

Expand Down
19 changes: 17 additions & 2 deletions lib/src/ui/cells/pluto_default_cell.dart
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@ class _PlutoDefaultCellState extends PlutoStateWithChange<PlutoDefaultCell> {

@override
void updateState(PlutoNotifierEvent event) {
final disable =
widget.column.disableRowCheckboxWhen?.call(widget.row) ?? false;
if (disable) return;

_hasFocus = update<bool>(
_hasFocus,
stateManager.hasFocus,
Expand Down Expand Up @@ -354,19 +358,27 @@ class CheckboxSelectionWidgetState
bool _tristate = false;

bool? _checked;
bool _pureValue = false;

@override
PlutoGridStateManager get stateManager => widget.stateManager;

@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<bool>(
_tristate,
stateManager.enabledRowGroups && widget.row.type.isGroup,
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion lib/src/widgets/pluto_scaled_checkbox.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down

0 comments on commit 894ede9

Please sign in to comment.