Show entity icon on error loading entity picture
This commit is contained in:
parent
a6d1baca77
commit
1ed56ce8f1
@ -49,7 +49,21 @@ class EntityIcon extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
} else {
|
} else {
|
||||||
if (entityWrapper.entityPicture != null) {
|
if (entityWrapper.entityPicture != null) {
|
||||||
iconWidget = Container(
|
iconWidget = ClipOval(
|
||||||
|
child: CachedNetworkImage(
|
||||||
|
imageUrl: '${entityWrapper.entityPicture}',
|
||||||
|
width: size+12,
|
||||||
|
fit: BoxFit.cover,
|
||||||
|
height: size+12,
|
||||||
|
errorWidget: (context, str, dyn) {
|
||||||
|
return Padding(
|
||||||
|
padding: iconPadding ?? padding,
|
||||||
|
child: _buildIcon(entityWrapper, iconColor)
|
||||||
|
);
|
||||||
|
},
|
||||||
|
),
|
||||||
|
);
|
||||||
|
/*iconWidget = Container(
|
||||||
height: size+12,
|
height: size+12,
|
||||||
width: size+12,
|
width: size+12,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
@ -57,62 +71,14 @@ class EntityIcon extends StatelessWidget {
|
|||||||
image: DecorationImage(
|
image: DecorationImage(
|
||||||
fit:BoxFit.cover,
|
fit:BoxFit.cover,
|
||||||
image: CachedNetworkImageProvider(
|
image: CachedNetworkImageProvider(
|
||||||
"${entityWrapper.entityPicture}"
|
"${entityWrapper.entityPicture}",
|
||||||
),
|
),
|
||||||
)
|
)
|
||||||
),
|
),
|
||||||
);
|
);*/
|
||||||
isPicture = true;
|
isPicture = true;
|
||||||
} else {
|
} else {
|
||||||
String iconName = entityWrapper.icon;
|
iconWidget = _buildIcon(entityWrapper, iconColor);
|
||||||
int iconCode = 0;
|
|
||||||
if (iconName.length > 0) {
|
|
||||||
iconCode = MaterialDesignIcons.getIconCodeByIconName(iconName);
|
|
||||||
} else {
|
|
||||||
iconCode = getDefaultIconByEntityId(entityWrapper.entity.entityId,
|
|
||||||
entityWrapper.entity.deviceClass, entityWrapper.entity.state); //
|
|
||||||
}
|
|
||||||
if (showBadge && entityWrapper.entity is LightEntity &&
|
|
||||||
(entityWrapper.entity as LightEntity).supportColor &&
|
|
||||||
(entityWrapper.entity as LightEntity).color != null &&
|
|
||||||
(entityWrapper.entity as LightEntity).color.toColor() != Colors.white
|
|
||||||
) {
|
|
||||||
Color lightColor = (entityWrapper.entity as LightEntity).color.toColor();
|
|
||||||
iconWidget = Stack(
|
|
||||||
children: <Widget>[
|
|
||||||
Icon(
|
|
||||||
IconData(iconCode, fontFamily: 'Material Design Icons'),
|
|
||||||
size: size,
|
|
||||||
color: iconColor,
|
|
||||||
),
|
|
||||||
Positioned(
|
|
||||||
bottom: 0,
|
|
||||||
right: 0,
|
|
||||||
child: Container(
|
|
||||||
width: size / 3,
|
|
||||||
height: size / 3,
|
|
||||||
decoration: BoxDecoration(
|
|
||||||
color: lightColor,
|
|
||||||
shape: BoxShape.circle,
|
|
||||||
boxShadow: <BoxShadow>[
|
|
||||||
BoxShadow(
|
|
||||||
spreadRadius: 0,
|
|
||||||
blurRadius: 0,
|
|
||||||
offset: Offset(0.3, 0.3)
|
|
||||||
)
|
|
||||||
]
|
|
||||||
),
|
|
||||||
),
|
|
||||||
)
|
|
||||||
],
|
|
||||||
);
|
|
||||||
} else {
|
|
||||||
iconWidget = Icon(
|
|
||||||
IconData(iconCode, fontFamily: 'Material Design Icons'),
|
|
||||||
size: size,
|
|
||||||
color: iconColor,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
EdgeInsetsGeometry computedPadding;
|
EdgeInsetsGeometry computedPadding;
|
||||||
@ -128,4 +94,58 @@ class EntityIcon extends StatelessWidget {
|
|||||||
child: iconWidget,
|
child: iconWidget,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Widget _buildIcon(EntityWrapper entityWrapper, Color iconColor) {
|
||||||
|
Widget iconWidget;
|
||||||
|
String iconName = entityWrapper.icon;
|
||||||
|
int iconCode = 0;
|
||||||
|
if (iconName.length > 0) {
|
||||||
|
iconCode = MaterialDesignIcons.getIconCodeByIconName(iconName);
|
||||||
|
} else {
|
||||||
|
iconCode = getDefaultIconByEntityId(entityWrapper.entity.entityId,
|
||||||
|
entityWrapper.entity.deviceClass, entityWrapper.entity.state); //
|
||||||
|
}
|
||||||
|
if (showBadge && entityWrapper.entity is LightEntity &&
|
||||||
|
(entityWrapper.entity as LightEntity).supportColor &&
|
||||||
|
(entityWrapper.entity as LightEntity).color != null &&
|
||||||
|
(entityWrapper.entity as LightEntity).color.toColor() != Colors.white
|
||||||
|
) {
|
||||||
|
Color lightColor = (entityWrapper.entity as LightEntity).color.toColor();
|
||||||
|
iconWidget = Stack(
|
||||||
|
children: <Widget>[
|
||||||
|
Icon(
|
||||||
|
IconData(iconCode, fontFamily: 'Material Design Icons'),
|
||||||
|
size: size,
|
||||||
|
color: iconColor,
|
||||||
|
),
|
||||||
|
Positioned(
|
||||||
|
bottom: 0,
|
||||||
|
right: 0,
|
||||||
|
child: Container(
|
||||||
|
width: size / 3,
|
||||||
|
height: size / 3,
|
||||||
|
decoration: BoxDecoration(
|
||||||
|
color: lightColor,
|
||||||
|
shape: BoxShape.circle,
|
||||||
|
boxShadow: <BoxShadow>[
|
||||||
|
BoxShadow(
|
||||||
|
spreadRadius: 0,
|
||||||
|
blurRadius: 0,
|
||||||
|
offset: Offset(0.3, 0.3)
|
||||||
|
)
|
||||||
|
]
|
||||||
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
],
|
||||||
|
);
|
||||||
|
} else {
|
||||||
|
iconWidget = Icon(
|
||||||
|
IconData(iconCode, fontFamily: 'Material Design Icons'),
|
||||||
|
size: size,
|
||||||
|
color: iconColor,
|
||||||
|
);
|
||||||
|
}
|
||||||
|
return iconWidget;
|
||||||
|
}
|
||||||
}
|
}
|
@ -14,7 +14,7 @@ dependencies:
|
|||||||
shared_preferences: ^0.5.6+1
|
shared_preferences: ^0.5.6+1
|
||||||
path_provider: ^1.6.5
|
path_provider: ^1.6.5
|
||||||
event_bus: ^1.1.1
|
event_bus: ^1.1.1
|
||||||
cached_network_image: ^2.0.0
|
cached_network_image: ^2.3.0-beta
|
||||||
url_launcher: ^5.4.1
|
url_launcher: ^5.4.1
|
||||||
date_format: ^1.0.8
|
date_format: ^1.0.8
|
||||||
charts_flutter: ^0.8.1
|
charts_flutter: ^0.8.1
|
||||||
|
Reference in New Issue
Block a user