1
0
mirror of https://gitlab.com/comunic/comunicmobile synced 2025-06-19 00:05:16 +00:00

Display the list of comments

This commit is contained in:
2019-05-16 14:52:22 +02:00
parent be53a73d9f
commit 28de22f427
8 changed files with 198 additions and 10 deletions

View File

@ -0,0 +1,53 @@
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:flutter/material.dart';
/// Single comment tile
///
/// @author Pierre HUBERT
class CommentTile extends StatelessWidget {
final Comment comment;
final User user;
const CommentTile({Key key, this.comment, this.user})
: assert(comment != null),
assert(user != 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,
)
: null,
),
// Comment text
Container(
child: comment.hasContent ? Text(comment.content,) : null,
),
],
);
}
}

View File

@ -2,6 +2,7 @@ import 'package:comunic/enums/post_kind.dart';
import 'package:comunic/lists/users_list.dart';
import 'package:comunic/models/post.dart';
import 'package:comunic/models/user.dart';
import 'package:comunic/ui/tiles/comment_tile.dart';
import 'package:comunic/ui/widgets/account_image_widget.dart';
import 'package:comunic/ui/widgets/network_image_widget.dart';
import 'package:comunic/utils/date_utils.dart';
@ -124,17 +125,23 @@ class PostTile extends StatelessWidget {
Widget build(BuildContext context) {
return Card(
elevation: 1.0,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
children: <Widget>[
_buildHeaderRow(),
_buildContentRow(),
_buildButtonsArea(),
],
),
),
// Main post column
child: Column(
children: <Widget>[
_buildHeaderRow(),
_buildContentRow(),
_buildButtonsArea(),
],
),
Container(
child: post.hasComments ? _buildComments() : null,
),
],
),
);
}
@ -146,4 +153,27 @@ class PostTile extends StatelessWidget {
roundedEdges: false,
);
}
/// Build the list of comments
Widget _buildComments() {
assert(post.hasComments);
final comments = List.generate(
post.comments.length,
(num) => CommentTile(
comment: post.comments[num],
user: usersInfo.getUser(post.comments[num].userID),
),
);
return Container(
color: Colors.grey[300],
child: Padding(
padding: const EdgeInsets.only(top: 8.0, bottom: 8.0),
child: Column(
children: comments,
),
),
);
}
}