Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
35 commits
Select commit Hold shift + click to select a range
1391c72
feat: PlutoCellColorCallback implemented
ujwalbasnet1 Dec 26, 2023
96fa692
feat: columnColorCallback -> cellColorCallback
ujwalbasnet1 Dec 26, 2023
fb5b75f
feat: support null
ujwalbasnet1 Dec 26, 2023
17c87b3
Merge branch 'bosskmk:master' into master
ujwalbasnet1 Mar 25, 2024
ada9a36
feat: handle each change event
ujwalbasnet1 Apr 18, 2024
738c606
feat: add validator on textcell
ujwalbasnet1 May 3, 2024
8075763
fix: error border validator
ujwalbasnet1 May 3, 2024
8599976
feat: error validation on text cell implemented
ujwalbasnet1 May 3, 2024
ac2c9e5
feat: use error colorscheme
ujwalbasnet1 May 3, 2024
d9cd10c
feat: add cellInternalPadding
ujwalbasnet1 May 3, 2024
770ddd7
feat: changes
ujwalbasnet1 May 3, 2024
149ecd9
feat: validate on statemanager added
ujwalbasnet1 May 3, 2024
09bf435
feat: validate to return isValid
ujwalbasnet1 May 4, 2024
f0cc6f1
fix: init fixes
ujwalbasnet1 May 4, 2024
e591386
fix: init fixes
ujwalbasnet1 May 4, 2024
7bca516
fix: unvalid -> valid changes
ujwalbasnet1 May 4, 2024
0adc7aa
fix: ignore hidden column
ujwalbasnet1 May 4, 2024
8e6504b
feat: force cell update onSubmit
ujwalbasnet1 May 7, 2024
e16b779
feat: support for body padding
ujwalbasnet1 Jun 1, 2024
cd784ae
Update pubspec.yaml
RamKoirala1123 Dec 12, 2024
6c4b8ab
feat: header and footer support in export pdf
RamKoirala1123 Dec 12, 2024
2840ccf
fix: header and footer support
RamKoirala1123 Dec 12, 2024
b3f81ee
fix: import issue
RamKoirala1123 Dec 12, 2024
5f793a0
added filter
RamKoirala1123 Feb 6, 2025
33b88b6
added filter
RamKoirala1123 Feb 6, 2025
fd0fc18
revert changes
RamKoirala1123 Feb 7, 2025
521d817
Merge pull request #1 from RamKoirala1123/master
ujwalbasnet1 Feb 7, 2025
e97e26b
support to change header style in pdf export
RamKoirala1123 Mar 3, 2025
93830f4
Update generic_pdf_controller.dart
RamKoirala1123 Mar 3, 2025
a0c1ee3
Update pluto_grid_pdf_export.dart
RamKoirala1123 Mar 3, 2025
d3011c6
Merge pull request #2 from RamKoirala1123/master
ujwalbasnet1 Mar 4, 2025
80de94e
Update pubspec.yaml
RamKoirala1123 Mar 18, 2025
7e362be
Merge pull request #3 from RamKoirala1123/patch-2
ujwalbasnet1 Mar 18, 2025
0c703a7
Update pubspec.yaml
RamKoirala1123 Jun 24, 2025
4303de5
Update pubspec.yaml
RamKoirala1123 Jun 24, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions lib/src/manager/pluto_grid_state_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ class PlutoGridStateChangeNotifier extends PlutoChangeNotifier
this.onRowsMoved,
this.onColumnsMoved,
this.rowColorCallback,
this.cellColorCallback,
this.createHeader,
this.createFooter,
PlutoColumnMenuDelegate? columnMenuDelegate,
Expand Down Expand Up @@ -142,6 +143,9 @@ class PlutoGridStateChangeNotifier extends PlutoChangeNotifier
@override
final PlutoRowColorCallback? rowColorCallback;

@override
final PlutoCellColorCallback? cellColorCallback;

@override
final CreateHeaderCallBack? createHeader;

Expand Down Expand Up @@ -223,6 +227,7 @@ class PlutoGridStateManager extends PlutoGridStateChangeNotifier {
super.onRowsMoved,
super.onColumnsMoved,
super.rowColorCallback,
super.cellColorCallback,
super.createHeader,
super.createFooter,
super.columnMenuDelegate,
Expand Down
2 changes: 2 additions & 0 deletions lib/src/manager/state/cell_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ abstract class ICellState {
/// currently selected cell.
PlutoCell? get currentCell;

PlutoCellColorCallback? get cellColorCallback;

/// The position index value of the currently selected cell.
PlutoGridCellPosition? get currentCellPosition;

Expand Down
32 changes: 24 additions & 8 deletions lib/src/manager/state/editing_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ abstract class IEditingState {
bool callOnChangedEvent = true,
bool force = false,
bool notify = true,
bool eachChange = false,
String? validationError,
});
}

Expand Down Expand Up @@ -212,6 +214,8 @@ mixin EditingState implements IPlutoGridState {
bool callOnChangedEvent = true,
bool force = false,
bool notify = true,
bool eachChange = false,
String? validationError,
}) {
final currentColumn = cell.column;

Expand Down Expand Up @@ -239,16 +243,28 @@ mixin EditingState implements IPlutoGridState {
currentRow.setState(PlutoRowState.updated);

cell.value = value;
cell.validationError = validationError;

if (callOnChangedEvent == true && onChanged != null) {
onChanged!(PlutoGridOnChangedEvent(
columnIdx: columnIndex(currentColumn)!,
column: currentColumn,
rowIdx: refRows.indexOf(currentRow),
row: currentRow,
value: value,
oldValue: oldValue,
));
onChanged!(
eachChange
? PlutoGridOnEachChangedEvent(
columnIdx: columnIndex(currentColumn)!,
column: currentColumn,
rowIdx: refRows.indexOf(currentRow),
row: currentRow,
value: value,
oldValue: oldValue,
)
: PlutoGridOnChangedEvent(
columnIdx: columnIndex(currentColumn)!,
column: currentColumn,
rowIdx: refRows.indexOf(currentRow),
row: currentRow,
value: value,
oldValue: oldValue,
),
);
}

notifyListeners(notify, changeCellValue.hashCode);
Expand Down
34 changes: 34 additions & 0 deletions lib/src/manager/state/layout_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,40 @@ mixin LayoutState implements IPlutoGridState {
notifyListeners(notify, setShowColumnFooter.hashCode);
}

bool validate({bool notify = true}) {
bool isValid = true;
for (var rowElement in refRows.originalList) {
for (var cellElement in rowElement.cells.values) {
if (cellElement.initialized) {
if (cellElement.column.validator != null &&
!cellElement.column.hide) {
final validationError = cellElement.column.validator?.call(
rowElement,
cellElement,
cellElement.value,
);

changeCellValue(
cellElement,
cellElement.value,
force: true,
eachChange: true,
callOnChangedEvent: true,
validationError: validationError,
);

if (validationError != null) {
isValid = false;
}
}
}
}
}

notifyListeners(notify, validate.hashCode);
return isValid;
}

@override
void setShowColumnFilter(bool flag, {bool notify = true}) {
if (showColumnFilter == flag) {
Expand Down
21 changes: 21 additions & 0 deletions lib/src/model/pluto_cell.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ class PlutoCell {

final Key _key;

String? _validationError;

dynamic _value;

dynamic _valueForSorting;
Expand Down Expand Up @@ -52,6 +54,18 @@ class PlutoCell {
return _value;
}

String? get validationError {
if (_needToApplyFormatOnInit) {
_applyFormatOnInit();
}

return _validationError;
}

bool get hasValidationError {
return validationError != null && validationError!.trim().isNotEmpty;
}

set value(dynamic changed) {
if (_value == changed) {
return;
Expand All @@ -62,6 +76,13 @@ class PlutoCell {
_valueForSorting = null;
}

set validationError(String? changed) {
if (_validationError == changed) {
return;
}
_validationError = changed;
}

dynamic get valueForSorting {
_valueForSorting ??= _getValueForSorting();

Expand Down
23 changes: 23 additions & 0 deletions lib/src/model/pluto_column.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import 'package:flutter/material.dart';
import 'package:pluto_grid/pluto_grid.dart';

typedef PlutoColumnValueFormatter = String Function(dynamic value);
typedef PlutoColumnValueValidator = String? Function(
PlutoRow row,
PlutoCell cell,
dynamic value,
);

typedef PlutoColumnRenderer = Widget Function(
PlutoColumnRendererContext rendererContext);
Expand All @@ -21,6 +26,10 @@ typedef PlutoColumnCheckReadOnly = bool Function(
);

class PlutoColumn {
bool? isFilterApplied;

Function()? onPressedFilter;

/// A title to be displayed on the screen.
/// If a titleSpan value is set, the title value is not displayed.
String title;
Expand Down Expand Up @@ -67,6 +76,9 @@ class PlutoColumn {
/// It takes precedence over defaultCellPadding in PlutoGridConfiguration.
EdgeInsets? cellPadding;

/// Customisable cellField padding.
EdgeInsets? cellInternalPadding;

/// Text alignment in Cell. (Left, Right, Center)
PlutoColumnTextAlign textAlign;

Expand Down Expand Up @@ -192,7 +204,15 @@ class PlutoColumn {
/// Hide the column.
bool hide;

/// Trigger [PlutoGridOnEachChangedEvent] for each character change
bool enablePlutoGridOnEachChangedEvent;

/// Field Validator for the column
PlutoColumnValueValidator? validator;

PlutoColumn({
this.isFilterApplied,
this.onPressedFilter,
required this.title,
required this.field,
required this.type,
Expand All @@ -204,6 +224,7 @@ class PlutoColumn {
this.filterPadding,
this.titleSpan,
this.cellPadding,
this.cellInternalPadding,
this.textAlign = PlutoColumnTextAlign.start,
this.titleTextAlign = PlutoColumnTextAlign.start,
this.frozen = PlutoColumnFrozen.none,
Expand All @@ -226,6 +247,8 @@ class PlutoColumn {
this.enableAutoEditing = false,
this.enableEditingMode = true,
this.hide = false,
this.enablePlutoGridOnEachChangedEvent = false,
this.validator,
}) : _key = UniqueKey(),
_checkReadOnly = checkReadOnly;

Expand Down
49 changes: 49 additions & 0 deletions lib/src/pluto_grid.dart
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ typedef CreateFooterCallBack = Widget Function(
typedef PlutoRowColorCallback = Color Function(
PlutoRowColorContext rowColorContext);

typedef PlutoCellColorCallback = Color? Function(
PlutoCellColorContext cellColorContext);

/// [PlutoGrid] is a widget that receives columns and rows and is expressed as a grid-type UI.
///
/// [PlutoGrid] supports movement and editing with the keyboard,
Expand Down Expand Up @@ -72,6 +75,7 @@ class PlutoGrid extends PlutoStatefulWidget {
this.createFooter,
this.noRowsWidget,
this.rowColorCallback,
this.cellColorCallback,
this.columnMenuDelegate,
this.configuration = const PlutoGridConfiguration(),
this.notifierFilterResolver,
Expand Down Expand Up @@ -291,6 +295,8 @@ class PlutoGrid extends PlutoStatefulWidget {
/// {@endtemplate}
final PlutoRowColorCallback? rowColorCallback;

final PlutoCellColorCallback? cellColorCallback;

/// {@template pluto_grid_property_columnMenuDelegate}
/// Column menu can be customized.
///
Expand Down Expand Up @@ -515,6 +521,7 @@ class PlutoGridState extends PlutoStateWithChange<PlutoGrid> {
onRowsMoved: widget.onRowsMoved,
onColumnsMoved: widget.onColumnsMoved,
rowColorCallback: widget.rowColorCallback,
cellColorCallback: widget.cellColorCallback,
createHeader: widget.createHeader,
createFooter: widget.createFooter,
columnMenuDelegate: widget.columnMenuDelegate,
Expand Down Expand Up @@ -1288,6 +1295,26 @@ class PlutoGridOnChangedEvent {
}
}

class PlutoGridOnEachChangedEvent extends PlutoGridOnChangedEvent {
const PlutoGridOnEachChangedEvent({
required super.columnIdx,
required super.column,
required super.rowIdx,
required super.row,
super.value,
super.oldValue,
});

@override
String toString() {
String out = '[PlutoGridOnEachChangedEvent] ';
out += 'ColumnIndex : $columnIdx, RowIndex : $rowIdx\n';
out += '::: oldValue : $oldValue\n';
out += '::: newValue : $value';
return out;
}
}

/// This is the argument value of the [PlutoGrid.onSelected] callback
/// that is called when the [PlutoGrid.mode] value is in select mode.
///
Expand Down Expand Up @@ -1470,6 +1497,28 @@ class PlutoRowColorContext {
});
}

/// Argument of [PlutoGrid.cellColorCallback] callback
/// to dynamically change the background color of a row.
class PlutoCellColorContext {
final PlutoColumn column;

final int rowIdx;

final PlutoRow row;

final PlutoCell cell;

final PlutoGridStateManager stateManager;

PlutoCellColorContext({
required this.column,
required this.rowIdx,
required this.row,
required this.cell,
required this.stateManager,
});
}

/// Extension class for [ScrollConfiguration.behavior] of [PlutoGrid].
class PlutoScrollBehavior extends MaterialScrollBehavior {
const PlutoScrollBehavior({
Expand Down
5 changes: 5 additions & 0 deletions lib/src/pluto_grid_configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,7 @@ class PlutoGridConfiguration {

class PlutoGridStyleConfig {
const PlutoGridStyleConfig({
this.bodyPadding = EdgeInsets.zero,
this.enableGridBorderShadow = false,
this.enableColumnBorderVertical = true,
this.enableColumnBorderHorizontal = true,
Expand Down Expand Up @@ -248,6 +249,7 @@ class PlutoGridStyleConfig {
});

const PlutoGridStyleConfig.dark({
this.bodyPadding = EdgeInsets.zero,
this.enableGridBorderShadow = false,
this.enableColumnBorderVertical = true,
this.enableColumnBorderHorizontal = true,
Expand Down Expand Up @@ -303,6 +305,9 @@ class PlutoGridStyleConfig {
this.gridPopupBorderRadius = BorderRadius.zero,
});

/// body padding
final EdgeInsets bodyPadding;

/// Enable borderShadow in [PlutoGrid].
final bool enableGridBorderShadow;

Expand Down
Loading