1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-10-23 15:03:22 +00:00
comunicmobile/lib/ui/tiles/comment_tile.dart

110 lines
2.7 KiB
Dart

import 'package:comunic/models/comment.dart';
import 'package:comunic/models/user.dart';
import 'package:comunic/ui/widgets/account_image_widget.dart';
import 'package:comunic/ui/widgets/network_image_widget.dart';
import 'package:comunic/utils/intl_utils.dart';
import 'package:flutter/material.dart';
/// Single comment tile
///
/// @author Pierre HUBERT
class CommentTile extends StatelessWidget {
final Comment comment;
final User user;
final void Function(Comment) onUpdateLike;
const CommentTile({
Key key,
@required this.comment,
@required this.user,
@required this.onUpdateLike,
}) : assert(comment != null),
assert(user != null),
assert(onUpdateLike != null),
super(key: key);
@override
Widget build(BuildContext context) {
return ListTile(
leading: AccountImageWidget(
user: user,
),
title: Text(
user.displayName,
),
subtitle: _buildCommentContent(),
);
}
Widget _buildCommentContent() {
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
// Comment image
Container(
child: comment.hasImage
? NetworkImageWidget(
url: comment.imageURL,
allowFullScreen: true,
height: 100.0,
width: null,
)
: null,
),
// Comment text
Container(
child: comment.hasContent
? Text(
comment.content,
style: TextStyle(color: Colors.black),
)
: null,
),
// Comment likes
_buildLikeButton(),
],
);
}
String get _likeString {
if (comment.likes == 0) return tr("Like");
if (comment.likes == 1)
return tr("1 Like");
else
return tr("%num% likes", args: {"num": comment.likes.toString()});
}
/// Build like button associated to this post
Widget _buildLikeButton() {
return Padding(
padding: const EdgeInsets.only(top: 4.0, bottom: 4.0),
child: Align(
alignment: AlignmentDirectional.topStart,
child: Column(
children: <Widget>[
InkWell(
onTap: () => onUpdateLike(comment),
child: Row(
children: <Widget>[
Icon(
Icons.thumb_up,
color: comment.userLike ? Colors.blue : null,
size: 15.0,
),
SizedBox(
width: 8.0,
),
Text(_likeString),
],
),
),
],
),
),
);
}
}