Add 2 widgets for displaying comments #16
This commit is contained in:
parent
712ea2994d
commit
3bb56a71dd
|
@ -0,0 +1,49 @@
|
|||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'comment_tree.dart';
|
||||
|
||||
class CommentWidget extends StatelessWidget {
|
||||
final int indent;
|
||||
final CommentTree commentTree;
|
||||
CommentWidget(
|
||||
this.commentTree, {
|
||||
this.indent = 0,
|
||||
});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var comment = commentTree.comment;
|
||||
return Column(
|
||||
children: [
|
||||
Container(
|
||||
child: Column(
|
||||
children: [
|
||||
Row(children: [
|
||||
Text(comment.creatorPreferredUsername ?? comment.creatorName),
|
||||
Spacer(),
|
||||
Text(comment.score.toString()),
|
||||
]),
|
||||
Row(children: [
|
||||
Flexible(child: Text(commentTree.comment.content)),
|
||||
]),
|
||||
Row(children: [
|
||||
Spacer(),
|
||||
// actions go here
|
||||
])
|
||||
],
|
||||
),
|
||||
padding: EdgeInsets.all(10),
|
||||
margin: EdgeInsets.only(left: indent > 1 ? (indent - 1) * 5.0 : 0),
|
||||
decoration: BoxDecoration(
|
||||
border: Border(
|
||||
left: indent > 0
|
||||
? BorderSide(color: Colors.red, width: 5)
|
||||
: BorderSide.none,
|
||||
top: BorderSide(width: 0.2))),
|
||||
),
|
||||
for (var c in commentTree.children)
|
||||
CommentWidget(c, indent: indent + 1),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:lemmy_api_client/lemmy_api_client.dart';
|
||||
|
||||
import 'comment.dart';
|
||||
import 'comment_tree.dart';
|
||||
|
||||
/// Manages comments section, sorts them
|
||||
class CommentsWidget extends HookWidget {
|
||||
final List<CommentView> rawComments;
|
||||
final List<CommentTree> comments;
|
||||
|
||||
CommentsWidget(this.rawComments)
|
||||
: comments = CommentTree.fromList(rawComments);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(children: [
|
||||
// sorting menu goes here
|
||||
for (var com in comments) CommentWidget(com),
|
||||
]);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue