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/entity_widgets/glance_entity_container.dart

84 lines
2.0 KiB
Dart
Raw Normal View History

2018-11-14 19:52:17 +02:00
part of '../main.dart';
class GlanceEntityContainer 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
2018-11-14 19:52:17 +02:00
GlanceEntityContainer({
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;
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(
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(
child: ConstrainedBox(
2018-11-25 20:44:19 +02:00
constraints: BoxConstraints(minWidth: Sizes.iconSize * 2),
child: Column(
mainAxisSize: MainAxisSize.min,
//mainAxisAlignment: MainAxisAlignment.start,
//crossAxisAlignment: CrossAxisAlignment.center,
children: result,
2018-11-25 17:33:33 +02:00
),
),
2018-11-25 20:44:19 +02:00
onTap: () => entityWrapper.handleTap(),
onLongPress: () => entityWrapper.handleHold(),
),
);
}
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
}
}