2018-09-28 10:15:25 +03:00
|
|
|
part of 'main.dart';
|
|
|
|
|
2018-10-21 16:11:47 +03:00
|
|
|
class CardWidget extends StatelessWidget {
|
2018-09-28 10:15:25 +03:00
|
|
|
|
2018-10-07 02:17:14 +03:00
|
|
|
final List<Entity> entities;
|
|
|
|
final String friendlyName;
|
2018-09-28 10:15:25 +03:00
|
|
|
|
2018-10-21 16:11:47 +03:00
|
|
|
const CardWidget({
|
2018-10-07 02:17:14 +03:00
|
|
|
Key key,
|
|
|
|
this.entities,
|
2018-10-21 02:39:51 +03:00
|
|
|
this.friendlyName
|
2018-10-07 02:17:14 +03:00
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2018-10-21 16:11:47 +03:00
|
|
|
final entityModel = EntityModel.of(context);
|
|
|
|
if (entityModel != null) {
|
|
|
|
final groupEntity = entityModel.entity;
|
2018-10-21 18:52:29 +03:00
|
|
|
if ((groupEntity!= null) && (groupEntity.isHidden)) {
|
2018-10-21 16:11:47 +03:00
|
|
|
return Container(width: 0.0, height: 0.0,);
|
|
|
|
}
|
|
|
|
}
|
2018-10-07 02:17:14 +03:00
|
|
|
List<Widget> body = [];
|
|
|
|
body.add(_buildCardHeader());
|
|
|
|
body.addAll(_buildCardBody(context));
|
2018-10-21 02:39:51 +03:00
|
|
|
return Card(
|
|
|
|
child: new Column(mainAxisSize: MainAxisSize.min, children: body)
|
|
|
|
);
|
2018-09-28 10:15:25 +03:00
|
|
|
}
|
|
|
|
|
2018-10-07 02:17:14 +03:00
|
|
|
Widget _buildCardHeader() {
|
|
|
|
var result;
|
|
|
|
if ((friendlyName != null) && (friendlyName.trim().length > 0)) {
|
|
|
|
result = new ListTile(
|
|
|
|
//leading: const Icon(Icons.device_hub),
|
|
|
|
//subtitle: Text(".."),
|
|
|
|
//trailing: Text("${data["state"]}"),
|
|
|
|
title: Text("$friendlyName",
|
|
|
|
textAlign: TextAlign.left,
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
style: new TextStyle(fontWeight: FontWeight.bold, fontSize: 25.0)),
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
result = new Container(width: 0.0, height: 0.0);
|
|
|
|
}
|
|
|
|
return result;
|
2018-09-28 10:15:25 +03:00
|
|
|
}
|
|
|
|
|
2018-10-07 02:17:14 +03:00
|
|
|
List<Widget> _buildCardBody(BuildContext context) {
|
|
|
|
List<Widget> result = [];
|
|
|
|
entities.forEach((Entity entity) {
|
|
|
|
result.add(
|
|
|
|
Padding(
|
|
|
|
padding: EdgeInsets.fromLTRB(0.0, 10.0, 0.0, 10.0),
|
2018-10-15 00:15:09 +03:00
|
|
|
child: entity.buildDefaultWidget(context),
|
2018-10-07 02:17:14 +03:00
|
|
|
));
|
|
|
|
});
|
|
|
|
return result;
|
2018-09-28 10:15:25 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|