2018-10-27 17:28:47 +03:00
|
|
|
part of '../main.dart';
|
|
|
|
|
|
|
|
class MediaControlCardWidget extends StatelessWidget {
|
|
|
|
|
|
|
|
final HACard card;
|
|
|
|
|
|
|
|
const MediaControlCardWidget({
|
|
|
|
Key key,
|
|
|
|
this.card
|
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2018-11-11 18:36:49 +02:00
|
|
|
if ((card.linkedEntity == null) || (card.linkedEntity.isHidden)) {
|
2018-10-27 17:28:47 +03:00
|
|
|
return Container(width: 0.0, height: 0.0,);
|
|
|
|
}
|
|
|
|
List<Widget> body = [];
|
2018-11-11 18:36:49 +02:00
|
|
|
if (homeAssistantWebHost != null) {
|
|
|
|
body.add(Stack(
|
|
|
|
alignment: AlignmentDirectional.topEnd,
|
|
|
|
children: <Widget>[
|
|
|
|
_buildImage(),
|
|
|
|
Positioned(
|
|
|
|
bottom: 0.0,
|
|
|
|
left: 0.0,
|
|
|
|
right: 0.0,
|
|
|
|
child: Container(
|
|
|
|
height: 80.0,
|
2018-11-11 18:49:04 +02:00
|
|
|
color: Colors.black45,
|
2018-11-11 18:36:49 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
Positioned(
|
|
|
|
bottom: 0.0,
|
|
|
|
left: 0.0,
|
|
|
|
child: _buildState(),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
));
|
|
|
|
}
|
2018-10-27 17:28:47 +03:00
|
|
|
return Card(
|
2018-11-11 18:36:49 +02:00
|
|
|
child: Column(
|
|
|
|
//crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: body
|
2018-10-27 17:28:47 +03:00
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2018-11-11 18:36:49 +02:00
|
|
|
Widget _buildState() {
|
|
|
|
TextStyle style = TextStyle(
|
|
|
|
fontSize: 14.0,
|
|
|
|
color: Colors.white,
|
|
|
|
fontWeight: FontWeight.normal,
|
|
|
|
height: 1.2
|
|
|
|
);
|
|
|
|
List<Widget> states = [];
|
|
|
|
states.add(Text("${card.linkedEntity.displayName}", style: style));
|
2018-11-11 18:49:04 +02:00
|
|
|
String state = card.linkedEntity.state;
|
|
|
|
if (state == null || state == "off" || state == "unavailable" || state == "idle") {
|
2018-11-11 18:36:49 +02:00
|
|
|
states.add(Text("${card.linkedEntity.state}", style: style.apply(fontSizeDelta: 4.0),));
|
|
|
|
} else {
|
|
|
|
states.add(Text("${card.linkedEntity.attributes['media_title'] ?? '-'}", style: style.apply(fontSizeDelta: 6.0, fontWeightDelta: 50),));
|
|
|
|
states.add(Text("${card.linkedEntity.attributes['media_artist'] ?? '-'}", style: style.apply(fontSizeDelta: 4.0),));
|
|
|
|
}
|
|
|
|
return Padding(
|
|
|
|
padding: EdgeInsets.only(left: Entity.leftWidgetPadding, right: Entity.rightWidgetPadding),
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: states,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget _buildImage() {
|
2018-11-11 18:49:04 +02:00
|
|
|
String state = card.linkedEntity.state;
|
|
|
|
if (homeAssistantWebHost != null && card.linkedEntity.entityPicture != null && state != "off" && state != "unavailable" && state != "idle") {
|
2018-11-11 18:36:49 +02:00
|
|
|
return Row(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: <Widget>[
|
|
|
|
Image(
|
|
|
|
image: CachedNetworkImageProvider("$homeAssistantWebHost${card.linkedEntity.entityPicture}"),
|
|
|
|
height: 300.0,
|
|
|
|
)
|
|
|
|
],
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return Container(
|
|
|
|
color: Colors.blue,
|
|
|
|
height: 80.0,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-10-27 17:28:47 +03:00
|
|
|
}
|