diff --git a/demo/linux/flutter/ephemeral/.plugin_symlinks/url_launcher_linux b/demo/linux/flutter/ephemeral/.plugin_symlinks/url_launcher_linux index e433ea04f..0661b75a0 120000 --- a/demo/linux/flutter/ephemeral/.plugin_symlinks/url_launcher_linux +++ b/demo/linux/flutter/ephemeral/.plugin_symlinks/url_launcher_linux @@ -1 +1 @@ -C:/Users/manek/AppData/Local/Pub/Cache/hosted/pub.dev/url_launcher_linux-3.0.2/ \ No newline at end of file +/Users/milad/.pub-cache/hosted/pub.dev/url_launcher_linux-3.1.1/ \ No newline at end of file diff --git a/lib/src/helper/pluto_key_manager_event.dart b/lib/src/helper/pluto_key_manager_event.dart index 91267675c..28bd86ff7 100644 --- a/lib/src/helper/pluto_key_manager_event.dart +++ b/lib/src/helper/pluto_key_manager_event.dart @@ -1,9 +1,10 @@ + import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; class PlutoKeyManagerEvent { FocusNode focusNode; - RawKeyEvent event; + KeyEvent event; PlutoKeyManagerEvent({ required this.focusNode, @@ -12,9 +13,9 @@ class PlutoKeyManagerEvent { bool get needsThrottle => isMoving || isTab || isPageUp || isPageDown; - bool get isKeyDownEvent => event.runtimeType == RawKeyDownEvent; + bool get isKeyDownEvent => event is KeyDownEvent; - bool get isKeyUpEvent => event.runtimeType == RawKeyUpEvent; + bool get isKeyUpEvent => event is KeyUpEvent; bool get isMoving => isHorizontal || isVertical; @@ -94,15 +95,15 @@ class PlutoKeyManagerEvent { } bool get isShiftPressed { - return event.isShiftPressed; + return HardwareKeyboard.instance.isShiftPressed; } bool get isCtrlPressed { - return event.isMetaPressed || event.isControlPressed; + return HardwareKeyboard.instance.isMetaPressed || HardwareKeyboard.instance.isControlPressed; } bool get isAltPressed { - return event.isAltPressed; + return HardwareKeyboard.instance.isAltPressed; } bool get isModifierPressed { diff --git a/lib/src/manager/pluto_grid_key_manager.dart b/lib/src/manager/pluto_grid_key_manager.dart index ba952c790..52a6a2e79 100644 --- a/lib/src/manager/pluto_grid_key_manager.dart +++ b/lib/src/manager/pluto_grid_key_manager.dart @@ -79,7 +79,7 @@ class PlutoGridKeyManager { if (stateManager.configuration.shortcut.handle( keyEvent: keyEvent, stateManager: stateManager, - state: RawKeyboard.instance, + state: HardwareKeyboard.instance, )) { return; } diff --git a/lib/src/manager/shortcut/pluto_grid_shortcut.dart b/lib/src/manager/shortcut/pluto_grid_shortcut.dart index 57907ab4d..a4511413f 100644 --- a/lib/src/manager/shortcut/pluto_grid_shortcut.dart +++ b/lib/src/manager/shortcut/pluto_grid_shortcut.dart @@ -27,7 +27,7 @@ class PlutoGridShortcut { bool handle({ required PlutoKeyManagerEvent keyEvent, required PlutoGridStateManager stateManager, - required RawKeyboard state, + required HardwareKeyboard state, }) { for (final action in actions.entries) { if (action.key.accepts(keyEvent.event, state)) { diff --git a/lib/src/manager/shortcut/pluto_grid_shortcut_action.dart b/lib/src/manager/shortcut/pluto_grid_shortcut_action.dart index 26110d358..6889d9cab 100644 --- a/lib/src/manager/shortcut/pluto_grid_shortcut_action.dart +++ b/lib/src/manager/shortcut/pluto_grid_shortcut_action.dart @@ -250,7 +250,7 @@ class PlutoGridActionDefaultTab extends PlutoGridShortcutAction { final saveIsEditing = stateManager.isEditing; - keyEvent.event.isShiftPressed + keyEvent.isShiftPressed ? _moveCellPrevious(stateManager) : _moveCellNext(stateManager); @@ -408,7 +408,7 @@ class PlutoGridActionDefaultEnterKey extends PlutoGridShortcutAction { } if (enterKeyAction.isEditingAndMoveDown) { - if (keyEvent.event.isShiftPressed) { + if (keyEvent.isShiftPressed) { stateManager.moveCurrentCell( PlutoMoveDirection.up, notify: false, @@ -420,7 +420,7 @@ class PlutoGridActionDefaultEnterKey extends PlutoGridShortcutAction { ); } } else if (enterKeyAction.isEditingAndMoveRight) { - if (keyEvent.event.isShiftPressed) { + if (keyEvent.isShiftPressed) { stateManager.moveCurrentCell( PlutoMoveDirection.left, force: true, diff --git a/lib/src/manager/state/column_state.dart b/lib/src/manager/state/column_state.dart index 77109320d..3cf9348a1 100644 --- a/lib/src/manager/state/column_state.dart +++ b/lib/src/manager/state/column_state.dart @@ -1,7 +1,9 @@ import 'dart:collection'; +import 'dart:math' as math; import 'package:flutter/material.dart'; import 'package:pluto_grid/pluto_grid.dart'; +import 'package:pluto_grid/src/ui/cells/pluto_default_cell.dart'; abstract class IColumnState { /// Columns provided at grid start. @@ -304,12 +306,12 @@ mixin ColumnState implements IPlutoGridState { @override PlutoColumn? get currentColumn { - return currentCell == null ? null : currentCell!.column; + return currentCell?.column; } @override String? get currentColumnField { - return currentCell == null ? null : currentCell!.column.field; + return currentCell?.column.field; } @override @@ -571,47 +573,65 @@ mixin ColumnState implements IPlutoGridState { @override void autoFitColumn(BuildContext context, PlutoColumn column) { - final String maxValue = refRows.fold('', (previousValue, element) { - final value = column.formattedValueForDisplay( - element.cells.entries - .firstWhere((element) => element.key == column.field) - .value - .value, - ); + String maxValue = ''; + bool hasExpandableRowGroup = false; + for (final row in refRows) { + final cell = row.cells.entries.firstWhere((element) => element.key == column.field).value; + var value = column.formattedValueForDisplay(cell.value); + if (hasRowGroups) { + if (PlutoDefaultCell.showGroupCount(rowGroupDelegate!, cell)) { + final groupCountValue = PlutoDefaultCell.groupCountText(rowGroupDelegate!, row); + if (groupCountValue.isNotEmpty) { + value = '$value $groupCountValue'; + } + } - if (previousValue.length < value.length) { - return value; + hasExpandableRowGroup |= PlutoDefaultCell.canExpand(rowGroupDelegate!, cell); } - - return previousValue; - }); + if (maxValue.length < value.length) { + maxValue = value; + } + } // Get size after rendering virtually // https://stackoverflow.com/questions/54351655/flutter-textfield-width-should-match-width-of-contained-text - TextSpan textSpan = TextSpan( - style: DefaultTextStyle.of(context).style, - text: maxValue, - ); - - TextPainter textPainter = TextPainter( - text: textSpan, - textDirection: TextDirection.ltr, - ); - - textPainter.layout(); - - // todo : Apply (popup type icon, checkbox, drag indicator, renderer) + final titleTextWidth = _visualTextWidth(column.title, style.columnTextStyle); + final maxValueTextWidth = _visualTextWidth(maxValue, style.cellTextStyle); + + // todo : Handle (renderer) width + + final calculatedTileWidth = titleTextWidth - + column.width + + [ + (column.titlePadding ?? style.defaultColumnTitlePadding).horizontal, + if (column.enableRowChecked) _getEffectiveButtonWidth(context, checkBox: true), + if (column.isShowRightIcon) style.iconSize, + 8, + ].reduce((acc, a) => acc + a); + + final calculatedCellWidth = maxValueTextWidth - + column.width + + [ + (column.cellPadding ?? style.defaultCellPadding).horizontal, + if (hasExpandableRowGroup) _getEffectiveButtonWidth(context), + if (column.enableRowChecked) _getEffectiveButtonWidth(context, checkBox: true), + if (column.isShowRightIcon) style.iconSize, + 2, + ].reduce((acc, a) => acc + a); - EdgeInsets cellPadding = - column.cellPadding ?? configuration.style.defaultCellPadding; + resizeColumn(column, math.max(calculatedTileWidth, calculatedCellWidth)); + } - resizeColumn( - column, - textPainter.width - - column.width + - (cellPadding.left + cellPadding.right) + - 2, - ); + double _visualTextWidth(String text, TextStyle style) { + if (text.isEmpty) return 0; + final painter = TextPainter( + text: TextSpan( + style: style, + text: text, + ), + textDirection: isRTL ? TextDirection.rtl : TextDirection.ltr, + )..layout(); + return painter.width; } @override @@ -1019,9 +1039,7 @@ mixin ColumnState implements IPlutoGridState { return false; } - final columns = showFrozenColumn - ? leftFrozenColumns + bodyColumns + rightFrozenColumns - : refColumns; + final columns = showFrozenColumn ? leftFrozenColumns + bodyColumns + rightFrozenColumns : refColumns; final resizeHelper = getColumnsResizeHelper( columns: columns, @@ -1031,4 +1049,22 @@ mixin ColumnState implements IPlutoGridState { return resizeHelper.update(); } + + double _getEffectiveButtonWidth(BuildContext context, {bool checkBox = false}) { + final theme = Theme.of(context); + late double width; + switch (theme.materialTapTargetSize) { + case MaterialTapTargetSize.padded: + width = kMinInteractiveDimension; + break; + case MaterialTapTargetSize.shrinkWrap: + width = kMinInteractiveDimension - 8.0; + break; + } + if (!checkBox) { + return width; + } + return width + theme.visualDensity.baseSizeAdjustment.dx; + } } + diff --git a/lib/src/model/pluto_column_type.dart b/lib/src/model/pluto_column_type.dart index 12203c48b..c224692ea 100644 --- a/lib/src/model/pluto_column_type.dart +++ b/lib/src/model/pluto_column_type.dart @@ -224,11 +224,9 @@ extension PlutoColumnTypeExtension on PlutoColumnType { bool get hasFormat => this is PlutoColumnTypeHasFormat; - bool get applyFormatOnInit => - hasFormat ? (this as PlutoColumnTypeHasFormat).applyFormatOnInit : false; + bool get applyFormatOnInit => hasFormat ? (this as PlutoColumnTypeHasFormat).applyFormatOnInit : false; - dynamic applyFormat(dynamic value) => - hasFormat ? (this as PlutoColumnTypeHasFormat).applyFormat(value) : value; + dynamic applyFormat(dynamic value) => hasFormat ? (this as PlutoColumnTypeHasFormat).applyFormat(value) : value; } class PlutoColumnTypeText implements PlutoColumnType { @@ -351,8 +349,7 @@ class PlutoColumnTypeCurrency late final int decimalPoint; } -class PlutoColumnTypeSelect - implements PlutoColumnType, PlutoColumnTypeHasPopupIcon { +class PlutoColumnTypeSelect implements PlutoColumnType, PlutoColumnTypeHasPopupIcon { @override final dynamic defaultValue; @@ -386,6 +383,8 @@ class PlutoColumnTypeSelect } } + + class PlutoColumnTypeDate implements PlutoColumnType, @@ -477,8 +476,7 @@ class PlutoColumnTypeDate } } -class PlutoColumnTypeTime - implements PlutoColumnType, PlutoColumnTypeHasPopupIcon { +class PlutoColumnTypeTime implements PlutoColumnType, PlutoColumnTypeHasPopupIcon { @override final dynamic defaultValue; @@ -595,9 +593,7 @@ mixin PlutoColumnTypeWithNumberFormat { match += numberFormat.symbols.MINUS_SIGN; } - formatted = formatted - .replaceAll(RegExp('[^$match]'), '') - .replaceFirst(numberFormat.symbols.DECIMAL_SEP, '.'); + formatted = formatted.replaceAll(RegExp('[^$match]'), '').replaceFirst(numberFormat.symbols.DECIMAL_SEP, '.'); final num formattedNumber = num.tryParse(formatted) ?? 0; diff --git a/lib/src/pluto_grid.dart b/lib/src/pluto_grid.dart index 54d8e96ee..af5bbf916 100644 --- a/lib/src/pluto_grid.dart +++ b/lib/src/pluto_grid.dart @@ -593,7 +593,7 @@ class PlutoGridState extends PlutoStateWithChange { } } - KeyEventResult _handleGridFocusOnKey(FocusNode focusNode, RawKeyEvent event) { + KeyEventResult _handleGridFocusOnKey(FocusNode focusNode, KeyEvent event) { if (_keyManager.eventResult.isSkip == false) { _keyManager.subject.add(PlutoKeyManagerEvent( focusNode: focusNode, @@ -608,7 +608,7 @@ class PlutoGridState extends PlutoStateWithChange { Widget build(BuildContext context) { return FocusScope( onFocusChange: _stateManager.setKeepFocus, - onKey: _handleGridFocusOnKey, + onKeyEvent: _handleGridFocusOnKey, child: _GridContainer( stateManager: _stateManager, child: LayoutBuilder( diff --git a/lib/src/ui/cells/pluto_default_cell.dart b/lib/src/ui/cells/pluto_default_cell.dart index ed117d365..703bc3d0e 100644 --- a/lib/src/ui/cells/pluto_default_cell.dart +++ b/lib/src/ui/cells/pluto_default_cell.dart @@ -27,6 +27,35 @@ class PlutoDefaultCell extends PlutoStatefulWidget { @override State createState() => _PlutoDefaultCellState(); + + static String groupCountText(PlutoRowGroupDelegate delegate, PlutoRow row) { + final compactCount = delegate.enableCompactCount; + final count = compactCount + ? delegate.compactNumber(row.type.group.children.length) + : row.type.group.children.length.toString(); + return '($count)'; + } + + static TextStyle groupCountTextStyle(PlutoGridStyleConfig style) { + return style.cellTextStyle.copyWith( + decoration: TextDecoration.none, + fontWeight: FontWeight.normal, + ); + } + + static bool canExpand(PlutoRowGroupDelegate? delegate, PlutoCell cell) { + if(delegate == null) return false; + if (!cell.row.type.isGroup || !delegate.enabled) { + return false; + } + return delegate.isExpandableCell(cell); + } + + + static bool showGroupCount(PlutoRowGroupDelegate? delegate, PlutoCell cell) { + if(delegate == null) return false; + return delegate.enabled && delegate.isExpandableCell(cell) && cell.row.type.isGroup && delegate.showCount; + } } class _PlutoDefaultCellState extends PlutoStateWithChange { @@ -41,46 +70,20 @@ class _PlutoDefaultCellState extends PlutoStateWithChange { @override PlutoGridStateManager get stateManager => widget.stateManager; - bool get _canExpand { - if (!widget.row.type.isGroup || !stateManager.enabledRowGroups) { - return false; - } - - return _isExpandableCell; - } - - bool get _isExpandableCell => - stateManager.rowGroupDelegate!.isExpandableCell(widget.cell); - bool get _showSpacing { - if (!stateManager.enabledRowGroups || - !stateManager.rowGroupDelegate!.showFirstExpandableIcon) { + if (!stateManager.enabledRowGroups || !stateManager.rowGroupDelegate!.showFirstExpandableIcon) { return false; } - if (_canExpand) return true; + if (PlutoDefaultCell.canExpand(stateManager.rowGroupDelegate!, widget.cell)) return true; final parentCell = widget.row.parent?.cells[widget.column.field]; - return parentCell != null && - stateManager.rowGroupDelegate!.isExpandableCell(parentCell); + return parentCell != null && stateManager.rowGroupDelegate!.isExpandableCell(parentCell); } bool get _isEmptyGroup => widget.row.type.group.children.isEmpty; - bool get _showGroupCount => - stateManager.enabledRowGroups && - _isExpandableCell && - widget.row.type.isGroup && - stateManager.rowGroupDelegate!.showCount; - - String get _groupCount => _compactCount - ? stateManager.rowGroupDelegate! - .compactNumber(widget.row.type.group.children.length) - : widget.row.type.group.children.length.toString(); - - bool get _compactCount => stateManager.rowGroupDelegate!.enableCompactCount; - @override void initState() { super.initState(); @@ -116,7 +119,6 @@ class _PlutoDefaultCellState extends PlutoStateWithChange { rowGroup: widget.row, ); } - @override Widget build(BuildContext context) { final cellWidget = _DefaultCellWidget( @@ -140,7 +142,7 @@ class _PlutoDefaultCellState extends PlutoStateWithChange { } Widget? expandIcon; - if (_canExpand) { + if (PlutoDefaultCell.canExpand(stateManager.rowGroupDelegate, widget.cell)) { expandIcon = IconButton( onPressed: _isEmptyGroup ? null : _handleToggleExpandedRowGroup, icon: _isEmptyGroup @@ -187,13 +189,10 @@ class _PlutoDefaultCellState extends PlutoStateWithChange { if (spacingWidget != null) spacingWidget, if (expandIcon != null) expandIcon, Expanded(child: cellWidget), - if (_showGroupCount) + if (PlutoDefaultCell.showGroupCount(stateManager.rowGroupDelegate, widget.cell)) Text( - '($_groupCount)', - style: stateManager.configuration.style.cellTextStyle.copyWith( - decoration: TextDecoration.none, - fontWeight: FontWeight.normal, - ), + PlutoDefaultCell.groupCountText(stateManager.rowGroupDelegate!, widget.row), + style: PlutoDefaultCell.groupCountTextStyle(stateManager.style), ), ]); } @@ -332,8 +331,7 @@ class CheckboxSelectionWidget extends PlutoStatefulWidget { CheckboxSelectionWidgetState createState() => CheckboxSelectionWidgetState(); } -class CheckboxSelectionWidgetState - extends PlutoStateWithChange { +class CheckboxSelectionWidgetState extends PlutoStateWithChange { bool _tristate = false; bool? _checked; diff --git a/lib/src/ui/cells/popup_cell.dart b/lib/src/ui/cells/popup_cell.dart index e2e6149da..add9e380b 100644 --- a/lib/src/ui/cells/popup_cell.dart +++ b/lib/src/ui/cells/popup_cell.dart @@ -62,7 +62,7 @@ mixin PopupCellState on State ..text = widget.column.formattedValueForDisplayInEditing(widget.cell.value); - textFocus = FocusNode(onKey: _handleKeyboardFocusOnKey); + textFocus = FocusNode(onKeyEvent: _handleKeyboardFocusOnKey); } @override @@ -175,7 +175,7 @@ mixin PopupCellState on State } } - KeyEventResult _handleKeyboardFocusOnKey(FocusNode node, RawKeyEvent event) { + KeyEventResult _handleKeyboardFocusOnKey(FocusNode node, KeyEvent event) { var keyManager = PlutoKeyManagerEvent( focusNode: node, event: event, diff --git a/lib/src/ui/cells/text_cell.dart b/lib/src/ui/cells/text_cell.dart index b007e4f35..87834461d 100644 --- a/lib/src/ui/cells/text_cell.dart +++ b/lib/src/ui/cells/text_cell.dart @@ -52,7 +52,7 @@ mixin TextCellState on State implements TextFieldProps { void initState() { super.initState(); - cellFocus = FocusNode(onKey: _handleOnKey); + cellFocus = FocusNode(onKeyEvent: _handleOnKey); widget.stateManager.setTextEditingController(_textController); @@ -172,7 +172,7 @@ mixin TextCellState on State implements TextFieldProps { }); } - KeyEventResult _handleOnKey(FocusNode node, RawKeyEvent event) { + KeyEventResult _handleOnKey(FocusNode node, KeyEvent event) { var keyManager = PlutoKeyManagerEvent( focusNode: node, event: event, diff --git a/lib/src/ui/columns/pluto_column_filter.dart b/lib/src/ui/columns/pluto_column_filter.dart index da1749122..486785ece 100644 --- a/lib/src/ui/columns/pluto_column_filter.dart +++ b/lib/src/ui/columns/pluto_column_filter.dart @@ -83,7 +83,7 @@ class PlutoColumnFilterState extends PlutoStateWithChange { initState() { super.initState(); - _focusNode = FocusNode(onKey: _handleOnKey); + _focusNode = FocusNode(onKeyEvent: _handleOnKey); widget.column.setFilterFocusNode(_focusNode); @@ -145,7 +145,7 @@ class PlutoColumnFilterState extends PlutoStateWithChange { stateManager.notifyListeners(); } - KeyEventResult _handleOnKey(FocusNode node, RawKeyEvent event) { + KeyEventResult _handleOnKey(FocusNode node, KeyEvent event) { var keyManager = PlutoKeyManagerEvent( focusNode: node, event: event, diff --git a/lib/src/ui/columns/pluto_column_title.dart b/lib/src/ui/columns/pluto_column_title.dart index a9d46cd0f..17514e4a7 100644 --- a/lib/src/ui/columns/pluto_column_title.dart +++ b/lib/src/ui/columns/pluto_column_title.dart @@ -31,9 +31,7 @@ class PlutoColumnTitleState extends PlutoStateWithChange { PlutoColumnSort _sort = PlutoColumnSort.none; bool get showContextIcon { - return widget.column.enableContextMenu || - widget.column.enableDropToResize || - !_sort.isNone; + return widget.column.enableContextMenu || widget.column.enableDropToResize || !_sort.isNone; } bool get enableGesture { @@ -42,9 +40,7 @@ class PlutoColumnTitleState extends PlutoStateWithChange { MouseCursor get contextMenuCursor { if (enableGesture) { - return widget.column.enableDropToResize - ? SystemMouseCursors.resizeLeftRight - : SystemMouseCursors.click; + return widget.column.enableDropToResize ? SystemMouseCursors.resizeLeftRight : SystemMouseCursors.click; } return SystemMouseCursors.basic; @@ -98,8 +94,7 @@ class PlutoColumnTitleState extends PlutoStateWithChange { void _handleOnPointMove(PointerMoveEvent event) { // if at least one movement event has distanceSquared > 0.5 _isPointMoving will be true - _isPointMoving |= - (_columnRightPosition - event.position).distanceSquared > 0.5; + _isPointMoving |= (_columnRightPosition - event.position).distanceSquared > 0.5; if (!_isPointMoving) return; @@ -144,9 +139,7 @@ class PlutoColumnTitleState extends PlutoStateWithChange { icon: PlutoGridColumnIcon( sort: _sort, color: style.iconColor, - icon: widget.column.enableContextMenu - ? style.columnContextIcon - : style.columnResizeIcon, + icon: widget.column.enableContextMenu ? style.columnContextIcon : style.columnResizeIcon, ascendingIcon: style.columnAscendingIcon, descendingIcon: style.columnDescendingIcon, ), @@ -279,8 +272,7 @@ class _DraggableWidget extends StatelessWidget { alignment: column.titleTextAlign.alignmentValue, width: PlutoGridSettings.minColumnWidth, height: stateManager.columnHeight, - backgroundColor: - stateManager.configuration.style.gridBackgroundColor, + backgroundColor: stateManager.configuration.style.gridBackgroundColor, borderColor: stateManager.configuration.style.gridBorderColor, child: Text( column.title, @@ -346,26 +338,23 @@ class _ColumnWidget extends StatelessWidget { Key? key, }) : super(key: key); - EdgeInsets get padding => - column.titlePadding ?? - stateManager.configuration.style.defaultColumnTitlePadding; + EdgeInsets get padding => column.titlePadding ?? stateManager.configuration.style.defaultColumnTitlePadding; - bool get showSizedBoxForIcon => - column.isShowRightIcon && - (column.titleTextAlign.isRight || stateManager.isRTL); + bool get showSizedBoxForIcon => column.isShowRightIcon && (column.titleTextAlign.isRight || stateManager.isRTL); @override Widget build(BuildContext context) { return DragTarget( - onWillAccept: (PlutoColumn? columnToDrag) { - return columnToDrag != null && - columnToDrag.key != column.key && + onWillAcceptWithDetails: (details) { + final columnToDrag = details.data; + return columnToDrag.key != column.key && !stateManager.limitMoveColumn( column: columnToDrag, targetColumn: column, ); }, - onAccept: (PlutoColumn columnToMove) { + onAcceptWithDetails: (details) { + final columnToMove = details.data; if (columnToMove.key != column.key) { stateManager.moveColumn(column: columnToMove, targetColumn: column); } @@ -380,9 +369,7 @@ class _ColumnWidget extends StatelessWidget { height: height, child: DecoratedBox( decoration: BoxDecoration( - color: noDragTarget - ? column.backgroundColor - : style.dragTargetColumnColor, + color: noDragTarget ? column.backgroundColor : style.dragTargetColumnColor, border: BorderDirectional( end: style.enableColumnBorderVertical ? BorderSide(color: style.borderColor, width: 1.0) @@ -395,8 +382,7 @@ class _ColumnWidget extends StatelessWidget { alignment: Alignment.centerLeft, child: Row( children: [ - if (column.enableRowChecked) - CheckboxAllSelectionWidget(stateManager: stateManager), + if (column.enableRowChecked) CheckboxAllSelectionWidget(stateManager: stateManager), Expanded( child: _ColumnTextWidget( column: column, @@ -419,16 +405,13 @@ class _ColumnWidget extends StatelessWidget { class CheckboxAllSelectionWidget extends PlutoStatefulWidget { final PlutoGridStateManager stateManager; - const CheckboxAllSelectionWidget({required this.stateManager, Key? key}) - : super(key: key); + const CheckboxAllSelectionWidget({required this.stateManager, Key? key}) : super(key: key); @override - CheckboxAllSelectionWidgetState createState() => - CheckboxAllSelectionWidgetState(); + CheckboxAllSelectionWidgetState createState() => CheckboxAllSelectionWidgetState(); } -class CheckboxAllSelectionWidgetState - extends PlutoStateWithChange { +class CheckboxAllSelectionWidgetState extends PlutoStateWithChange { bool? _checked; @override @@ -531,8 +514,7 @@ class _ColumnTextWidgetState extends PlutoStateWithChange<_ColumnTextWidget> { ); } - String? get _title => - widget.column.titleSpan == null ? widget.column.title : null; + String? get _title => widget.column.titleSpan == null ? widget.column.title : null; List get _children => [ if (widget.column.titleSpan != null) widget.column.titleSpan!, @@ -547,8 +529,7 @@ class _ColumnTextWidgetState extends PlutoStateWithChange<_ColumnTextWidget> { ), onPressed: _handleOnPressedFilter, constraints: BoxConstraints( - maxHeight: - widget.height + (PlutoGridSettings.rowBorderWidth * 2), + maxHeight: widget.height + (PlutoGridSettings.rowBorderWidth * 2), ), ), ), diff --git a/lib/src/ui/pluto_base_row.dart b/lib/src/ui/pluto_base_row.dart index 598098294..4e0fc2a51 100644 --- a/lib/src/ui/pluto_base_row.dart +++ b/lib/src/ui/pluto_base_row.dart @@ -41,18 +41,14 @@ class PlutoBaseRow extends StatelessWidget { return true; } - bool _handleOnWillAccept(PlutoRow? draggingRow) { - if (draggingRow == null) { - return false; - } - - return !_checkSameDragRows(draggingRow); + bool _handleOnWillAccept(DragTargetDetails details) { + return !_checkSameDragRows(details.data); } - void _handleOnAccept(PlutoRow draggingRow) async { + void _handleOnAccept(DragTargetDetails details) async { final draggingRows = stateManager.currentSelectingRows.isNotEmpty ? stateManager.currentSelectingRows - : [draggingRow]; + : [details.data]; stateManager.eventManager!.addEvent( PlutoGridDragRowsEvent( @@ -111,8 +107,8 @@ class PlutoBaseRow extends StatelessWidget { @override Widget build(BuildContext context) { return DragTarget( - onWillAccept: _handleOnWillAccept, - onAccept: _handleOnAccept, + onWillAcceptWithDetails: _handleOnWillAccept, + onAcceptWithDetails: _handleOnAccept, builder: _dragTargetBuilder, ); } diff --git a/lib/src/ui/pluto_body_rows.dart b/lib/src/ui/pluto_body_rows.dart index fc37f7209..cac1049a2 100644 --- a/lib/src/ui/pluto_body_rows.dart +++ b/lib/src/ui/pluto_body_rows.dart @@ -1,3 +1,5 @@ +import 'dart:math'; + import 'package:flutter/material.dart'; import 'package:pluto_grid/pluto_grid.dart'; @@ -62,20 +64,19 @@ class PlutoBodyRowsState extends PlutoStateWithChange { } List _getColumns() { - return stateManager.showFrozenColumn == true - ? stateManager.bodyColumns - : stateManager.columns; + return stateManager.showFrozenColumn == true ? stateManager.bodyColumns : stateManager.columns; } @override Widget build(BuildContext context) { final scrollbarConfig = stateManager.configuration.scrollbar; - + final scrollbarMaxWidth = max( + scrollbarConfig.scrollbarThicknessWhileDragging, + scrollbarConfig.scrollbarThickness, + ); return PlutoScrollbar( - verticalController: - scrollbarConfig.draggableScrollbar ? _verticalScroll : null, - horizontalController: - scrollbarConfig.draggableScrollbar ? _horizontalScroll : null, + verticalController: scrollbarConfig.draggableScrollbar ? _verticalScroll : null, + horizontalController: scrollbarConfig.draggableScrollbar ? _horizontalScroll : null, isAlwaysShown: scrollbarConfig.isAlwaysShown, onlyDraggingThumb: scrollbarConfig.onlyDraggingThumb, enableHover: PlatformHelper.isDesktop, @@ -102,6 +103,10 @@ class PlutoBodyRowsState extends PlutoStateWithChange { physics: const ClampingScrollPhysics(), itemCount: _rows.length, itemExtent: stateManager.rowTotalHeight, + padding: EdgeInsetsDirectional.only( + bottom: scrollbarMaxWidth, + end: scrollbarMaxWidth, + ), addRepaintBoundaries: false, itemBuilder: (ctx, i) { return PlutoBaseRow( @@ -125,8 +130,7 @@ class ListResizeDelegate extends SingleChildLayoutDelegate { List columns; - ListResizeDelegate(this.stateManager, this.columns) - : super(relayout: stateManager.resizingChangeNotifier); + ListResizeDelegate(this.stateManager, this.columns) : super(relayout: stateManager.resizingChangeNotifier); @override bool shouldRelayout(covariant SingleChildLayoutDelegate oldDelegate) { @@ -134,8 +138,9 @@ class ListResizeDelegate extends SingleChildLayoutDelegate { } double _getWidth() { + final scrollbarConfig = stateManager.configuration.scrollbar; return columns.fold( - 0, + max(scrollbarConfig.scrollbarThickness, scrollbarConfig.scrollbarThicknessWhileDragging), (previousValue, element) => previousValue + element.width, ); } diff --git a/lib/src/ui/pluto_left_frozen_rows.dart b/lib/src/ui/pluto_left_frozen_rows.dart index 9cb6a0eb4..3dde04a89 100644 --- a/lib/src/ui/pluto_left_frozen_rows.dart +++ b/lib/src/ui/pluto_left_frozen_rows.dart @@ -1,3 +1,5 @@ +import 'dart:math'; + import 'package:flutter/material.dart'; import 'package:pluto_grid/pluto_grid.dart'; @@ -15,8 +17,7 @@ class PlutoLeftFrozenRows extends PlutoStatefulWidget { PlutoLeftFrozenRowsState createState() => PlutoLeftFrozenRowsState(); } -class PlutoLeftFrozenRowsState - extends PlutoStateWithChange { +class PlutoLeftFrozenRowsState extends PlutoStateWithChange { List _columns = []; List _rows = []; @@ -53,10 +54,17 @@ class PlutoLeftFrozenRowsState @override Widget build(BuildContext context) { + final scrollbarConfig = stateManager.configuration.scrollbar; return ListView.builder( controller: _scroll, scrollDirection: Axis.vertical, physics: const ClampingScrollPhysics(), + padding: EdgeInsets.only( + bottom: max( + scrollbarConfig.scrollbarThicknessWhileDragging, + scrollbarConfig.scrollbarThickness, + ), + ), itemCount: _rows.length, itemExtent: stateManager.rowTotalHeight, itemBuilder: (ctx, i) { diff --git a/lib/src/ui/pluto_right_frozen_rows.dart b/lib/src/ui/pluto_right_frozen_rows.dart index 90244f1af..ffa7a4817 100644 --- a/lib/src/ui/pluto_right_frozen_rows.dart +++ b/lib/src/ui/pluto_right_frozen_rows.dart @@ -1,3 +1,5 @@ +import 'dart:math'; + import 'package:flutter/material.dart'; import 'package:pluto_grid/pluto_grid.dart'; @@ -53,10 +55,17 @@ class PlutoRightFrozenRowsState @override Widget build(BuildContext context) { + final scrollbarConfig = stateManager.configuration.scrollbar; return ListView.builder( controller: _scroll, scrollDirection: Axis.vertical, physics: const ClampingScrollPhysics(), + padding: EdgeInsets.only( + bottom: max( + scrollbarConfig.scrollbarThicknessWhileDragging, + scrollbarConfig.scrollbarThickness, + ), + ), itemCount: _rows.length, itemExtent: stateManager.rowTotalHeight, itemBuilder: (ctx, i) { diff --git a/packages/pluto_grid_export/example/ios/Flutter/Debug.xcconfig b/packages/pluto_grid_export/example/ios/Flutter/Debug.xcconfig index 592ceee85..ec97fc6f3 100644 --- a/packages/pluto_grid_export/example/ios/Flutter/Debug.xcconfig +++ b/packages/pluto_grid_export/example/ios/Flutter/Debug.xcconfig @@ -1 +1,2 @@ +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" #include "Generated.xcconfig" diff --git a/packages/pluto_grid_export/example/ios/Flutter/Release.xcconfig b/packages/pluto_grid_export/example/ios/Flutter/Release.xcconfig index 592ceee85..c4855bfe2 100644 --- a/packages/pluto_grid_export/example/ios/Flutter/Release.xcconfig +++ b/packages/pluto_grid_export/example/ios/Flutter/Release.xcconfig @@ -1 +1,2 @@ +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" #include "Generated.xcconfig" diff --git a/packages/pluto_grid_export/example/macos/Flutter/Flutter-Debug.xcconfig b/packages/pluto_grid_export/example/macos/Flutter/Flutter-Debug.xcconfig index c2efd0b60..4b81f9b2d 100644 --- a/packages/pluto_grid_export/example/macos/Flutter/Flutter-Debug.xcconfig +++ b/packages/pluto_grid_export/example/macos/Flutter/Flutter-Debug.xcconfig @@ -1 +1,2 @@ +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" #include "ephemeral/Flutter-Generated.xcconfig" diff --git a/packages/pluto_grid_export/example/macos/Flutter/Flutter-Release.xcconfig b/packages/pluto_grid_export/example/macos/Flutter/Flutter-Release.xcconfig index c2efd0b60..5caa9d157 100644 --- a/packages/pluto_grid_export/example/macos/Flutter/Flutter-Release.xcconfig +++ b/packages/pluto_grid_export/example/macos/Flutter/Flutter-Release.xcconfig @@ -1 +1,2 @@ +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" #include "ephemeral/Flutter-Generated.xcconfig" diff --git a/packages/pluto_grid_export/example/macos/Flutter/GeneratedPluginRegistrant.swift b/packages/pluto_grid_export/example/macos/Flutter/GeneratedPluginRegistrant.swift index 416ef8457..9c4efdd9c 100644 --- a/packages/pluto_grid_export/example/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/packages/pluto_grid_export/example/macos/Flutter/GeneratedPluginRegistrant.swift @@ -6,7 +6,7 @@ import FlutterMacOS import Foundation import file_saver -import path_provider_macos +import path_provider_foundation import printing func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { diff --git a/packages/pluto_grid_export/lib/src/pdf/generic_pdf_controller.dart b/packages/pluto_grid_export/lib/src/pdf/generic_pdf_controller.dart index 82ea42a9c..4af78ab21 100644 --- a/packages/pluto_grid_export/lib/src/pdf/generic_pdf_controller.dart +++ b/packages/pluto_grid_export/lib/src/pdf/generic_pdf_controller.dart @@ -79,7 +79,7 @@ class GenericPdfController extends PdfController { } Widget _table(List columns, List> rows) { - return Table.fromTextArray( + return TableHelper.fromTextArray( border: null, cellAlignment: Alignment.center, // [Resolved 3.8.1] https://github.com/DavBfr/dart_pdf/pull/1033 to replace "headerDecoration" with "headerCellDecoration" diff --git a/test/src/helper/pluto_key_manager_event_test.dart b/test/src/helper/pluto_key_manager_event_test.dart index f0907a12d..b83925c95 100644 --- a/test/src/helper/pluto_key_manager_event_test.dart +++ b/test/src/helper/pluto_key_manager_event_test.dart @@ -8,7 +8,7 @@ void main() { late PlutoKeyManagerEvent? keyManagerEvent; - KeyEventResult callback(FocusNode node, RawKeyEvent event) { + KeyEventResult callback(FocusNode node, KeyEvent event) { keyManagerEvent = PlutoKeyManagerEvent( focusNode: node, event: event, @@ -28,12 +28,12 @@ void main() { Future buildWidget({ required WidgetTester tester, - required KeyEventResult Function(FocusNode, RawKeyEvent) callback, + required KeyEventResult Function(FocusNode, KeyEvent) callback, }) async { await tester.pumpWidget(MaterialApp( home: FocusScope( autofocus: true, - onKey: callback, + onKeyEvent: callback, child: Focus( focusNode: focusNode, child: const SizedBox(width: 100, height: 100), @@ -62,7 +62,7 @@ void main() { (tester) async { late PlutoKeyManagerEvent keyManagerEvent; - KeyEventResult callback(FocusNode node, RawKeyEvent event) { + KeyEventResult callback(FocusNode node, KeyEvent event) { keyManagerEvent = PlutoKeyManagerEvent( focusNode: node, event: event, diff --git a/test/src/manager/pluto_grid_key_manager_test.dart b/test/src/manager/pluto_grid_key_manager_test.dart index 57634f5e1..7e88553cd 100644 --- a/test/src/manager/pluto_grid_key_manager_test.dart +++ b/test/src/manager/pluto_grid_key_manager_test.dart @@ -46,8 +46,8 @@ void main() { await tester.pumpWidget( MaterialApp( home: Material( - child: RawKeyboardListener( - onKey: (event) { + child: KeyboardListener( + onKeyEvent: (event) { keyManager.subject.add(PlutoKeyManagerEvent( focusNode: FocusNode(), event: event, @@ -98,8 +98,8 @@ void main() { await tester.pumpWidget( MaterialApp( home: Material( - child: RawKeyboardListener( - onKey: (event) { + child: KeyboardListener( + onKeyEvent: (event) { keyManager.subject.add(PlutoKeyManagerEvent( focusNode: FocusNode(), event: event, @@ -150,8 +150,8 @@ void main() { await tester.pumpWidget( MaterialApp( home: Material( - child: RawKeyboardListener( - onKey: (event) { + child: KeyboardListener( + onKeyEvent: (event) { keyManager.subject.add(PlutoKeyManagerEvent( focusNode: FocusNode(), event: event, @@ -204,8 +204,8 @@ void main() { await tester.pumpWidget( MaterialApp( home: Material( - child: RawKeyboardListener( - onKey: (event) { + child: KeyboardListener( + onKeyEvent: (event) { keyManager.subject.add(PlutoKeyManagerEvent( focusNode: FocusNode(), event: event, @@ -258,8 +258,8 @@ void main() { await tester.pumpWidget( MaterialApp( home: Material( - child: RawKeyboardListener( - onKey: (event) { + child: KeyboardListener( + onKeyEvent: (event) { keyManager.subject.add(PlutoKeyManagerEvent( focusNode: FocusNode(), event: event, @@ -311,8 +311,8 @@ void main() { await tester.pumpWidget( MaterialApp( home: Material( - child: RawKeyboardListener( - onKey: (event) { + child: KeyboardListener( + onKeyEvent: (event) { keyManager.subject.add(PlutoKeyManagerEvent( focusNode: FocusNode(), event: event, @@ -440,8 +440,8 @@ void main() { await tester.pumpWidget( MaterialApp( home: Material( - child: RawKeyboardListener( - onKey: (event) { + child: KeyboardListener( + onKeyEvent: (event) { keyManager.subject.add(PlutoKeyManagerEvent( focusNode: FocusNode(), event: event,