2018-11-14 19:52:17 +02:00
|
|
|
part of '../main.dart';
|
|
|
|
|
|
|
|
class GlanceCardWidget extends StatelessWidget {
|
|
|
|
|
|
|
|
final HACard card;
|
|
|
|
|
|
|
|
const GlanceCardWidget({
|
|
|
|
Key key,
|
|
|
|
this.card
|
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2018-11-15 19:08:47 +02:00
|
|
|
if ((card.linkedEntity!= null) && (card.linkedEntity.entity.isHidden)) {
|
2018-11-14 19:52:17 +02:00
|
|
|
return Container(width: 0.0, height: 0.0,);
|
|
|
|
}
|
|
|
|
List<Widget> rows = [];
|
|
|
|
rows.add(CardHeaderWidget(name: card.name));
|
|
|
|
rows.add(_buildRows(context));
|
|
|
|
return Card(
|
|
|
|
child: new Column(mainAxisSize: MainAxisSize.min, children: rows)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget _buildRows(BuildContext context) {
|
|
|
|
List<Widget> result = [];
|
|
|
|
double width = MediaQuery.of(context).size.width - Sizes.leftWidgetPadding - (2*Sizes.rightWidgetPadding);
|
2018-11-15 19:08:47 +02:00
|
|
|
List<EntityWrapper> toShow = card.entities.where((entity) {return !entity.entity.isHidden;}).toList();
|
2018-11-14 19:52:17 +02:00
|
|
|
int columnsCount = toShow.length >= card.columnsCount ? card.columnsCount : toShow.length;
|
2018-11-15 19:08:47 +02:00
|
|
|
card.entities.forEach((EntityWrapper entity) {
|
|
|
|
if (!entity.entity.isHidden) {
|
2018-11-14 19:52:17 +02:00
|
|
|
result.add(
|
|
|
|
SizedBox(
|
|
|
|
width: width / columnsCount,
|
2018-11-15 19:08:47 +02:00
|
|
|
child: EntityModel(
|
|
|
|
entity: entity,
|
|
|
|
child: entity.entity.buildGlanceWidget(context, card.showName, card.showState),
|
|
|
|
handleTap: true
|
|
|
|
),
|
2018-11-14 19:52:17 +02:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return Padding(
|
|
|
|
padding: EdgeInsets.fromLTRB(0.0, Sizes.rowPadding, 0.0, 2*Sizes.rowPadding),
|
|
|
|
child: Wrap(
|
|
|
|
alignment: WrapAlignment.spaceAround,
|
|
|
|
runSpacing: Sizes.rowPadding*2,
|
|
|
|
children: result,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|