@@ -338,12 +338,16 @@ class VirtualResultGrid extends material.StatefulWidget {
338338 required this .rows,
339339 this .stagingBuffer,
340340 this .onRowSelected,
341+ this .onSelectionValuesChanged,
342+ this .onCellFocused,
341343 });
342344
343345 final List <String > columns;
344346 final List <List <String >> rows;
345347 final DataGridStagingBuffer ? stagingBuffer;
346348 final material.ValueChanged <int ?>? onRowSelected;
349+ final material.ValueChanged <List <String >>? onSelectionValuesChanged;
350+ final void Function (String columnName, String cellValue, int rowIndex)? onCellFocused;
347351
348352 @override
349353 material.State <VirtualResultGrid > createState () => _VirtualResultGridState ();
@@ -446,6 +450,7 @@ class _VirtualResultGridState extends material.State<VirtualResultGrid> {
446450 bool moveNextCol = false ,
447451 bool movePrevCol = false ,
448452 bool moveNextRow = false ,
453+ bool movePrevRow = false ,
449454 }) {
450455 if (widget.stagingBuffer != null ) {
451456 widget.stagingBuffer! .setCell (row, column, value);
@@ -503,6 +508,18 @@ class _VirtualResultGridState extends material.State<VirtualResultGrid> {
503508 } else {
504509 _editingCell = null ;
505510 }
511+ } else if (movePrevRow) {
512+ if (row > 0 ) {
513+ _editingCell = ResultGridCellCoordinate (row - 1 , column);
514+ _selection = ResultGridSelection (
515+ startRow: row - 1 ,
516+ startColumn: column,
517+ endRow: row - 1 ,
518+ endColumn: column,
519+ );
520+ } else {
521+ _editingCell = null ;
522+ }
506523 } else {
507524 _editingCell = null ;
508525 }
@@ -585,6 +602,38 @@ class _VirtualResultGridState extends material.State<VirtualResultGrid> {
585602 }
586603 }
587604
605+ void _notifySelectionAndFocus () {
606+ if (widget.onSelectionValuesChanged != null ) {
607+ if (_selection == null ) {
608+ widget.onSelectionValuesChanged !(const []);
609+ } else {
610+ final rows = _sortedRows;
611+ final values = < String > [];
612+ for (var r = _selection! .startRow; r <= _selection! .endRow; r++ ) {
613+ if (r >= 0 && r < rows.length) {
614+ for (var c = _selection! .startColumn; c <= _selection! .endColumn; c++ ) {
615+ if (c >= 0 && c < rows[r].length) {
616+ values.add (rows[r][c]);
617+ }
618+ }
619+ }
620+ }
621+ widget.onSelectionValuesChanged !(values);
622+ }
623+ }
624+
625+ if (widget.onCellFocused != null && _selectionAnchor != null ) {
626+ final r = _selectionAnchor! .row;
627+ final c = _selectionAnchor! .column;
628+ final rows = _sortedRows;
629+ if (r >= 0 && r < rows.length && c >= 0 && c < widget.columns.length) {
630+ final colName = widget.columns[c];
631+ final val = c < rows[r].length ? rows[r][c] : '' ;
632+ widget.onCellFocused !(colName, val, r);
633+ }
634+ }
635+ }
636+
588637 void _onCellTap (int row, int column, {bool isShift = false }) {
589638 _focusNode.requestFocus ();
590639 widget.onRowSelected? .call (row);
@@ -605,6 +654,7 @@ class _VirtualResultGridState extends material.State<VirtualResultGrid> {
605654 );
606655 }
607656 });
657+ _notifySelectionAndFocus ();
608658 }
609659
610660 void _onCellSecondaryTap (int row, int column) {
@@ -622,6 +672,7 @@ class _VirtualResultGridState extends material.State<VirtualResultGrid> {
622672 endColumn: column,
623673 );
624674 });
675+ _notifySelectionAndFocus ();
625676 _copySelection ();
626677 }
627678 }
@@ -1078,6 +1129,7 @@ class _DataRow extends material.StatelessWidget {
10781129 bool moveNextCol,
10791130 bool movePrevCol,
10801131 bool moveNextRow,
1132+ bool movePrevRow,
10811133 })? onCommitEdit;
10821134 final material.VoidCallback ? onCancelEdit;
10831135 final void Function (int row, int col)? onOpenInspector;
@@ -1181,6 +1233,7 @@ class _GridCell extends material.StatelessWidget {
11811233 bool moveNextCol,
11821234 bool movePrevCol,
11831235 bool moveNextRow,
1236+ bool movePrevRow,
11841237 })? onCommitEdit;
11851238 final material.VoidCallback ? onCancelEdit;
11861239 final void Function (int row, int col)? onOpenInspector;
@@ -1192,14 +1245,15 @@ class _GridCell extends material.StatelessWidget {
11921245 initialValue: text,
11931246 width: width,
11941247 height: double .infinity,
1195- onCommit: (val, {moveNextCol = false , movePrevCol = false , moveNextRow = false }) {
1248+ onCommit: (val, {moveNextCol = false , movePrevCol = false , moveNextRow = false , movePrevRow = false }) {
11961249 onCommitEdit? .call (
11971250 row,
11981251 column,
11991252 val,
12001253 moveNextCol: moveNextCol,
12011254 movePrevCol: movePrevCol,
12021255 moveNextRow: moveNextRow,
1256+ movePrevRow: movePrevRow,
12031257 );
12041258 },
12051259 onCancel: () => onCancelEdit? .call (),
0 commit comments