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/entity_button_card.dart

70 lines
2.0 KiB
Dart
Raw Normal View History

2020-04-25 18:59:07 +03:00
part of '../main.dart';
class EntityButtonCard extends StatelessWidget {
2020-04-27 01:46:37 +03:00
final ButtonCardData card;
2020-04-25 18:59:07 +03:00
EntityButtonCard({
Key key, this.card
}) : super(key: key);
@override
Widget build(BuildContext context) {
2020-04-27 01:46:37 +03:00
EntityWrapper entityWrapper = card.entity;
if (entityWrapper.entity.statelessType == StatelessEntityType.missed) {
2020-04-27 01:46:37 +03:00
return EntityModel(
entityWrapper: card.entity,
child: MissedEntityWidget(),
handleTap: false,
);
} else if (entityWrapper.entity.statelessType != StatelessEntityType.ghost && entityWrapper.entity.statelessType != StatelessEntityType.none) {
2020-04-25 18:59:07 +03:00
return Container(width: 0.0, height: 0.0,);
}
double widthBase = math.min(MediaQuery.of(context).size.width, MediaQuery.of(context).size.height) / 6;
Widget buttonIcon;
2020-04-27 01:46:37 +03:00
if (!card.showIcon) {
buttonIcon = Container(height: Sizes.rowPadding, width: 10);
} else {
buttonIcon = EntityIcon(
padding: EdgeInsets.fromLTRB(2.0, 6.0, 2.0, 2.0),
size: widthBase / (card.depth * 0.5),
);
}
2020-04-25 18:59:07 +03:00
return CardWrapper(
child: EntityModel(
2020-04-27 01:46:37 +03:00
entityWrapper: card.entity,
child: InkWell(
onTap: () => entityWrapper.handleTap(),
onLongPress: () => entityWrapper.handleHold(),
onDoubleTap: () => entityWrapper.handleDoubleTap(),
2020-04-27 01:46:37 +03:00
child: Center(
2020-04-25 18:59:07 +03:00
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
2020-04-25 18:59:07 +03:00
children: <Widget>[
buttonIcon,
2020-04-25 18:59:07 +03:00
_buildName()
],
)
2020-04-25 18:59:07 +03:00
),
),
handleTap: true
2020-04-25 18:59:07 +03:00
)
);
}
Widget _buildName() {
if (card.showName) {
return EntityName(
padding: EdgeInsets.fromLTRB(Sizes.buttonPadding, 0.0, Sizes.buttonPadding, Sizes.rowPadding),
textOverflow: TextOverflow.ellipsis,
maxLines: 3,
wordsWrap: true,
textAlign: TextAlign.center
);
}
return Container(width: 0, height: 0);
}
}