maxim-saplin / data_table_2

In-place substitute for Flutter's DataTable and PaginatedDataTable with fixed/sticky header and extra features
https://pub.dev/packages/data_table_2
BSD 3-Clause "New" or "Revised" License
202 stars 137 forks source link

FEATURE REQUEST (PaginatedDataTable2) - Enable to introduce display logic base on events, when Hover or LongPress #201

Closed wer-mathurin closed 1 year ago

wer-mathurin commented 1 year ago

The idea is to be able to show actions over a row like Gmail image

The idea is to have an API like this

final source = _Source();
PaginatedDataTable2(
    source:  source,
    onHover : (int row) => source.onHover(row),
)

With this we will be able to call something like this (not real code...but just to show the possibilities !!!

class _Source extends DataTableSource{
...

int? hoveredRow;
void onHover(int row) {
    hoveredRow = row;
    notifyListeners();
}

 @override
  DataRow? getRow(int index) {
   DataRow2.byIndex(
      index: index,
      cells: [
        for (var i = 0; i < columnsCount(); i++)
          DataCell(
            builder.call(data, i, index == hoveredRow),
          ),
      ],
    );
}
}

So the builder will be called and it can decided to draw actions base on the hovered flag :-)

wer-mathurin commented 1 year ago

This is a Workaround in the meantime. The UI will be updated when you will hover on different cells. But still think this can be more useful if this can be done on the Row level.

Using this resolve the issue when your mouse is over something render (so if the text is small, it will detect hover only on the Text.

DataCell(
            MouseRegion(
              onEnter: (event) {
                if (hoveredRow != index) {
                  hoveredRow = index;
                  notifyListeners();
                }
              },
              onExit: (event) {
                hoveredRow = null;
                notifyListeners();
              },
              child: builder.call(data, i, index == hoveredRow),
            ),
          ),
maxim-saplin commented 1 year ago

Do you have a working example? You can open a PR and try demonstrating the feature via /examples