From eb5b6d6faee6ba4c2c3949d2c86c9deb528ec640 Mon Sep 17 00:00:00 2001 From: Pierre HUBERT Date: Fri, 26 Apr 2019 11:34:24 +0200 Subject: [PATCH] Can enlarge conversation images --- lib/ui/tiles/conversation_message_tile.dart | 56 +++++++++++---------- lib/utils/ui_utils.dart | 14 +++++- 2 files changed, 43 insertions(+), 27 deletions(-) diff --git a/lib/ui/tiles/conversation_message_tile.dart b/lib/ui/tiles/conversation_message_tile.dart index 87921da..6e4a73f 100644 --- a/lib/ui/tiles/conversation_message_tile.dart +++ b/lib/ui/tiles/conversation_message_tile.dart @@ -3,6 +3,7 @@ import 'package:comunic/models/conversation_message.dart'; import 'package:comunic/models/user.dart'; import 'package:comunic/utils/account_utils.dart'; import 'package:comunic/utils/date_utils.dart'; +import 'package:comunic/utils/ui_utils.dart'; import 'package:flutter/material.dart'; /// Conversation message tile @@ -47,31 +48,34 @@ class ConversationMessageTile extends StatelessWidget { } /// Build widget image - Widget _buildMessageImage() { + Widget _buildMessageImage(BuildContext context) { return Container( margin: EdgeInsets.only(bottom: 2), child: Material( - child: CachedNetworkImage( - imageUrl: message.imageURL, - width: 200.0, - height: 200.0, - fit: BoxFit.cover, - placeholder: (c, s) => Container( - width: 200, - height: 200, - color: Colors.lightBlueAccent, - child: Center( - child: CircularProgressIndicator(), + child: InkWell( + onTap: (){showImageFullScreen(context, message.imageURL);}, + child: CachedNetworkImage( + imageUrl: message.imageURL, + width: 200.0, + height: 200.0, + fit: BoxFit.cover, + placeholder: (c, s) => Container( + width: 200, + height: 200, + color: Colors.lightBlueAccent, + child: Center( + child: CircularProgressIndicator(), + ), ), - ), - errorWidget: (c, s, o) => Container( - width: 200, - height: 200, - color: Colors.red, - child: Center( - child: Icon(Icons.error, color: Colors.white,) + errorWidget: (c, s, o) => Container( + width: 200, + height: 200, + color: Colors.red, + child: Center( + child: Icon(Icons.error, color: Colors.white,) + ), ), - ), + ), ), borderRadius: BorderRadius.all(Radius.circular(8.0)), clipBehavior: Clip.hardEdge, @@ -94,7 +98,7 @@ class ConversationMessageTile extends StatelessWidget { } /// Build a message of the current user - Widget _buildRightMessage() { + Widget _buildRightMessage(BuildContext context) { return Container( margin: EdgeInsets.only(bottom: isLastMessage ? 20.0 : 10.0), child: Row( @@ -108,7 +112,7 @@ class ConversationMessageTile extends StatelessWidget { children: [ // Text image Container( - child: message.hasImage ? _buildMessageImage() : null, + child: message.hasImage ? _buildMessageImage(context) : null, ), // Text message @@ -152,7 +156,7 @@ class ConversationMessageTile extends StatelessWidget { } /// Build a message of a peer user - Widget _buildLeftMessage() { + Widget _buildLeftMessage(BuildContext context) { return Container( margin: EdgeInsets.only(bottom: isLastMessage ? 20.0 : 5.0), child: Column( @@ -179,7 +183,7 @@ class ConversationMessageTile extends StatelessWidget { children: [ // Text image Container( - child: message.hasImage ? _buildMessageImage() : null, + child: message.hasImage ? _buildMessageImage(context) : null, ), // Text message @@ -221,7 +225,7 @@ class ConversationMessageTile extends StatelessWidget { @override Widget build(BuildContext context) { return userID() == message.userID - ? _buildRightMessage() - : _buildLeftMessage(); + ? _buildRightMessage(context) + : _buildLeftMessage(context); } } diff --git a/lib/utils/ui_utils.dart b/lib/utils/ui_utils.dart index 0c9dd12..e72ee61 100644 --- a/lib/utils/ui_utils.dart +++ b/lib/utils/ui_utils.dart @@ -1,3 +1,4 @@ +import 'package:cached_network_image/cached_network_image.dart'; import 'package:flutter/material.dart'; /// User interface utilities @@ -9,7 +10,6 @@ Widget buildCenteredProgressBar() { ); } - /// Build and return a full loading page Widget buildLoadingPage() { return Scaffold( @@ -48,3 +48,15 @@ Widget buildErrorCard(String message, {List actions}) { ), ); } + +/// Show an image with a given [url] in full screen +void showImageFullScreen(BuildContext context, String url) { + Navigator.of(context).push(MaterialPageRoute(builder: (c) { + + // TODO : add better support later + return CachedNetworkImage( + imageUrl: url, + ); + + })); +}