Fix light card with wrong domain entity. Show custom cards if there is entitites
This commit is contained in:
parent
44c28ad106
commit
f9b2d7d84c
@ -90,6 +90,12 @@ class CardData {
|
|||||||
return BadgesData(rawData);
|
return BadgesData(rawData);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
if (rawData.containsKey('entity')) {
|
||||||
|
rawData['entities'] = [rawData['entity']];
|
||||||
|
}
|
||||||
|
if (rawData.containsKey('entities') && rawData['entities'] is List) {
|
||||||
|
return EntitiesCardData(rawData);
|
||||||
|
}
|
||||||
return CardData(null);
|
return CardData(null);
|
||||||
}
|
}
|
||||||
} catch (error, stacktrace) {
|
} catch (error, stacktrace) {
|
||||||
@ -374,8 +380,14 @@ class LightCardData extends CardData {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget buildCardWidget() {
|
Widget buildCardWidget() {
|
||||||
|
if (this.entity != null && this.entity.entity is LightEntity) {
|
||||||
return LightCard(card: this);
|
return LightCard(card: this);
|
||||||
}
|
}
|
||||||
|
return ErrorCard(
|
||||||
|
errorText: 'Specify an entity from within the light domain.',
|
||||||
|
showReportButton: false,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
LightCardData(rawData) : super(rawData) {
|
LightCardData(rawData) : super(rawData) {
|
||||||
//Parsing card data
|
//Parsing card data
|
||||||
|
@ -2,12 +2,21 @@ part of '../main.dart';
|
|||||||
|
|
||||||
class ErrorCard extends StatelessWidget {
|
class ErrorCard extends StatelessWidget {
|
||||||
final ErrorCardData card;
|
final ErrorCardData card;
|
||||||
|
final String errorText;
|
||||||
|
final bool showReportButton;
|
||||||
|
|
||||||
const ErrorCard({Key key, this.card}) : super(key: key);
|
const ErrorCard({Key key, this.card, this.errorText, this.showReportButton: true}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
|
String error;
|
||||||
|
if (errorText == null) {
|
||||||
|
error = 'There was an error showing ${card?.type}';
|
||||||
|
} else {
|
||||||
|
error = errorText;
|
||||||
|
}
|
||||||
return CardWrapper(
|
return CardWrapper(
|
||||||
|
color: Theme.of(context).errorColor,
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: EdgeInsets.fromLTRB(Sizes.leftWidgetPadding, Sizes.rowPadding, Sizes.rightWidgetPadding, Sizes.rowPadding),
|
padding: EdgeInsets.fromLTRB(Sizes.leftWidgetPadding, Sizes.rowPadding, Sizes.rightWidgetPadding, Sizes.rowPadding),
|
||||||
child: Column(
|
child: Column(
|
||||||
@ -15,21 +24,25 @@ class ErrorCard extends StatelessWidget {
|
|||||||
crossAxisAlignment: CrossAxisAlignment.center,
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
Text(
|
Text(
|
||||||
'There was an error rendering card: ${card.type}. Please copy card config to clipboard and report this issue. Thanks!',
|
error,
|
||||||
textAlign: TextAlign.center,
|
textAlign: TextAlign.center,
|
||||||
),
|
),
|
||||||
|
card != null ?
|
||||||
RaisedButton(
|
RaisedButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
Clipboard.setData(new ClipboardData(text: card.cardConfig));
|
Clipboard.setData(new ClipboardData(text: card.cardConfig));
|
||||||
},
|
},
|
||||||
child: Text('Copy card config'),
|
child: Text('Copy card config'),
|
||||||
),
|
) :
|
||||||
|
Container(width: 0, height: 0),
|
||||||
|
showReportButton ?
|
||||||
RaisedButton(
|
RaisedButton(
|
||||||
onPressed: () {
|
onPressed: () {
|
||||||
Launcher.launchURLInBrowser("https://github.com/estevez-dev/ha_client/issues/new?assignees=&labels=&template=bug_report.md&title=");
|
Launcher.launchURLInBrowser("https://github.com/estevez-dev/ha_client/issues/new?assignees=&labels=&template=bug_report.md&title=");
|
||||||
},
|
},
|
||||||
child: Text('Report issue'),
|
child: Text('Report issue'),
|
||||||
)
|
) :
|
||||||
|
Container(width: 0, height: 0)
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
|
@ -7,6 +7,6 @@ class UnsupportedCard extends StatelessWidget {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Container();
|
return Container(height: 20);
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -4,12 +4,14 @@ class CardWrapper extends StatelessWidget {
|
|||||||
|
|
||||||
final Widget child;
|
final Widget child;
|
||||||
final EdgeInsets padding;
|
final EdgeInsets padding;
|
||||||
|
final Color color;
|
||||||
|
|
||||||
const CardWrapper({Key key, this.child, this.padding: const EdgeInsets.all(0)}) : super(key: key);
|
const CardWrapper({Key key, this.child, this.color, this.padding: const EdgeInsets.all(0)}) : super(key: key);
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return Card(
|
return Card(
|
||||||
|
color: color,
|
||||||
child: Padding(
|
child: Padding(
|
||||||
padding: padding,
|
padding: padding,
|
||||||
child: child
|
child: child
|
||||||
|
Reference in New Issue
Block a user