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 {
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,
width: size+12,
decoration: BoxDecoration(
@ -57,13 +71,32 @@ class EntityIcon extends StatelessWidget {
image: DecorationImage(
fit:BoxFit.cover,
image: CachedNetworkImageProvider(
"${entityWrapper.entityPicture}"
"${entityWrapper.entityPicture}",
),
)
),
);
);*/
isPicture = true;
} 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;
int iconCode = 0;
if (iconName.length > 0) {
@ -113,19 +146,6 @@ class EntityIcon extends StatelessWidget {
color: 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,
);
return iconWidget;
}
}

View File

@ -14,7 +14,7 @@ dependencies:
shared_preferences: ^0.5.6+1
path_provider: ^1.6.5
event_bus: ^1.1.1
cached_network_image: ^2.0.0
cached_network_image: ^2.3.0-beta
url_launcher: ^5.4.1
date_format: ^1.0.8
charts_flutter: ^0.8.1