bosskmk / pluto_grid

PlutoGrid is a dataGrid for flutter that can be controlled by the keyboard on desktop and web. Of course, it works well on Android and IOS.

Home Page:https://pluto.weblaze.dev

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

After a Click hold and drag to select multiple rows

opened this issue · comments

After a Click hold and drag to select multiple rows, what event could be called to get the selected rows when mouse is released?

See the example below to get the rows being dragged.

class EmptyScreen extends StatefulWidget {
  static const routeName = 'empty';

  const EmptyScreen({Key? key}) : super(key: key);

  @override
  _EmptyScreenState createState() => _EmptyScreenState();
}

class _EmptyScreenState extends State<EmptyScreen> {
  late List<PlutoColumn> columns;

  late List<PlutoRow> rows;

  late PlutoGridStateManager stateManager;

  late StreamSubscription eventStream;

  @override
  void dispose() {
    eventStream.cancel();

    super.dispose();
  }

  @override
  void initState() {
    super.initState();

    columns = [
      PlutoColumn(
        title: 'column1',
        field: 'column1',
        type: PlutoColumnType.text(),
        enableRowDrag: true,
        renderer: (rendererContext) {
          return Text(
            rendererContext.cell.value,
            maxLines: 2,
          );
        },
      ),
      PlutoColumn(
        title: 'column2',
        field: 'column2',
        type: PlutoColumnType.number(),
        backgroundColor: Colors.blue,
      ),
      PlutoColumn(
        title: 'column3',
        field: 'column3',
        type: PlutoColumnType.number(),
      ),
    ];

    rows = DummyData.rowsByColumns(length: 30, columns: columns);
  }

  void streamListeners(PlutoGridEvent event) {
    if (event is PlutoGridDragRowsEvent) {
      print('dragging');
      print(event.targetIdx);
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        padding: const EdgeInsets.all(15),
        child: PlutoGrid(
          columns: columns,
          rows: rows,
          onChanged: (PlutoGridOnChangedEvent event) {
            print(event);
          },
          onLoaded: (PlutoGridOnLoadedEvent event) {
            stateManager = event.stateManager;

            stateManager.setSelectingMode(PlutoGridSelectingMode.row);

            eventStream = stateManager.eventManager!.listener(streamListeners);
          },
          configuration: const PlutoGridConfiguration(
            enterKeyAction: PlutoGridEnterKeyAction.editingAndMoveDown,
          ),
        ),
      ),
    );
  }
}

This issue is stale because it has been open for 30 days with no activity.

This issue was closed because it has been inactive for 14 days since being marked as stale.