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

Created a tile to quickly show user account image

This commit is contained in:
Pierre HUBERT 2019-04-27 14:19:39 +02:00
parent 91b5d55a83
commit 09d43ab5c0
2 changed files with 67 additions and 16 deletions

View File

@ -1,6 +1,7 @@
import 'package:cached_network_image/cached_network_image.dart'; import 'package:cached_network_image/cached_network_image.dart';
import 'package:comunic/models/conversation_message.dart'; import 'package:comunic/models/conversation_message.dart';
import 'package:comunic/models/user.dart'; import 'package:comunic/models/user.dart';
import 'package:comunic/ui/widgets/account_image_widget.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:comunic/utils/ui_utils.dart';
@ -32,17 +33,9 @@ class ConversationMessageTile extends StatelessWidget {
Widget _buildAccountImage() { Widget _buildAccountImage() {
return Container( return Container(
margin: EdgeInsets.all(10.0), margin: EdgeInsets.all(10.0),
child: Material( child: AccountImageWidget(
child: CachedNetworkImage( user: userInfo,
imageUrl: userInfo.accountImageURL, width: 35.0,
width: 35.0,
height: 35.0,
fit: BoxFit.cover,
),
borderRadius: BorderRadius.all(
Radius.circular(18.0),
),
clipBehavior: Clip.hardEdge,
), ),
); );
} }
@ -53,7 +46,9 @@ class ConversationMessageTile extends StatelessWidget {
margin: EdgeInsets.only(bottom: 2), margin: EdgeInsets.only(bottom: 2),
child: Material( child: Material(
child: InkWell( child: InkWell(
onTap: (){showImageFullScreen(context, message.imageURL);}, onTap: () {
showImageFullScreen(context, message.imageURL);
},
child: CachedNetworkImage( child: CachedNetworkImage(
imageUrl: message.imageURL, imageUrl: message.imageURL,
width: 200.0, width: 200.0,
@ -72,8 +67,10 @@ class ConversationMessageTile extends StatelessWidget {
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,
)),
), ),
), ),
), ),
@ -112,7 +109,9 @@ class ConversationMessageTile extends StatelessWidget {
children: <Widget>[ children: <Widget>[
// Text image // Text image
Container( Container(
child: message.hasImage ? _buildMessageImage(context) : null, child: message.hasImage
? _buildMessageImage(context)
: null,
), ),
// Text message // Text message
@ -183,7 +182,8 @@ class ConversationMessageTile extends StatelessWidget {
children: <Widget>[ children: <Widget>[
// Text image // Text image
Container( Container(
child: message.hasImage ? _buildMessageImage(context) : null, child:
message.hasImage ? _buildMessageImage(context) : null,
), ),
// Text message // Text message

View File

@ -0,0 +1,51 @@
import 'package:cached_network_image/cached_network_image.dart';
import 'package:comunic/models/user.dart';
import 'package:flutter/material.dart';
/// Account image widget
///
/// This widget is intended to only show a user account image
///
/// @author Pierre HUBERT
class AccountImageWidget extends StatelessWidget {
final User user;
final double width;
const AccountImageWidget({Key key, this.user, this.width = 35.0})
: assert(user != null),
super(key: key);
@override
Widget build(BuildContext context) {
return Material(
child: CachedNetworkImage(
imageUrl: user.accountImageURL,
width: width,
height: width,
fit: BoxFit.cover,
placeholder: (c, s) => Container(
color: Colors.grey,
width: width,
height: width,
child: CircularProgressIndicator(
strokeWidth: 7.0,
),
),
errorWidget: (c, s, o) => Container(
color: Colors.red,
width: width,
height: width,
child: Icon(
Icons.error,
color: Colors.white,
),
),
),
borderRadius: BorderRadius.all(
Radius.circular(18.0),
),
clipBehavior: Clip.hardEdge,
);
}
}