Add fit option for EntityPicture widget

This commit is contained in:
Yegor Vialov 2020-03-14 18:23:39 +00:00
parent 7e09d92fdf
commit bf53e4b9df
2 changed files with 9 additions and 3 deletions

View File

@ -105,14 +105,18 @@ class _CameraStreamViewState extends State<CameraStreamView> {
Widget screenWidget; Widget screenWidget;
if (!_isLoaded) { if (!_isLoaded) {
screenWidget = Center( screenWidget = Center(
child: EntityPicture() child: EntityPicture(
fit: BoxFit.contain,
)
); );
} else if (_entity.supportStream) { } else if (_entity.supportStream) {
if (_videoPlayerController.value.initialized) { if (_videoPlayerController.value.initialized) {
screenWidget = VideoPlayer(_videoPlayerController); screenWidget = VideoPlayer(_videoPlayerController);
} else { } else {
screenWidget = Center( screenWidget = Center(
child: EntityPicture() child: EntityPicture(
fit: BoxFit.contain,
)
); );
} }
} else { } else {

View File

@ -3,8 +3,9 @@ part of '../main.dart';
class EntityPicture extends StatelessWidget { class EntityPicture extends StatelessWidget {
final EdgeInsetsGeometry padding; final EdgeInsetsGeometry padding;
final BoxFit fit;
const EntityPicture({Key key, this.padding: const EdgeInsets.all(0.0)}) : super(key: key); const EntityPicture({Key key, this.padding: const EdgeInsets.all(0.0), this.fit: BoxFit.cover}) : super(key: key);
int getDefaultIconByEntityId(String entityId, String deviceClass, String state) { int getDefaultIconByEntityId(String entityId, String deviceClass, String state) {
String domain = entityId.split(".")[0]; String domain = entityId.split(".")[0];
@ -47,6 +48,7 @@ class EntityPicture extends StatelessWidget {
if (data.entityPicture != null) { if (data.entityPicture != null) {
return CachedNetworkImage( return CachedNetworkImage(
imageUrl: data.entityPicture, imageUrl: data.entityPicture,
fit: this.fit,
errorWidget: (context, _, __) => iconPicture, errorWidget: (context, _, __) => iconPicture,
placeholder: (context, _) => iconPicture, placeholder: (context, _) => iconPicture,
); );