Widget rendering improvements
This commit is contained in:
parent
513bf85cae
commit
16c06a2d48
@ -19,6 +19,7 @@ class HACard {
|
|||||||
String unit;
|
String unit;
|
||||||
int min;
|
int min;
|
||||||
int max;
|
int max;
|
||||||
|
int depth;
|
||||||
Map severity;
|
Map severity;
|
||||||
|
|
||||||
HACard({
|
HACard({
|
||||||
@ -37,6 +38,7 @@ class HACard {
|
|||||||
this.unit,
|
this.unit,
|
||||||
this.min,
|
this.min,
|
||||||
this.max,
|
this.max,
|
||||||
|
this.depth: 1,
|
||||||
this.severity,
|
this.severity,
|
||||||
@required this.type
|
@required this.type
|
||||||
}) {
|
}) {
|
||||||
|
@ -87,11 +87,13 @@ class CardWidget extends StatelessWidget {
|
|||||||
child: childCard.build(context),
|
child: childCard.build(context),
|
||||||
)
|
)
|
||||||
).toList();
|
).toList();
|
||||||
return Row(
|
return IntrinsicHeight(
|
||||||
|
child: Row(
|
||||||
mainAxisSize: MainAxisSize.max,
|
mainAxisSize: MainAxisSize.max,
|
||||||
mainAxisAlignment: MainAxisAlignment.center,
|
mainAxisAlignment: MainAxisAlignment.center,
|
||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||||
children: children,
|
children: children,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
return Container(height: 0.0, width: 0.0,);
|
return Container(height: 0.0, width: 0.0,);
|
||||||
@ -237,52 +239,48 @@ class CardWidget extends StatelessWidget {
|
|||||||
if (entitiesToShow.isEmpty && !card.showEmpty) {
|
if (entitiesToShow.isEmpty && !card.showEmpty) {
|
||||||
return Container(height: 0.0, width: 0.0,);
|
return Container(height: 0.0, width: 0.0,);
|
||||||
}
|
}
|
||||||
List<Widget> rows = [];
|
int length = entitiesToShow.length;
|
||||||
rows.add(CardHeader(name: card.name));
|
int columnsCount = length >= card.columnsCount ? card.columnsCount : entitiesToShow.length;
|
||||||
|
int rowsCount = (length / columnsCount).round();
|
||||||
int columnsCount = entitiesToShow.length >= card.columnsCount ? card.columnsCount : entitiesToShow.length;
|
List<TableRow> rows = [];
|
||||||
|
for (int i = 0; i < rowsCount; i++) {
|
||||||
rows.add(
|
int start = i*columnsCount;
|
||||||
Padding(
|
int end = start + math.min(columnsCount, length - start);
|
||||||
padding: EdgeInsets.only(bottom: Sizes.rowPadding, top: Sizes.rowPadding),
|
List<Widget> rowChildren = [];
|
||||||
child: FractionallySizedBox(
|
rowChildren.addAll(entitiesToShow.sublist(
|
||||||
widthFactor: 1,
|
start, end
|
||||||
child: LayoutBuilder(
|
).map(
|
||||||
builder: (BuildContext context, BoxConstraints constraints) {
|
(EntityWrapper entity){
|
||||||
List<Widget> buttons = [];
|
return EntityModel(
|
||||||
double buttonWidth = constraints.maxWidth / columnsCount;
|
|
||||||
entitiesToShow.forEach((EntityWrapper entity) {
|
|
||||||
buttons.add(
|
|
||||||
SizedBox(
|
|
||||||
width: buttonWidth,
|
|
||||||
child: EntityModel(
|
|
||||||
entityWrapper: entity,
|
entityWrapper: entity,
|
||||||
child: GlanceCardEntityContainer(
|
child: GlanceCardEntityContainer(
|
||||||
showName: card.showName,
|
showName: card.showName,
|
||||||
showState: card.showState,
|
showState: card.showState,
|
||||||
),
|
),
|
||||||
handleTap: true
|
handleTap: true
|
||||||
),
|
|
||||||
)
|
|
||||||
);
|
|
||||||
});
|
|
||||||
return Wrap(
|
|
||||||
//spacing: 5.0,
|
|
||||||
//alignment: WrapAlignment.spaceEvenly,
|
|
||||||
runSpacing: Sizes.doubleRowPadding,
|
|
||||||
children: buttons,
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
),
|
).toList()
|
||||||
),
|
);
|
||||||
|
while (rowChildren.length < columnsCount) {
|
||||||
|
rowChildren.add(
|
||||||
|
Container()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
rows.add(
|
||||||
|
TableRow(
|
||||||
|
children: rowChildren
|
||||||
)
|
)
|
||||||
);
|
);
|
||||||
|
}
|
||||||
|
|
||||||
return Card(
|
return Card(
|
||||||
child: Column(
|
child: Padding(
|
||||||
mainAxisSize: MainAxisSize.min,
|
padding: EdgeInsets.symmetric(vertical: Sizes.rowPadding),
|
||||||
|
child: Table(
|
||||||
children: rows
|
children: rows
|
||||||
)
|
)
|
||||||
|
)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -303,6 +301,7 @@ class CardWidget extends StatelessWidget {
|
|||||||
child: EntityModel(
|
child: EntityModel(
|
||||||
entityWrapper: card.linkedEntityWrapper,
|
entityWrapper: card.linkedEntityWrapper,
|
||||||
child: EntityButtonCardBody(
|
child: EntityButtonCardBody(
|
||||||
|
depth: card.depth,
|
||||||
showName: card.showName,
|
showName: card.showName,
|
||||||
),
|
),
|
||||||
handleTap: true
|
handleTap: true
|
||||||
|
@ -3,9 +3,10 @@ part of '../../main.dart';
|
|||||||
class EntityButtonCardBody extends StatelessWidget {
|
class EntityButtonCardBody extends StatelessWidget {
|
||||||
|
|
||||||
final bool showName;
|
final bool showName;
|
||||||
|
final int depth;
|
||||||
|
|
||||||
EntityButtonCardBody({
|
EntityButtonCardBody({
|
||||||
Key key, this.showName: true,
|
Key key, this.showName: true, @required this.depth
|
||||||
}) : super(key: key);
|
}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
@ -17,28 +18,21 @@ class EntityButtonCardBody extends StatelessWidget {
|
|||||||
if (entityWrapper.entity.statelessType > StatelessEntityType.MISSED) {
|
if (entityWrapper.entity.statelessType > StatelessEntityType.MISSED) {
|
||||||
return Container(width: 0.0, height: 0.0,);
|
return Container(width: 0.0, height: 0.0,);
|
||||||
}
|
}
|
||||||
|
double widthBase = math.min(MediaQuery.of(context).size.width, MediaQuery.of(context).size.height) / 6;
|
||||||
return InkWell(
|
return InkWell(
|
||||||
onTap: () => entityWrapper.handleTap(),
|
onTap: () => entityWrapper.handleTap(),
|
||||||
onLongPress: () => entityWrapper.handleHold(),
|
onLongPress: () => entityWrapper.handleHold(),
|
||||||
onDoubleTap: () => entityWrapper.handleDoubleTap(),
|
onDoubleTap: () => entityWrapper.handleDoubleTap(),
|
||||||
child: FractionallySizedBox(
|
|
||||||
widthFactor: 1,
|
|
||||||
child: Column(
|
child: Column(
|
||||||
mainAxisSize: MainAxisSize.min,
|
mainAxisSize: MainAxisSize.min,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
LayoutBuilder(
|
EntityIcon(
|
||||||
builder: (BuildContext context, BoxConstraints constraints) {
|
|
||||||
return EntityIcon(
|
|
||||||
padding: EdgeInsets.fromLTRB(2.0, 6.0, 2.0, 2.0),
|
padding: EdgeInsets.fromLTRB(2.0, 6.0, 2.0, 2.0),
|
||||||
size: constraints.maxWidth / 2.5,
|
size: widthBase / (depth * 0.5),
|
||||||
);
|
|
||||||
}
|
|
||||||
),
|
),
|
||||||
_buildName()
|
_buildName()
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -94,19 +94,7 @@ class GaugeCardBody extends StatelessWidget {
|
|||||||
onDoubleTap: () => entityWrapper.handleDoubleTap(),
|
onDoubleTap: () => entityWrapper.handleDoubleTap(),
|
||||||
child: AspectRatio(
|
child: AspectRatio(
|
||||||
aspectRatio: 2,
|
aspectRatio: 2,
|
||||||
child: LayoutBuilder(
|
child: SfRadialGauge(
|
||||||
builder: (BuildContext context, BoxConstraints constraints) {
|
|
||||||
double fontSizeFactor;
|
|
||||||
if (constraints.maxWidth > 300.0) {
|
|
||||||
fontSizeFactor = 1.6;
|
|
||||||
} else if (constraints.maxWidth > 150.0) {
|
|
||||||
fontSizeFactor = 1;
|
|
||||||
} else if (constraints.maxWidth > 100.0) {
|
|
||||||
fontSizeFactor = 0.6;
|
|
||||||
} else {
|
|
||||||
fontSizeFactor = 0.4;
|
|
||||||
}
|
|
||||||
return SfRadialGauge(
|
|
||||||
axes: <RadialAxis>[
|
axes: <RadialAxis>[
|
||||||
RadialAxis(
|
RadialAxis(
|
||||||
maximum: max.toDouble(),
|
maximum: max.toDouble(),
|
||||||
@ -128,7 +116,7 @@ class GaugeCardBody extends StatelessWidget {
|
|||||||
//verticalAlignment: GaugeAlignment.far,
|
//verticalAlignment: GaugeAlignment.far,
|
||||||
widget: EntityName(
|
widget: EntityName(
|
||||||
textStyle: Theme.of(context).textTheme.body1.copyWith(
|
textStyle: Theme.of(context).textTheme.body1.copyWith(
|
||||||
fontSize: Theme.of(context).textTheme.body1.fontSize * fontSizeFactor
|
fontSize: Theme.of(context).textTheme.body1.fontSize
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -141,7 +129,7 @@ class GaugeCardBody extends StatelessWidget {
|
|||||||
maxLines: 1,
|
maxLines: 1,
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
textStyle: Theme.of(context).textTheme.title.copyWith(
|
textStyle: Theme.of(context).textTheme.title.copyWith(
|
||||||
fontSize: Theme.of(context).textTheme.title.fontSize * fontSizeFactor,
|
fontSize: Theme.of(context).textTheme.title.fontSize,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
@ -160,9 +148,7 @@ class GaugeCardBody extends StatelessWidget {
|
|||||||
]
|
]
|
||||||
)
|
)
|
||||||
],
|
],
|
||||||
);
|
)
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
import 'dart:math' as math;
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/rendering.dart';
|
import 'package:flutter/rendering.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
@ -33,10 +33,10 @@ class HAView {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
cards.addAll(_createLovelaceCards(rawData["cards"] ?? []));
|
cards.addAll(_createLovelaceCards(rawData["cards"] ?? [], 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
List<HACard> _createLovelaceCards(List rawCards) {
|
List<HACard> _createLovelaceCards(List rawCards, int depth) {
|
||||||
List<HACard> result = [];
|
List<HACard> result = [];
|
||||||
rawCards.forEach((rawCard){
|
rawCards.forEach((rawCard){
|
||||||
try {
|
try {
|
||||||
@ -58,10 +58,11 @@ class HAView {
|
|||||||
min: rawCardInfo['min'] ?? 0,
|
min: rawCardInfo['min'] ?? 0,
|
||||||
max: rawCardInfo['max'] ?? 100,
|
max: rawCardInfo['max'] ?? 100,
|
||||||
unit: rawCardInfo['unit'],
|
unit: rawCardInfo['unit'],
|
||||||
|
depth: depth,
|
||||||
severity: rawCardInfo['severity']
|
severity: rawCardInfo['severity']
|
||||||
);
|
);
|
||||||
if (rawCardInfo["cards"] != null) {
|
if (rawCardInfo["cards"] != null) {
|
||||||
card.childCards = _createLovelaceCards(rawCardInfo["cards"]);
|
card.childCards = _createLovelaceCards(rawCardInfo["cards"], depth + 1);
|
||||||
}
|
}
|
||||||
var rawEntities = rawCard["entities"] ?? rawCardInfo["entities"];
|
var rawEntities = rawCard["entities"] ?? rawCardInfo["entities"];
|
||||||
rawEntities?.forEach((rawEntity) {
|
rawEntities?.forEach((rawEntity) {
|
||||||
|
@ -26,6 +26,11 @@ class ViewWidget extends StatelessWidget {
|
|||||||
} else {
|
} else {
|
||||||
cardsContainer = Container();
|
cardsContainer = Container();
|
||||||
}
|
}
|
||||||
|
return ListView(
|
||||||
|
shrinkWrap: false,
|
||||||
|
padding: EdgeInsets.all(0),
|
||||||
|
children: this.view.cards.map((card) => card.build(context)).toList()
|
||||||
|
);
|
||||||
return ListView(
|
return ListView(
|
||||||
shrinkWrap: true,
|
shrinkWrap: true,
|
||||||
padding: EdgeInsets.all(0),
|
padding: EdgeInsets.all(0),
|
||||||
|
Reference in New Issue
Block a user