Add comment actions
This commit is contained in:
parent
b13508c011
commit
e44b6cf10f
|
@ -1,5 +1,6 @@
|
||||||
import 'package:cached_network_image/cached_network_image.dart';
|
import 'package:cached_network_image/cached_network_image.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:lemmy_api_client/lemmy_api_client.dart';
|
||||||
import 'package:timeago/timeago.dart' as timeago;
|
import 'package:timeago/timeago.dart' as timeago;
|
||||||
|
|
||||||
import '../comment_tree.dart';
|
import '../comment_tree.dart';
|
||||||
|
@ -16,16 +17,34 @@ class Comment extends StatelessWidget {
|
||||||
@required this.postCreatorId,
|
@required this.postCreatorId,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
void _openMoreMenu() {
|
||||||
|
print('OPEN MORE MENU');
|
||||||
|
}
|
||||||
|
|
||||||
void _goToUser() {
|
void _goToUser() {
|
||||||
print('GO TO USER');
|
print('GO TO USER');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void _save(bool save) {
|
||||||
|
print('SAVE COMMENT, $save');
|
||||||
|
}
|
||||||
|
|
||||||
|
void _reply() {
|
||||||
|
print('OPEN REPLY BOX');
|
||||||
|
}
|
||||||
|
|
||||||
|
void _vote(VoteType vote) {
|
||||||
|
print('COMMENT VOTE: ${vote.toString()}');
|
||||||
|
}
|
||||||
|
|
||||||
bool get isOP => commentTree.comment.creatorId == postCreatorId;
|
bool get isOP => commentTree.comment.creatorId == postCreatorId;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final comment = commentTree.comment;
|
final comment = commentTree.comment;
|
||||||
|
|
||||||
|
final saved = comment.saved ?? false;
|
||||||
|
|
||||||
// decide which username to use
|
// decide which username to use
|
||||||
final username = () {
|
final username = () {
|
||||||
if (comment.creatorPreferredUsername != null &&
|
if (comment.creatorPreferredUsername != null &&
|
||||||
|
@ -100,7 +119,31 @@ class Comment extends StatelessWidget {
|
||||||
Row(children: [body]),
|
Row(children: [body]),
|
||||||
Row(children: [
|
Row(children: [
|
||||||
Spacer(),
|
Spacer(),
|
||||||
// actions go here
|
_CommentAction(
|
||||||
|
icon: Icons.more_horiz,
|
||||||
|
onPressed: _openMoreMenu,
|
||||||
|
tooltip: 'more',
|
||||||
|
),
|
||||||
|
_CommentAction(
|
||||||
|
icon: saved ? Icons.bookmark : Icons.bookmark_border,
|
||||||
|
onPressed: () => _save(!saved),
|
||||||
|
tooltip: '${saved ? 'unsave' : 'save'} comment',
|
||||||
|
),
|
||||||
|
_CommentAction(
|
||||||
|
icon: Icons.reply,
|
||||||
|
onPressed: _reply,
|
||||||
|
tooltip: 'reply',
|
||||||
|
),
|
||||||
|
_CommentAction(
|
||||||
|
icon: Icons.arrow_upward,
|
||||||
|
onPressed: () => _vote(VoteType.up),
|
||||||
|
tooltip: 'upvote',
|
||||||
|
),
|
||||||
|
_CommentAction(
|
||||||
|
icon: Icons.arrow_downward,
|
||||||
|
onPressed: () => _vote(VoteType.down),
|
||||||
|
tooltip: 'downvote',
|
||||||
|
),
|
||||||
])
|
])
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
@ -148,3 +191,30 @@ class CommentTag extends StatelessWidget {
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class _CommentAction extends StatelessWidget {
|
||||||
|
final IconData icon;
|
||||||
|
final void Function() onPressed;
|
||||||
|
final String tooltip;
|
||||||
|
|
||||||
|
const _CommentAction({
|
||||||
|
Key key,
|
||||||
|
@required this.icon,
|
||||||
|
@required this.onPressed,
|
||||||
|
@required this.tooltip,
|
||||||
|
}) : super(key: key);
|
||||||
|
|
||||||
|
@override
|
||||||
|
Widget build(BuildContext context) => IconButton(
|
||||||
|
constraints: BoxConstraints.tight(Size(32, 26)),
|
||||||
|
icon: Icon(
|
||||||
|
icon,
|
||||||
|
color: Theme.of(context).iconTheme.color.withAlpha(190),
|
||||||
|
),
|
||||||
|
splashRadius: 25,
|
||||||
|
onPressed: onPressed,
|
||||||
|
iconSize: 22,
|
||||||
|
tooltip: tooltip,
|
||||||
|
padding: EdgeInsets.all(0),
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue