WIP #224 Dynamic multi column view
This commit is contained in:
parent
298a64b7ae
commit
d61103ac42
@ -25,6 +25,7 @@ import 'package:in_app_purchase/in_app_purchase.dart';
|
|||||||
import 'plugins/circular_slider/single_circular_slider.dart';
|
import 'plugins/circular_slider/single_circular_slider.dart';
|
||||||
import 'package:share/receive_share_state.dart';
|
import 'package:share/receive_share_state.dart';
|
||||||
import 'package:share/share.dart';
|
import 'package:share/share.dart';
|
||||||
|
import 'plugins/DynamicMultiColumnLayout.dart';
|
||||||
|
|
||||||
import 'utils/logger.dart';
|
import 'utils/logger.dart';
|
||||||
|
|
||||||
|
146
lib/plugins/DynamicMultiColumnLayout.dart
Normal file
146
lib/plugins/DynamicMultiColumnLayout.dart
Normal file
@ -0,0 +1,146 @@
|
|||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/rendering.dart';
|
||||||
|
import 'dart:math' as math;
|
||||||
|
|
||||||
|
class DynamicMultiColumnLayout extends MultiChildRenderObjectWidget {
|
||||||
|
|
||||||
|
final int minColumnWidth;
|
||||||
|
|
||||||
|
DynamicMultiColumnLayout({
|
||||||
|
Key key,
|
||||||
|
this.minColumnWidth: 350,
|
||||||
|
List<Widget> children = const <Widget>[],
|
||||||
|
}) : super(key: key, children: children);
|
||||||
|
|
||||||
|
@override
|
||||||
|
RenderCustomLayoutBox createRenderObject(BuildContext context) {
|
||||||
|
return RenderCustomLayoutBox(minColumnWidth: this.minColumnWidth);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
class RenderCustomLayoutBox extends RenderBox
|
||||||
|
with ContainerRenderObjectMixin<RenderBox, CustomLayoutParentData>,
|
||||||
|
RenderBoxContainerDefaultsMixin<RenderBox, CustomLayoutParentData> {
|
||||||
|
|
||||||
|
final int minColumnWidth;
|
||||||
|
|
||||||
|
RenderCustomLayoutBox({
|
||||||
|
this.minColumnWidth,
|
||||||
|
List<RenderBox> children,
|
||||||
|
}) {
|
||||||
|
addAll(children);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void setupParentData(RenderBox child) {
|
||||||
|
if (child.parentData is! CustomLayoutParentData) {
|
||||||
|
child.parentData = CustomLayoutParentData();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
double _getIntrinsicHeight(double childSize(RenderBox child)) {
|
||||||
|
double inflexibleSpace = 0.0;
|
||||||
|
RenderBox child = firstChild;
|
||||||
|
while (child != null) {
|
||||||
|
inflexibleSpace += childSize(child);
|
||||||
|
final FlexParentData childParentData = child.parentData;
|
||||||
|
child = childParentData.nextSibling;
|
||||||
|
}
|
||||||
|
return inflexibleSpace;
|
||||||
|
}
|
||||||
|
|
||||||
|
double _getIntrinsicWidth(double childSize(RenderBox child)) {
|
||||||
|
double maxSpace = 0.0;
|
||||||
|
RenderBox child = firstChild;
|
||||||
|
while (child != null) {
|
||||||
|
maxSpace = math.max(maxSpace, childSize(child));
|
||||||
|
final FlexParentData childParentData = child.parentData;
|
||||||
|
child = childParentData.nextSibling;
|
||||||
|
}
|
||||||
|
return maxSpace;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
double computeMinIntrinsicWidth(double height) {
|
||||||
|
return _getIntrinsicWidth((RenderBox child) => child.getMinIntrinsicWidth(height));
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
double computeMaxIntrinsicWidth(double height) {
|
||||||
|
return _getIntrinsicWidth((RenderBox child) => child.getMaxIntrinsicWidth(height));
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
double computeMinIntrinsicHeight(double width) {
|
||||||
|
return _getIntrinsicHeight((RenderBox child) => child.getMinIntrinsicHeight(width));
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
double computeMaxIntrinsicHeight(double width) {
|
||||||
|
return _getIntrinsicHeight((RenderBox child) => child.getMaxIntrinsicHeight(width));
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void performLayout() {
|
||||||
|
int columnsCount;
|
||||||
|
List<double> columnXPositions = [];
|
||||||
|
List<double> columnYPositions = [];
|
||||||
|
if (childCount == 0) {
|
||||||
|
size = constraints.biggest;
|
||||||
|
assert(size.isFinite);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
columnsCount = (constraints.maxWidth ~/ this.minColumnWidth);
|
||||||
|
double columnWidth = constraints.maxWidth / columnsCount;
|
||||||
|
double startY = 0;
|
||||||
|
for (int i =0; i < columnsCount; i++) {
|
||||||
|
columnXPositions.add(i*columnWidth);
|
||||||
|
columnYPositions.add(startY);
|
||||||
|
}
|
||||||
|
RenderBox child = firstChild;
|
||||||
|
while (child != null) {
|
||||||
|
final CustomLayoutParentData childParentData = child.parentData;
|
||||||
|
|
||||||
|
int columnToAdd = 0;
|
||||||
|
double minYPosition = columnYPositions[0];
|
||||||
|
for (int i=0; i<columnsCount; i++) {
|
||||||
|
if (columnYPositions[i] < minYPosition) {
|
||||||
|
minYPosition = columnYPositions[i];
|
||||||
|
columnToAdd = i;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
child.layout(BoxConstraints.tightFor(width: columnWidth), parentUsesSize: true);
|
||||||
|
childParentData.offset = Offset(columnXPositions[columnToAdd], columnYPositions[columnToAdd]);
|
||||||
|
final Size newSize = child.size;
|
||||||
|
columnYPositions[columnToAdd] = minYPosition + newSize.height;
|
||||||
|
|
||||||
|
child = childParentData.nextSibling;
|
||||||
|
}
|
||||||
|
|
||||||
|
double width = constraints.maxWidth;
|
||||||
|
double height = 0;
|
||||||
|
for (int i=0; i<columnsCount; i++) {
|
||||||
|
if (columnYPositions[i] > height) {
|
||||||
|
height = columnYPositions[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
size = Size(width, height);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void paint(PaintingContext context, Offset offset) {
|
||||||
|
defaultPaint(context, offset);
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
bool hitTestChildren(HitTestResult result, { Offset position }) {
|
||||||
|
return defaultHitTestChildren(result, position: position);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
class CustomLayoutParentData extends ContainerBoxParentData<RenderBox> {
|
||||||
|
|
||||||
|
}
|
@ -31,6 +31,16 @@ class ViewWidgetState extends State<ViewWidget> {
|
|||||||
child: _buildPanelChild(context),
|
child: _buildPanelChild(context),
|
||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
|
return ListView(
|
||||||
|
shrinkWrap: true,
|
||||||
|
padding: EdgeInsets.all(0),
|
||||||
|
children: <Widget>[
|
||||||
|
DynamicMultiColumnLayout(
|
||||||
|
minColumnWidth: Sizes.minViewColumnWidth,
|
||||||
|
children: _buildChildren(context),
|
||||||
|
)
|
||||||
|
]
|
||||||
|
);
|
||||||
return ListView(
|
return ListView(
|
||||||
shrinkWrap: true,
|
shrinkWrap: true,
|
||||||
padding: EdgeInsets.all(0),
|
padding: EdgeInsets.all(0),
|
||||||
@ -61,7 +71,7 @@ class ViewWidgetState extends State<ViewWidget> {
|
|||||||
List<Widget> result = [];
|
List<Widget> result = [];
|
||||||
int layoutChildId = 0;
|
int layoutChildId = 0;
|
||||||
|
|
||||||
if (widget.view.badges.isNotEmpty) {
|
/*if (widget.view.badges.isNotEmpty) {
|
||||||
result.add(
|
result.add(
|
||||||
LayoutId(
|
LayoutId(
|
||||||
id: "badges",
|
id: "badges",
|
||||||
@ -73,15 +83,11 @@ class ViewWidgetState extends State<ViewWidget> {
|
|||||||
),
|
),
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
}
|
}*/
|
||||||
widget.view.cards.forEach((HACard card){
|
widget.view.cards.forEach((HACard card){
|
||||||
result.add(
|
result.add(
|
||||||
LayoutId(
|
card.build(context)
|
||||||
id: 'card_$layoutChildId',
|
|
||||||
child: card.build(context),
|
|
||||||
)
|
|
||||||
);
|
);
|
||||||
layoutChildId += 1;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -164,7 +164,7 @@ packages:
|
|||||||
name: flutter_webview_plugin
|
name: flutter_webview_plugin
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.3.7"
|
version: "0.3.8"
|
||||||
http:
|
http:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -374,7 +374,7 @@ packages:
|
|||||||
name: url_launcher
|
name: url_launcher
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "5.1.2"
|
version: "5.1.3"
|
||||||
uuid:
|
uuid:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
Reference in New Issue
Block a user