You can listen for column move events with the PlutoGrid.onColumnsMoved callback.
However, there is no event for hiding a column, adding a column, or deleting a column.
I have attached the code below for these events.
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:pluto_grid/pluto_grid.dart';
import '../dummy_data/development.dart';
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<PlutoNotifierEvent> notifierEvent;
late final columnsNotifier = {
stateManager.moveColumn.hashCode,
stateManager.hideColumn.hashCode,
stateManager.hideColumns.hashCode,
stateManager.insertColumns.hashCode,
stateManager.removeColumns.hashCode,
stateManager.toggleFrozenColumn.hashCode,
};
@override
void initState() {
super.initState();
final dummyData = DummyData(10, 100);
columns = dummyData.columns;
rows = dummyData.rows;
}
@override
void dispose() {
notifierEvent.cancel();
super.dispose();
}
void _notifyListener(PlutoNotifierEvent event) {
if (event.notifier.firstWhere((e) => columnsNotifier.contains(e)) != -1) {
print('changed columns');
print(stateManager.columns.length);
print(stateManager.refColumns.originalList.length);
print(stateManager.leftFrozenColumns.length);
print(stateManager.bodyColumns.length);
print(stateManager.rightFrozenColumns.length);
print(stateManager.columnIndexesByShowFrozen);
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: Container(
padding: const EdgeInsets.all(15),
child: PlutoGrid(
columns: columns,
rows: rows,
onLoaded: (PlutoGridOnLoadedEvent event) {
stateManager = event.stateManager;
notifierEvent = stateManager.streamNotifier.stream.listen(
_notifyListener,
);
},
),
),
),
);
}
}
Terje
Developing for everything
The framework is truly awesome. Is it possible to have vertical borders on ColumnGroups and NOT on Columns? This is to visually distinguish groups from each other better. It would also, possibly, be a good thing to have the ability to change the background colors on columns/column groups as well as on rows.