From e7579c976af901480c8aeb2bcea2ba37483c078d Mon Sep 17 00:00:00 2001 From: Jonathan Ma Date: Fri, 24 Mar 2023 10:54:31 -0400 Subject: [PATCH 1/3] add flag to vertically stack dual grid --- lib/src/pluto_dual_grid.dart | 120 +++++++++++++++++++++++++++++------ 1 file changed, 101 insertions(+), 19 deletions(-) diff --git a/lib/src/pluto_dual_grid.dart b/lib/src/pluto_dual_grid.dart index 167686ba1..3cdd3b2f5 100644 --- a/lib/src/pluto_dual_grid.dart +++ b/lib/src/pluto_dual_grid.dart @@ -47,6 +47,8 @@ class PlutoDualGrid extends StatefulWidget { final PlutoDualOnSelectedEventCallback? onSelected; + final bool? isVertical; + /// [PlutoDualGridDisplayRatio] /// Set the width of the two grids by specifying the ratio of the left grid. /// 0.5 is 5(left grid):5(right grid). @@ -67,6 +69,7 @@ class PlutoDualGrid extends StatefulWidget { this.mode = PlutoGridMode.normal, this.onSelected, this.display, + this.isVertical, this.divider = const PlutoDualGridDivider(), Key? key, }) : super(key: key); @@ -97,11 +100,14 @@ class PlutoDualGridState extends State { late final StreamSubscription _streamB; + late final bool isVertical; + @override void initState() { super.initState(); display = widget.display ?? PlutoDualGridDisplayRatio(); + isVertical = widget.isVertical ?? false; } @override @@ -209,6 +215,7 @@ class PlutoDualGridState extends State { display: display, showDraggableDivider: widget.divider.show, isLTR: isLTR, + isVertical: isVertical, ), children: [ _buildGrid( @@ -227,12 +234,19 @@ class PlutoDualGridState extends State { final RenderBox object = context.findRenderObject() as RenderBox; - display.offset = object - .globalToLocal(Offset( - details.globalPosition.dx, - details.globalPosition.dy, - )) - .dx; + display.offset = isVertical + ? object + .globalToLocal(Offset( + details.globalPosition.dx, + details.globalPosition.dy, + )) + .dy + : object + .globalToLocal(Offset( + details.globalPosition.dx, + details.globalPosition.dy, + )) + .dx; resizeNotifier.resize(); }, @@ -306,15 +320,24 @@ class PlutoDualGridDividerWidgetState onHorizontalDragStart: onHorizontalDragStart, onHorizontalDragUpdate: onHorizontalDragUpdate, onHorizontalDragEnd: onHorizontalDragEnd, + onVerticalDragStart: onHorizontalDragStart, + onVerticalDragUpdate: onHorizontalDragUpdate, + onVerticalDragEnd: onHorizontalDragEnd, child: ColoredBox( color: isDragging ? widget.draggingColor : widget.backgroundColor, child: Stack( children: [ Positioned( - top: (size.maxHeight / 2) - 18, - left: -4, + top: size.maxHeight > size.maxWidth + ? (size.maxHeight / 2) - 18 + : -4, + left: size.maxHeight > size.maxWidth + ? -4 + : (size.maxWidth / 2) - 18, child: Icon( - Icons.drag_indicator, + size.maxHeight > size.maxWidth + ? Icons.drag_indicator + : Icons.drag_handle, color: widget.indicatorColor, size: 18, ), @@ -340,6 +363,7 @@ class PlutoDualGridLayoutDelegate extends MultiChildLayoutDelegate { required this.display, required this.showDraggableDivider, required this.isLTR, + required this.isVertical, }) : super(relayout: notifier); final PlutoDualGridDisplay display; @@ -348,6 +372,8 @@ class PlutoDualGridLayoutDelegate extends MultiChildLayoutDelegate { final bool isLTR; + final bool isVertical; + @override void performLayout(Size size) { final BoxConstraints constrains = BoxConstraints( @@ -366,6 +392,8 @@ class PlutoDualGridLayoutDelegate extends MultiChildLayoutDelegate { : display.offset! - dividerHalf : display.gridAWidth(constrains) - dividerHalf; double gridBWidth = size.width - gridAWidth - dividerWidth; + double gridAHeight = size.height; + double gridBHeight = size.height; if (!isLTR) { final savedGridBWidth = gridBWidth; @@ -373,6 +401,29 @@ class PlutoDualGridLayoutDelegate extends MultiChildLayoutDelegate { gridAWidth = savedGridBWidth; } + if (isVertical) { + gridAWidth = size.width; + gridBWidth = size.width; + gridAHeight = showDraggableDivider + ? display.offset == null + ? display.gridAHeight(constrains) - dividerHalf + : display.offset! - dividerHalf + : display.gridAHeight(constrains) - dividerHalf; + gridBHeight = size.height - gridAHeight - dividerWidth; + + if (gridAHeight < 0) { + gridAHeight = 0; + } else if (gridAHeight > size.height - dividerWidth) { + gridAHeight = size.height - dividerWidth; + } + + if (gridBHeight < 0) { + gridBHeight = 0; + } else if (gridBHeight > size.height - dividerWidth) { + gridBHeight = size.height - dividerWidth; + } + } + if (gridAWidth < 0) { gridAWidth = 0; } else if (gridAWidth > size.width - dividerWidth) { @@ -389,39 +440,51 @@ class PlutoDualGridLayoutDelegate extends MultiChildLayoutDelegate { layoutChild( _PlutoDualGridId.gridA, BoxConstraints.tight( - Size(gridAWidth, size.height), + Size(gridAWidth, gridAHeight), ), ); final double posX = isLTR ? 0 : gridBWidth + dividerWidth; - - positionChild(_PlutoDualGridId.gridA, Offset(posX, 0)); + if (isVertical) { + positionChild(_PlutoDualGridId.gridA, const Offset(0, 0)); + } else { + positionChild(_PlutoDualGridId.gridA, Offset(posX, 0)); + } } if (hasChild(_PlutoDualGridId.divider)) { layoutChild( _PlutoDualGridId.divider, BoxConstraints.tight( - Size(PlutoDualGrid.dividerWidth, size.height), + isVertical + ? Size(size.width, PlutoDualGrid.dividerWidth) + : Size(PlutoDualGrid.dividerWidth, size.height), ), ); final double posX = isLTR ? gridAWidth : gridBWidth; - - positionChild(_PlutoDualGridId.divider, Offset(posX, 0)); + if (isVertical) { + positionChild(_PlutoDualGridId.divider, Offset(0, gridAHeight)); + } else { + positionChild(_PlutoDualGridId.divider, Offset(posX, 0)); + } } if (hasChild(_PlutoDualGridId.gridB)) { layoutChild( _PlutoDualGridId.gridB, BoxConstraints.tight( - Size(gridBWidth, size.height), + Size(gridBWidth, gridBHeight), ), ); final double posX = isLTR ? gridAWidth + dividerWidth : 0; - - positionChild(_PlutoDualGridId.gridB, Offset(posX, 0)); + if (isVertical) { + positionChild( + _PlutoDualGridId.gridB, Offset(0, gridAHeight + dividerWidth)); + } else { + positionChild(_PlutoDualGridId.gridB, Offset(posX, 0)); + } } } @@ -444,8 +507,9 @@ class PlutoDualOnSelectedEvent { abstract class PlutoDualGridDisplay { double gridAWidth(BoxConstraints size); - + double gridAHeight(BoxConstraints size); double gridBWidth(BoxConstraints size); + double gridBHeight(BoxConstraints size); double? offset; } @@ -465,6 +529,12 @@ class PlutoDualGridDisplayRatio implements PlutoDualGridDisplay { @override double gridBWidth(BoxConstraints size) => size.maxWidth * (1 - ratio); + + @override + double gridAHeight(BoxConstraints size) => size.maxHeight * ratio; + + @override + double gridBHeight(BoxConstraints size) => size.maxHeight * (1 - ratio); } class PlutoDualGridDisplayFixedAndExpanded implements PlutoDualGridDisplay { @@ -482,6 +552,12 @@ class PlutoDualGridDisplayFixedAndExpanded implements PlutoDualGridDisplay { @override double gridBWidth(BoxConstraints size) => size.maxWidth - width; + + @override + double gridAHeight(BoxConstraints size) => width; + + @override + double gridBHeight(BoxConstraints size) => size.maxHeight - width; } class PlutoDualGridDisplayExpandedAndFixed implements PlutoDualGridDisplay { @@ -499,6 +575,12 @@ class PlutoDualGridDisplayExpandedAndFixed implements PlutoDualGridDisplay { @override double gridBWidth(BoxConstraints size) => width; + + @override + double gridAHeight(BoxConstraints size) => size.maxHeight - width; + + @override + double gridBHeight(BoxConstraints size) => width; } class PlutoDualGridProps { From 33febb5694f6ca35163be45413e22d202311a9ad Mon Sep 17 00:00:00 2001 From: Jonathan Ma Date: Fri, 30 Jun 2023 15:51:09 -0400 Subject: [PATCH 2/3] Update pubspec.yaml --- pubspec.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pubspec.yaml b/pubspec.yaml index 9ff0f667c..672ce515f 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -15,7 +15,7 @@ dependencies: # https://github.com/flutter/flutter/blob/84a1e904f44f9b0e9c4510138010edcc653163f8/packages/flutter_localizations/pubspec.yaml#L11 intl: ^0.18.0 rxdart: ^0.27.7 - collection: ^1.17.1 + collection: ^1.17.0 dev_dependencies: flutter_test: From 4a07b5facc9e6846fe2dd4042ec47870ed43308b Mon Sep 17 00:00:00 2001 From: Jonathan Ma Date: Tue, 29 Aug 2023 12:56:50 -0400 Subject: [PATCH 3/3] fix extra space on right for vertical grid --- lib/src/pluto_dual_grid.dart | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lib/src/pluto_dual_grid.dart b/lib/src/pluto_dual_grid.dart index 3cdd3b2f5..864a6caa2 100644 --- a/lib/src/pluto_dual_grid.dart +++ b/lib/src/pluto_dual_grid.dart @@ -401,6 +401,18 @@ class PlutoDualGridLayoutDelegate extends MultiChildLayoutDelegate { gridAWidth = savedGridBWidth; } + if (gridAWidth < 0) { + gridAWidth = 0; + } else if (gridAWidth > size.width - dividerWidth) { + gridAWidth = size.width - dividerWidth; + } + + if (gridBWidth < 0) { + gridBWidth = 0; + } else if (gridBWidth > size.width - dividerWidth) { + gridBWidth = size.width - dividerWidth; + } + if (isVertical) { gridAWidth = size.width; gridBWidth = size.width; @@ -424,18 +436,6 @@ class PlutoDualGridLayoutDelegate extends MultiChildLayoutDelegate { } } - if (gridAWidth < 0) { - gridAWidth = 0; - } else if (gridAWidth > size.width - dividerWidth) { - gridAWidth = size.width - dividerWidth; - } - - if (gridBWidth < 0) { - gridBWidth = 0; - } else if (gridBWidth > size.width - dividerWidth) { - gridBWidth = size.width - dividerWidth; - } - if (hasChild(_PlutoDualGridId.gridA)) { layoutChild( _PlutoDualGridId.gridA,