This repository has been archived on 2023-11-18. You can view files and clone it, but cannot push or open issues or pull requests.
ha_client/lib/card_class.dart

54 lines
1.3 KiB
Dart
Raw Normal View History

part of 'main.dart';
2018-10-07 02:17:14 +03:00
class HACard extends StatelessWidget {
2018-10-07 02:17:14 +03:00
final List<Entity> entities;
final String friendlyName;
2018-10-07 02:17:14 +03:00
const HACard({
Key key,
this.entities,
this.friendlyName
}) : super(key: key);
@override
Widget build(BuildContext context) {
List<Widget> body = [];
body.add(_buildCardHeader());
body.addAll(_buildCardBody(context));
return Card(
child: new Column(mainAxisSize: MainAxisSize.min, children: body)
);
}
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-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),
child: entity.buildDefaultWidget(context),
2018-10-07 02:17:14 +03:00
));
});
return result;
}
}