From 18bd85343a7a49c6b91ea09aaea5fef80dc3ef66 Mon Sep 17 00:00:00 2001 From: Salvatore Giordano Date: Tue, 31 Mar 2020 09:21:41 +0200 Subject: [PATCH] show error message on image error --- lib/src/message_widget.dart | 30 +++++++++++++++++++----------- pubspec.yaml | 6 +++--- 2 files changed, 22 insertions(+), 14 deletions(-) diff --git a/lib/src/message_widget.dart b/lib/src/message_widget.dart index 4067092a..8eaed2a5 100644 --- a/lib/src/message_widget.dart +++ b/lib/src/message_widget.dart @@ -879,21 +879,29 @@ class _MessageWidgetState extends State Widget _buildImage( Attachment attachment, ) { + final errorWidget = Container( + width: 200, + height: 140, + color: Color(0xffd0021B).withAlpha(26), + child: Center( + child: Icon( + Icons.error_outline, + color: Colors.white, + ), + ), + ); + + if (attachment.thumbUrl == null && + attachment.imageUrl == null && + attachment.assetUrl == null) { + return errorWidget; + } + return CachedNetworkImage( imageUrl: attachment.thumbUrl ?? attachment.imageUrl ?? attachment.assetUrl, errorWidget: (context, url, error) { - return Container( - width: 200, - height: 140, - color: Color(0xffd0021B).withAlpha(26), - child: Center( - child: Icon( - Icons.error_outline, - color: Colors.white, - ), - ), - ); + return errorWidget; }, fit: BoxFit.cover, ); diff --git a/pubspec.yaml b/pubspec.yaml index de2db30a..967cbc81 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -16,10 +16,10 @@ dependencies: url_launcher: ^5.4.2 video_player: ^0.10.8+1 chewie: ^0.9.10 - file_picker: ^1.5.0 - image_picker: ^0.6.3+4 + file_picker: ^1.5.1 + image_picker: ^0.6.4 keyboard_visibility: ^0.5.6 - stream_chat: ^0.1.19 + stream_chat: ^0.1.21 visibility_detector: ^0.1.4 dev_dependencies: