1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-22 12:59:21 +00:00

Can enlarge conversation images

This commit is contained in:
Pierre HUBERT 2019-04-26 11:34:24 +02:00
parent afd999400e
commit eb5b6d6fae
2 changed files with 43 additions and 27 deletions

View File

@ -3,6 +3,7 @@ import 'package:comunic/models/conversation_message.dart';
import 'package:comunic/models/user.dart'; import 'package:comunic/models/user.dart';
import 'package:comunic/utils/account_utils.dart'; import 'package:comunic/utils/account_utils.dart';
import 'package:comunic/utils/date_utils.dart'; import 'package:comunic/utils/date_utils.dart';
import 'package:comunic/utils/ui_utils.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
/// Conversation message tile /// Conversation message tile
@ -47,31 +48,34 @@ class ConversationMessageTile extends StatelessWidget {
} }
/// Build widget image /// Build widget image
Widget _buildMessageImage() { Widget _buildMessageImage(BuildContext context) {
return Container( return Container(
margin: EdgeInsets.only(bottom: 2), margin: EdgeInsets.only(bottom: 2),
child: Material( child: Material(
child: CachedNetworkImage( child: InkWell(
imageUrl: message.imageURL, onTap: (){showImageFullScreen(context, message.imageURL);},
width: 200.0, child: CachedNetworkImage(
height: 200.0, imageUrl: message.imageURL,
fit: BoxFit.cover, width: 200.0,
placeholder: (c, s) => Container( height: 200.0,
width: 200, fit: BoxFit.cover,
height: 200, placeholder: (c, s) => Container(
color: Colors.lightBlueAccent, width: 200,
child: Center( height: 200,
child: CircularProgressIndicator(), color: Colors.lightBlueAccent,
child: Center(
child: CircularProgressIndicator(),
),
), ),
), errorWidget: (c, s, o) => Container(
errorWidget: (c, s, o) => Container( width: 200,
width: 200, height: 200,
height: 200, color: Colors.red,
color: Colors.red, child: Center(
child: Center( child: Icon(Icons.error, color: Colors.white,)
child: Icon(Icons.error, color: Colors.white,) ),
), ),
), ),
), ),
borderRadius: BorderRadius.all(Radius.circular(8.0)), borderRadius: BorderRadius.all(Radius.circular(8.0)),
clipBehavior: Clip.hardEdge, clipBehavior: Clip.hardEdge,
@ -94,7 +98,7 @@ class ConversationMessageTile extends StatelessWidget {
} }
/// Build a message of the current user /// Build a message of the current user
Widget _buildRightMessage() { Widget _buildRightMessage(BuildContext context) {
return Container( return Container(
margin: EdgeInsets.only(bottom: isLastMessage ? 20.0 : 10.0), margin: EdgeInsets.only(bottom: isLastMessage ? 20.0 : 10.0),
child: Row( child: Row(
@ -108,7 +112,7 @@ class ConversationMessageTile extends StatelessWidget {
children: <Widget>[ children: <Widget>[
// Text image // Text image
Container( Container(
child: message.hasImage ? _buildMessageImage() : null, child: message.hasImage ? _buildMessageImage(context) : null,
), ),
// Text message // Text message
@ -152,7 +156,7 @@ class ConversationMessageTile extends StatelessWidget {
} }
/// Build a message of a peer user /// Build a message of a peer user
Widget _buildLeftMessage() { Widget _buildLeftMessage(BuildContext context) {
return Container( return Container(
margin: EdgeInsets.only(bottom: isLastMessage ? 20.0 : 5.0), margin: EdgeInsets.only(bottom: isLastMessage ? 20.0 : 5.0),
child: Column( child: Column(
@ -179,7 +183,7 @@ class ConversationMessageTile extends StatelessWidget {
children: <Widget>[ children: <Widget>[
// Text image // Text image
Container( Container(
child: message.hasImage ? _buildMessageImage() : null, child: message.hasImage ? _buildMessageImage(context) : null,
), ),
// Text message // Text message
@ -221,7 +225,7 @@ class ConversationMessageTile extends StatelessWidget {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return userID() == message.userID return userID() == message.userID
? _buildRightMessage() ? _buildRightMessage(context)
: _buildLeftMessage(); : _buildLeftMessage(context);
} }
} }

View File

@ -1,3 +1,4 @@
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
/// User interface utilities /// User interface utilities
@ -9,7 +10,6 @@ Widget buildCenteredProgressBar() {
); );
} }
/// Build and return a full loading page /// Build and return a full loading page
Widget buildLoadingPage() { Widget buildLoadingPage() {
return Scaffold( return Scaffold(
@ -48,3 +48,15 @@ Widget buildErrorCard(String message, {List<Widget> 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,
);
}));
}