2019-09-09 18:50:35 +03:00
|
|
|
part of '../main.dart';
|
2018-10-27 14:27:41 +03:00
|
|
|
|
|
|
|
class BadgeWidget extends StatelessWidget {
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final entityModel = EntityModel.of(context);
|
|
|
|
double iconSize = 26.0;
|
|
|
|
Widget badgeIcon;
|
|
|
|
String onBadgeTextValue;
|
2020-04-07 00:39:16 +03:00
|
|
|
Color iconColor = HAClientTheme().getBadgeColor(entityModel.entityWrapper.entity.domain);
|
2018-11-16 22:32:43 +02:00
|
|
|
switch (entityModel.entityWrapper.entity.domain) {
|
2018-10-27 14:27:41 +03:00
|
|
|
case "sun":
|
|
|
|
{
|
2018-11-16 22:32:43 +02:00
|
|
|
badgeIcon = entityModel.entityWrapper.entity.state == "below_horizon"
|
2018-10-27 14:27:41 +03:00
|
|
|
? Icon(
|
2019-02-22 15:15:27 +02:00
|
|
|
MaterialDesignIcons.getIconDataFromIconCode(0xf0dc),
|
2018-10-27 14:27:41 +03:00
|
|
|
size: iconSize,
|
|
|
|
)
|
|
|
|
: Icon(
|
2019-02-22 15:15:27 +02:00
|
|
|
MaterialDesignIcons.getIconDataFromIconCode(0xf5a8),
|
2018-10-27 14:27:41 +03:00
|
|
|
size: iconSize,
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
2019-02-10 22:33:46 +02:00
|
|
|
case "camera":
|
|
|
|
case "media_player":
|
|
|
|
case "binary_sensor":
|
2018-10-27 14:27:41 +03:00
|
|
|
{
|
2019-02-21 16:32:55 +02:00
|
|
|
badgeIcon = EntityIcon(
|
|
|
|
padding: EdgeInsets.all(0.0),
|
|
|
|
size: iconSize,
|
2020-04-04 18:44:06 +03:00
|
|
|
color: Theme.of(context).textTheme.body1.color
|
2019-02-21 16:32:55 +02:00
|
|
|
);
|
2018-10-27 14:27:41 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
case "device_tracker":
|
2019-06-23 14:53:11 +03:00
|
|
|
case "person":
|
2018-10-27 14:27:41 +03:00
|
|
|
{
|
2019-02-21 16:32:55 +02:00
|
|
|
badgeIcon = EntityIcon(
|
|
|
|
padding: EdgeInsets.all(0.0),
|
|
|
|
size: iconSize,
|
2020-04-04 18:44:06 +03:00
|
|
|
color: Theme.of(context).textTheme.body1.color
|
2019-02-21 16:32:55 +02:00
|
|
|
);
|
2019-06-23 15:24:08 +03:00
|
|
|
onBadgeTextValue = entityModel.entityWrapper.entity.displayState;
|
2018-10-27 14:27:41 +03:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
{
|
2019-06-23 14:53:11 +03:00
|
|
|
double stateFontSize;
|
2019-06-23 15:24:08 +03:00
|
|
|
if (entityModel.entityWrapper.entity.displayState.length <= 3) {
|
2019-06-23 14:53:11 +03:00
|
|
|
stateFontSize = 18.0;
|
2019-06-23 15:24:08 +03:00
|
|
|
} else if (entityModel.entityWrapper.entity.displayState.length <= 4) {
|
2019-06-23 14:53:11 +03:00
|
|
|
stateFontSize = 15.0;
|
2019-06-23 15:24:08 +03:00
|
|
|
} else if (entityModel.entityWrapper.entity.displayState.length <= 6) {
|
2019-06-23 14:53:11 +03:00
|
|
|
stateFontSize = 10.0;
|
2019-06-23 15:24:08 +03:00
|
|
|
} else if (entityModel.entityWrapper.entity.displayState.length <= 10) {
|
2019-06-23 14:53:11 +03:00
|
|
|
stateFontSize = 8.0;
|
|
|
|
}
|
2019-09-07 17:04:40 +03:00
|
|
|
onBadgeTextValue = entityModel.entityWrapper.unitOfMeasurement;
|
2019-02-10 22:33:46 +02:00
|
|
|
badgeIcon = Center(
|
|
|
|
child: Text(
|
2019-06-23 15:24:08 +03:00
|
|
|
"${entityModel.entityWrapper.entity.displayState}",
|
2019-02-10 22:33:46 +02:00
|
|
|
overflow: TextOverflow.fade,
|
|
|
|
softWrap: false,
|
|
|
|
textAlign: TextAlign.center,
|
2020-04-04 18:44:06 +03:00
|
|
|
style: Theme.of(context).textTheme.body1.copyWith(
|
|
|
|
fontSize: stateFontSize
|
|
|
|
)
|
2019-02-10 22:33:46 +02:00
|
|
|
),
|
|
|
|
);
|
|
|
|
break;
|
2018-10-27 14:27:41 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
Widget onBadgeText;
|
|
|
|
if (onBadgeTextValue == null || onBadgeTextValue.length == 0) {
|
|
|
|
onBadgeText = Container(width: 0.0, height: 0.0);
|
|
|
|
} else {
|
|
|
|
onBadgeText = Container(
|
|
|
|
padding: EdgeInsets.fromLTRB(6.0, 2.0, 6.0, 2.0),
|
|
|
|
child: Text("$onBadgeTextValue",
|
2020-04-04 18:13:55 +03:00
|
|
|
style: Theme.of(context).textTheme.overline.copyWith(
|
2020-04-07 00:39:16 +03:00
|
|
|
color: HAClientTheme().getOnBadgeTextColor()
|
2020-04-04 18:13:55 +03:00
|
|
|
),
|
2018-10-27 14:27:41 +03:00
|
|
|
textAlign: TextAlign.center,
|
|
|
|
softWrap: false,
|
|
|
|
overflow: TextOverflow.fade),
|
|
|
|
decoration: new BoxDecoration(
|
|
|
|
// Circle shape
|
|
|
|
//shape: BoxShape.circle,
|
|
|
|
color: iconColor,
|
|
|
|
borderRadius: BorderRadius.circular(9.0),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
return GestureDetector(
|
|
|
|
child: Column(
|
|
|
|
children: <Widget>[
|
|
|
|
Container(
|
|
|
|
margin: EdgeInsets.fromLTRB(0.0, 10.0, 0.0, 10.0),
|
|
|
|
width: 50.0,
|
|
|
|
height: 50.0,
|
|
|
|
decoration: new BoxDecoration(
|
|
|
|
// Circle shape
|
|
|
|
shape: BoxShape.circle,
|
2020-04-04 18:44:06 +03:00
|
|
|
color: Theme.of(context).cardColor,
|
2018-10-27 14:27:41 +03:00
|
|
|
// The border you want
|
|
|
|
border: new Border.all(
|
|
|
|
width: 2.0,
|
|
|
|
color: iconColor,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
child: Stack(
|
|
|
|
overflow: Overflow.visible,
|
|
|
|
children: <Widget>[
|
|
|
|
Positioned(
|
|
|
|
width: 46.0,
|
|
|
|
height: 46.0,
|
|
|
|
top: 0.0,
|
|
|
|
left: 0.0,
|
|
|
|
child: badgeIcon,
|
|
|
|
),
|
|
|
|
Positioned(
|
|
|
|
//width: 50.0,
|
|
|
|
bottom: -9.0,
|
|
|
|
left: -10.0,
|
|
|
|
right: -10.0,
|
|
|
|
child: Center(
|
|
|
|
child: onBadgeText,
|
|
|
|
))
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Container(
|
|
|
|
width: 60.0,
|
|
|
|
child: Text(
|
2018-11-16 22:32:43 +02:00
|
|
|
"${entityModel.entityWrapper.displayName}",
|
2018-10-27 14:27:41 +03:00
|
|
|
textAlign: TextAlign.center,
|
2020-04-04 18:13:55 +03:00
|
|
|
style: Theme.of(context).textTheme.caption,
|
2018-10-27 14:27:41 +03:00
|
|
|
softWrap: true,
|
|
|
|
maxLines: 3,
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
onTap: () =>
|
2020-05-01 21:50:50 +03:00
|
|
|
eventBus.fire(new ShowEntityPageEvent(entityId: entityModel.entityWrapper.entity.entityId)));
|
2018-10-27 14:27:41 +03:00
|
|
|
}
|
|
|
|
}
|