Show entity icon on error loading entity picture

This commit is contained in:
Yegor Vialov 2020-05-22 13:31:07 +00:00
parent a6d1baca77
commit 1ed56ce8f1
2 changed files with 73 additions and 53 deletions

View File

@ -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,13 +71,32 @@ 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 {
iconWidget = _buildIcon(entityWrapper, iconColor);
}
}
EdgeInsetsGeometry computedPadding;
if (isPicture && imagePadding != null) {
computedPadding = imagePadding;
} else if (!isPicture && iconPadding != null) {
computedPadding = iconPadding;
} else {
computedPadding = padding;
}
return Padding(
padding: computedPadding,
child: iconWidget,
);
}
Widget _buildIcon(EntityWrapper entityWrapper, Color iconColor) {
Widget iconWidget;
String iconName = entityWrapper.icon; String iconName = entityWrapper.icon;
int iconCode = 0; int iconCode = 0;
if (iconName.length > 0) { if (iconName.length > 0) {
@ -113,19 +146,6 @@ class EntityIcon extends StatelessWidget {
color: iconColor, color: iconColor,
); );
} }
} return iconWidget;
}
EdgeInsetsGeometry computedPadding;
if (isPicture && imagePadding != null) {
computedPadding = imagePadding;
} else if (!isPicture && iconPadding != null) {
computedPadding = iconPadding;
} else {
computedPadding = padding;
}
return Padding(
padding: computedPadding,
child: iconWidget,
);
} }
} }

View File

@ -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