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/cards/widgets/glance_card_entity_container.dart

86 lines
2.1 KiB
Dart
Raw Normal View History

2019-09-07 15:47:09 +03:00
part of '../../main.dart';
2018-11-14 19:52:17 +02:00
2019-09-07 18:23:04 +03:00
class GlanceCardEntityContainer extends StatelessWidget {
2018-11-15 19:08:47 +02:00
final bool showName;
final bool showState;
2018-11-25 17:33:33 +02:00
final bool nameInTheBottom;
final double iconSize;
final double nameFontSize;
2018-11-25 20:44:19 +02:00
final bool wordsWrapInName;
2018-11-15 19:08:47 +02:00
2019-09-07 18:23:04 +03:00
GlanceCardEntityContainer({
2018-11-25 17:33:33 +02:00
Key key,
@required this.showName,
@required this.showState,
this.nameInTheBottom: false,
this.iconSize: Sizes.iconSize,
this.nameFontSize: Sizes.smallFontSize,
2018-11-25 20:44:19 +02:00
this.wordsWrapInName: false
2018-11-14 19:52:17 +02:00
}) : super(key: key);
@override
Widget build(BuildContext context) {
2018-11-24 00:37:55 +02:00
final EntityWrapper entityWrapper = EntityModel.of(context).entityWrapper;
if (entityWrapper.entity.statelessType == StatelessEntityType.MISSED) {
2019-03-12 23:35:33 +02:00
return MissedEntityWidget();
}
if (entityWrapper.entity.statelessType > StatelessEntityType.MISSED) {
return Container(width: 0.0, height: 0.0,);
}
2018-11-15 19:08:47 +02:00
List<Widget> result = [];
2018-11-25 17:33:33 +02:00
if (!nameInTheBottom) {
if (showName) {
2018-11-25 20:44:19 +02:00
result.add(_buildName());
2018-11-25 17:33:33 +02:00
}
} else {
if (showState) {
2018-11-25 20:44:19 +02:00
result.add(_buildState());
2018-11-25 17:33:33 +02:00
}
2018-11-15 19:08:47 +02:00
}
2018-11-24 00:37:55 +02:00
result.add(
2019-09-07 16:46:41 +03:00
EntityIcon(
padding: EdgeInsets.all(0.0),
size: iconSize,
)
2018-11-24 00:37:55 +02:00
);
2018-11-25 17:33:33 +02:00
if (!nameInTheBottom) {
if (showState) {
2018-11-25 20:44:19 +02:00
result.add(_buildState());
2018-11-25 17:33:33 +02:00
}
} else {
2018-11-25 20:44:19 +02:00
result.add(_buildName());
2018-11-15 19:08:47 +02:00
}
2018-11-25 20:44:19 +02:00
return Center(
child: InkResponse(
2019-09-07 16:46:41 +03:00
child: Column(
mainAxisSize: MainAxisSize.min,
children: result,
2018-11-25 17:33:33 +02:00
),
2018-11-25 20:44:19 +02:00
onTap: () => entityWrapper.handleTap(),
onLongPress: () => entityWrapper.handleHold(),
2020-03-14 20:12:11 +02:00
onDoubleTap: () => entityWrapper.handleDoubleTap(),
2018-11-25 20:44:19 +02:00
),
);
}
Widget _buildName() {
return EntityName(
padding: EdgeInsets.only(bottom: Sizes.rowPadding),
textOverflow: TextOverflow.ellipsis,
wordsWrap: wordsWrapInName,
textAlign: TextAlign.center,
fontSize: nameFontSize,
);
}
Widget _buildState() {
return SimpleEntityState(
textAlign: TextAlign.center,
expanded: false,
maxLines: 1,
padding: EdgeInsets.only(top: Sizes.rowPadding),
);
2018-11-14 19:52:17 +02:00
}
}