Skip to content

Commit

Permalink
Add callback to row checks
Browse files Browse the repository at this point in the history
  • Loading branch information
MrCasCode committed May 26, 2021
1 parent b6b0177 commit 3e1e744
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 0 deletions.
2 changes: 2 additions & 0 deletions lib/src/manager/pluto_grid_state_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ class PlutoGridStateManager extends PlutoGridState {
PlutoGridMode? mode,
PlutoOnChangedEventCallback? onChangedEventCallback,
PlutoOnSelectedEventCallback? onSelectedEventCallback,
PlutoOnRowCheckedEventCallback? onRowCheckedEventCallback,
CreateHeaderCallBack? createHeader,
CreateFooterCallBack? createFooter,
PlutoGridConfiguration? configuration,
Expand All @@ -66,6 +67,7 @@ class PlutoGridStateManager extends PlutoGridState {
setGridMode(mode);
setOnChanged(onChangedEventCallback);
setOnSelected(onSelectedEventCallback);
setOnRowChecked(onRowCheckedEventCallback);
setCreateHeader(createHeader);
setCreateFooter(createFooter);
setConfiguration(configuration);
Expand Down
8 changes: 8 additions & 0 deletions lib/src/manager/state/grid_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ mixin GridState implements IPlutoGridState {

PlutoOnSelectedEventCallback? _onSelected;

PlutoOnRowCheckedEventCallback? get onRowChecked => _onRowChecked;

PlutoOnRowCheckedEventCallback? _onRowChecked;

CreateHeaderCallBack? get createHeader => _createHeader;

CreateHeaderCallBack? _createHeader;
Expand Down Expand Up @@ -108,6 +112,10 @@ mixin GridState implements IPlutoGridState {
_onSelected = onSelected;
}

void setOnRowChecked(PlutoOnRowCheckedEventCallback? onRowChecked) {
_onRowChecked = onRowChecked;
}

void setCreateHeader(CreateHeaderCallBack? createHeader) {
_createHeader = createHeader;
}
Expand Down
17 changes: 17 additions & 0 deletions lib/src/pluto_grid.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@ typedef PlutoOnChangedEventCallback = void Function(
typedef PlutoOnSelectedEventCallback = void Function(
PlutoGridOnSelectedEvent event);

typedef PlutoOnRowCheckedEventCallback = void Function(
PlutoGridOnRowCheckedEvent event);

typedef CreateHeaderCallBack = Widget Function(
PlutoGridStateManager stateManager);

Expand All @@ -28,6 +31,8 @@ class PlutoGrid extends StatefulWidget {

final PlutoOnSelectedEventCallback? onSelected;

final PlutoOnRowCheckedEventCallback? onRowChecked;

final CreateHeaderCallBack? createHeader;

final CreateFooterCallBack? createFooter;
Expand All @@ -49,6 +54,7 @@ class PlutoGrid extends StatefulWidget {
this.onLoaded,
this.onChanged,
this.onSelected,
this.onRowChecked,
this.createHeader,
this.createFooter,
this.configuration,
Expand Down Expand Up @@ -130,6 +136,7 @@ class _PlutoGridState extends State<PlutoGrid> {
mode: widget.mode,
onChangedEventCallback: widget.onChanged,
onSelectedEventCallback: widget.onSelected,
onRowCheckedEventCallback: widget.onRowChecked,
createHeader: widget.createHeader,
createFooter: widget.createFooter,
configuration: widget.configuration,
Expand Down Expand Up @@ -464,6 +471,16 @@ class PlutoGridOnSelectedEvent {
});
}


class PlutoGridOnRowCheckedEvent {
final PlutoRow? row;
final bool? isChecked;

PlutoGridOnRowCheckedEvent({
this.row,
this.isChecked});
}

class PlutoGridSettings {
/// If there is a frozen column, the minimum width of the body
/// (if it is less than the value, the frozen column is released)
Expand Down
1 change: 1 addition & 0 deletions lib/src/ui/cells/pluto_default_cell.dart
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ class __CheckboxSelectionWidgetState
}

widget.stateManager.setRowChecked(widget.row, changed);
if (widget.stateManager.onRowChecked != null) widget.stateManager.onRowChecked!(PlutoGridOnRowCheckedEvent(row: widget.row, isChecked: changed));

setState(() {
checked = changed;
Expand Down

0 comments on commit 3e1e744

Please sign in to comment.