lemmur-app-android/lib/widgets/comment.dart

76 lines
2.0 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
import 'comment_tree.dart';
2020-08-31 12:23:32 +02:00
import 'markdown_text.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;
2020-08-31 13:39:27 +02:00
// decide which username to use
var username;
if (comment.creatorPreferredUsername != null &&
comment.creatorPreferredUsername != '') {
username = comment.creatorPreferredUsername;
} else {
username = '@${comment.creatorName}';
}
2020-08-31 12:23:32 +02:00
var body;
if (comment.deleted) {
body = Flexible(
child: Text(
'comment deleted by creator',
style: TextStyle(fontStyle: FontStyle.italic),
));
} else if (comment.removed) {
body = Flexible(
child: Text(
'comment deleted by moderator',
style: TextStyle(fontStyle: FontStyle.italic),
));
} else {
body =
Flexible(child: MarkdownText(commentTree.comment.content, context));
}
return Column(
children: [
Container(
child: Column(
children: [
Row(children: [
Text(comment.creatorPreferredUsername ?? comment.creatorName),
Spacer(),
Text(comment.score.toString()),
]),
2020-08-31 12:23:32 +02:00
Row(children: [body]),
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),
],
);
}
}