Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add PlutoOnColMovedEvent and PlutoOnColWidthChangeEvent #532

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 17 additions & 3 deletions demo/lib/screen/feature/add_and_remove_column_row_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class _AddAndRemoveColumnRowScreenState
)),
TextSpan(text: 'Id'),
]),
enableInsertColumn: true,
),
PlutoColumn(
title: 'Name',
Expand Down Expand Up @@ -146,6 +147,22 @@ class _AddAndRemoveColumnRowScreenState
columns: columns,
rows: rows,
columnGroups: columnGroups,
onLoaded: (PlutoGridOnLoadedEvent event) {
stateManager = event.stateManager;
event.stateManager.eventManager!
.listener((PlutoGridEvent plutoEvent) {
if (plutoEvent is PlutoGridInsertColumnEvent) {
final columnIdx = plutoEvent.index;
stateManager.insertColumns(columnIdx, [
PlutoColumn(
title: 'New Column',
field: 'New Field ID{${stateManager.columnIndexes.length}}',
type: PlutoColumnType.text(),
)
]);
}
});
},
onChanged: (PlutoGridOnChangedEvent event) {
print(event);

Expand All @@ -155,9 +172,6 @@ class _AddAndRemoveColumnRowScreenState

stateManager.notifyListeners();
},
onLoaded: (PlutoGridOnLoadedEvent event) {
stateManager = event.stateManager;
},
createHeader: (stateManager) => _Header(stateManager: stateManager),
),
);
Expand Down
1 change: 1 addition & 0 deletions lib/pluto_grid.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export './src/manager/event/pluto_grid_drag_column_event.dart';
export './src/manager/event/pluto_grid_drag_rows_event.dart';
export './src/manager/event/pluto_grid_event.dart';
export './src/manager/event/pluto_grid_scroll_update_event.dart';
export './src/manager/event/pluto_grid_insert_column_event.dart';
export './src/manager/pluto_grid_event_manager.dart';
export './src/manager/pluto_grid_key_manager.dart';
export './src/manager/pluto_grid_state_manager.dart';
Expand Down
47 changes: 33 additions & 14 deletions lib/src/helper/show_column_menu.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,31 +54,23 @@ Future<PlutoGridColumnMenuItem?>? showColumnMenu({
position: RelativeRect.fromRect(
position & const Size(40, 40), Offset.zero & overlay.size),
items: [
if (column!.frozen.isFrozen == true)
if (column!.enableInsertColumn == true) ...[
_buildMenuItem(
value: PlutoGridColumnMenuItem.unfreeze,
value: PlutoGridColumnMenuItem.insertToLeft,
child: _buildTextItem(
text: localeText.unfreezeColumn,
text: localeText.insertToLeft,
textColor: textColor,
),
),
if (column.frozen.isFrozen != true) ...[
_buildMenuItem(
value: PlutoGridColumnMenuItem.freezeToLeft,
value: PlutoGridColumnMenuItem.insertToRight,
child: _buildTextItem(
text: localeText.freezeColumnToLeft,
textColor: textColor,
),
),
_buildMenuItem(
value: PlutoGridColumnMenuItem.freezeToRight,
child: _buildTextItem(
text: localeText.freezeColumnToRight,
text: localeText.insertToRight,
textColor: textColor,
),
),
const PopupMenuDivider(),
],
const PopupMenuDivider(),
_buildMenuItem(
value: PlutoGridColumnMenuItem.autoFit,
child: _buildTextItem(
Expand Down Expand Up @@ -123,12 +115,39 @@ Future<PlutoGridColumnMenuItem?>? showColumnMenu({
enabled: stateManager.hasFilter,
),
],
const PopupMenuDivider(),
if (column.frozen.isFrozen == true)
_buildMenuItem(
value: PlutoGridColumnMenuItem.unfreeze,
child: _buildTextItem(
text: localeText.unfreezeColumn,
textColor: textColor,
),
),
if (column.frozen.isFrozen != true) ...[
_buildMenuItem(
value: PlutoGridColumnMenuItem.freezeToLeft,
child: _buildTextItem(
text: localeText.freezeColumnToLeft,
textColor: textColor,
),
),
_buildMenuItem(
value: PlutoGridColumnMenuItem.freezeToRight,
child: _buildTextItem(
text: localeText.freezeColumnToRight,
textColor: textColor,
),
),
],
],
);
}

/// Items in the context menu on the right side of the column
enum PlutoGridColumnMenuItem {
insertToLeft,
insertToRight,
unfreeze,
freezeToLeft,
freezeToRight,
Expand Down
23 changes: 23 additions & 0 deletions lib/src/manager/event/pluto_grid_insert_column_event.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import 'package:pluto_grid/pluto_grid.dart';

class PlutoGridInsertColumnEvent extends PlutoGridEvent {
final int index;

PlutoGridInsertColumnEvent({
required this.index,
}) : super(
type: PlutoGridEventType.debounce,
duration: const Duration(milliseconds: debounceMilliseconds),
);

static const int debounceMilliseconds = 300;

static const int resumeMilliseconds = debounceMilliseconds + 100;

@override
void handler(PlutoGridStateManager? stateManager) async {
if (stateManager!.eventManager!.subscription.isPaused) {
return;
}
}
}
25 changes: 25 additions & 0 deletions lib/src/model/pluto_column.dart
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,30 @@ class PlutoColumn {
/// Entering the Enter key or tapping the cell enters the Editing mode.
bool? enableEditingMode;

/// You can insert columns on [PlutoGridInsertColumnEvent]
/// ```dart
/// PlutoGrid(
/// // ...
/// onLoaded: (PlutoGridOnLoadedEvent event) {
/// stateManager = event.stateManager;
/// event.stateManager.eventManager!
/// .listener((PlutoGridEvent plutoEvent) {
/// if (plutoEvent is PlutoGridInsertColumnEvent) {
/// final columnIdx = plutoEvent.index;
/// stateManager.insertColumns(columnIdx, [
/// PlutoColumn(
/// title: 'New Column',
/// field: 'New Field ID{${stateManager.columnIndexes.length}}',
/// type: PlutoColumnType.text(),
/// )
/// ]);
/// }
/// });
/// },
/// // ...
/// ```
bool enableInsertColumn;

/// Hide the column.
bool hide;

Expand Down Expand Up @@ -148,6 +172,7 @@ class PlutoColumn {
this.enableSetColumnsMenuItem = true,
this.enableAutoEditing = false,
this.enableEditingMode = true,
this.enableInsertColumn = false,
this.hide = false,
}) : _key = UniqueKey(),
_checkReadOnly = checkReadOnly;
Expand Down
18 changes: 18 additions & 0 deletions lib/src/pluto_grid_configuration.dart
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,8 @@ class PlutoGridConfiguration {

class PlutoGridLocaleText {
// Column menu
final String insertToLeft;
final String insertToRight;
final String unfreezeColumn;
final String freezeColumnToLeft;
final String freezeColumnToRight;
Expand Down Expand Up @@ -355,6 +357,8 @@ class PlutoGridLocaleText {

const PlutoGridLocaleText({
// Column menu
this.insertToLeft = 'Insert to left',
this.insertToRight = 'Insert to right',
this.unfreezeColumn = 'Unfreeze',
this.freezeColumnToLeft = 'Freeze to left',
this.freezeColumnToRight = 'Freeze to right',
Expand Down Expand Up @@ -395,6 +399,8 @@ class PlutoGridLocaleText {

const PlutoGridLocaleText.china({
// Column menu
this.insertToLeft = '向左插入列',
this.insertToRight = '向右插入列',
this.unfreezeColumn = '解冻',
this.freezeColumnToLeft = '冻结至左侧',
this.freezeColumnToRight = '冻结至右侧',
Expand Down Expand Up @@ -435,6 +441,8 @@ class PlutoGridLocaleText {

const PlutoGridLocaleText.korean({
// Column menu
this.insertToLeft = 'Insert to left',
this.insertToRight = 'Insert to right',
this.unfreezeColumn = '고정 해제',
this.freezeColumnToLeft = '왼쪽 고정',
this.freezeColumnToRight = '오른쪽 고정',
Expand Down Expand Up @@ -475,6 +483,8 @@ class PlutoGridLocaleText {

const PlutoGridLocaleText.russian({
// Column menu
this.insertToLeft = 'Insert to left',
this.insertToRight = 'Insert to right',
this.unfreezeColumn = 'Открепить',
this.freezeColumnToLeft = 'Закрепить слева',
this.freezeColumnToRight = 'Закрепить справа',
Expand Down Expand Up @@ -515,6 +525,8 @@ class PlutoGridLocaleText {

const PlutoGridLocaleText.czech({
// Column menu
this.insertToLeft = 'Insert to left',
this.insertToRight = 'Insert to right',
this.unfreezeColumn = 'Uvolnit',
this.freezeColumnToLeft = 'Ukotvit vlevo',
this.freezeColumnToRight = 'Ukotvit vpravo',
Expand Down Expand Up @@ -555,6 +567,8 @@ class PlutoGridLocaleText {

const PlutoGridLocaleText.brazilianPortuguese({
// Column menu
this.insertToLeft = 'Insert to left',
this.insertToRight = 'Insert to right',
this.unfreezeColumn = 'Descongelar',
this.freezeColumnToLeft = 'Congelar à esquerda',
this.freezeColumnToRight = 'Congelar à direita',
Expand Down Expand Up @@ -595,6 +609,8 @@ class PlutoGridLocaleText {

const PlutoGridLocaleText.spanish({
// Column menu
this.insertToLeft = 'Insert to left',
this.insertToRight = 'Insert to right',
this.unfreezeColumn = 'Descongelar',
this.freezeColumnToLeft = 'Congelar a la izquierda',
this.freezeColumnToRight = 'Congelar a la derecha',
Expand Down Expand Up @@ -635,6 +651,8 @@ class PlutoGridLocaleText {

const PlutoGridLocaleText.persian({
// Column menu
this.insertToLeft = 'Insert to left',
this.insertToRight = 'Insert to right',
this.unfreezeColumn = 'جدا کردن',
this.freezeColumnToLeft = 'چسباندن به چپ',
this.freezeColumnToRight = 'چسباندن به راست',
Expand Down
17 changes: 15 additions & 2 deletions lib/src/ui/columns/pluto_column_title.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,27 @@ class PlutoColumnTitleState extends State<PlutoColumnTitle> {
bool _isPointMoving = false;

void _showContextMenu(BuildContext context, Offset position) async {
final PlutoGridColumnMenuItem? selectedMenu = await showColumnMenu(
final PlutoGridColumnMenuItem? selectedMenu = (await showColumnMenu(
context: context,
position: position,
stateManager: widget.stateManager,
column: widget.column,
);
));
if (selectedMenu == null) return;

switch (selectedMenu) {
case PlutoGridColumnMenuItem.insertToLeft:
final columnIdx = selectedMenu.index;
widget.stateManager.eventManager?.addEvent(PlutoGridInsertColumnEvent(
index: columnIdx,
));
break;
case PlutoGridColumnMenuItem.insertToRight:
final columnIdx = selectedMenu.index + 1;
widget.stateManager.eventManager?.addEvent(PlutoGridInsertColumnEvent(
index: columnIdx,
));
break;
case PlutoGridColumnMenuItem.unfreeze:
widget.stateManager
.toggleFrozenColumn(widget.column.key, PlutoColumnFrozen.none);
Expand Down