From 9c28b0085bfb77356804fd975dfbb469649eaa05 Mon Sep 17 00:00:00 2001 From: estevez-dev Date: Tue, 10 Sep 2019 15:40:49 +0300 Subject: [PATCH] Tablet UI in progress --- lib/const.dart | 1 + lib/view.dart | 96 +++++++++++++++++++++++++++++++++++++++----------- 2 files changed, 76 insertions(+), 21 deletions(-) diff --git a/lib/const.dart b/lib/const.dart index 6e7c99e..9da7af2 100644 --- a/lib/const.dart +++ b/lib/const.dart @@ -113,4 +113,5 @@ class Sizes { static const inputWidth = 160.0; static const rowPadding = 10.0; static const doubleRowPadding = rowPadding*2; + static const minViewColumnWidth = 350; } \ No newline at end of file diff --git a/lib/view.dart b/lib/view.dart index e6e2d06..7a3ee9a 100644 --- a/lib/view.dart +++ b/lib/view.dart @@ -32,9 +32,19 @@ class ViewWidgetState extends State { ); } else { return ListView( - padding: EdgeInsets.all(0.0), - //physics: const AlwaysScrollableScrollPhysics(), - children: _buildChildren(context), + shrinkWrap: true, + padding: EdgeInsets.all(0), + children: [ + ConstrainedBox( + constraints: BoxConstraints(maxHeight: 3000), + child: CustomMultiChildLayout( + delegate: ViewLayoutBuilder( + cardsCount: widget.view.cards.length + ), + children: _buildChildren(context), + ), + ) + ], ); } } @@ -49,34 +59,31 @@ class ViewWidgetState extends State { List _buildChildren(BuildContext context) { List result = []; + int layoutChildId = 0; if (widget.view.badges.isNotEmpty) { - result.insert(0, - Wrap( - alignment: WrapAlignment.center, - spacing: 10.0, - runSpacing: 1.0, - children: _buildBadges(context), + result.add( + LayoutId( + id: "badges", + child: Wrap( + alignment: WrapAlignment.center, + spacing: 10.0, + runSpacing: 1.0, + children: _buildBadges(context), + ), ) ); } - - List cards = []; widget.view.cards.forEach((HACard card){ - cards.add( - ConstrainedBox( - constraints: BoxConstraints(maxWidth: 500), + result.add( + LayoutId( + id: 'card_$layoutChildId', child: card.build(context), ) ); + layoutChildId += 1; }); - result.add( - Column ( - children: cards, - ) - ); - return result; } @@ -84,7 +91,9 @@ class ViewWidgetState extends State { List result = []; widget.view.badges.forEach((Entity entity) { if (!entity.isHidden) { - result.add(entity.buildBadgeWidget(context)); + result.add( + entity.buildBadgeWidget(context) + ); } }); return result; @@ -95,5 +104,50 @@ class ViewWidgetState extends State { super.dispose(); } +} +class ViewLayoutBuilder extends MultiChildLayoutDelegate { + final int cardsCount; + + ViewLayoutBuilder({@required this.cardsCount}); + + @override + void performLayout(Size size) { + int columnsCount = (size.width ~/ Sizes.minViewColumnWidth); + double columnWidth = size.width / columnsCount; + List columnXPositions = []; + List columnYPositions = []; + double startY = 0; + if (hasChild("badges")) { + Size badgesSizes = layoutChild( + 'badges', BoxConstraints.tightFor(width: size.width)); + startY += badgesSizes.height; + positionChild('badges', Offset(0, 0)); + } + for (int i =0; i < columnsCount; i++) { + columnXPositions.add(i*columnWidth); + columnYPositions.add(startY); + } + for (int i = 0; i < cardsCount; i++) { + final String cardId = 'card_$i'; + + if (hasChild(cardId)) { + int columnToAdd = 0; + double minYPosition = columnYPositions[0]; + for (int i=1; i false; } \ No newline at end of file