1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2024-11-22 21:09:21 +00:00
comunicmobile/lib/ui/tiles/comment_tile.dart

103 lines
2.4 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,
)
: 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 Align(
alignment: AlignmentDirectional.topStart,
child: FlatButton(
padding: EdgeInsets.only(left: 0.0),
onPressed: () => 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),
],
),
),
);
}
}