* move comment out of `widgets/`
* remove `Widget` suffix from widgets * change `list.length != 0` to `list.isEmpty` * convert MarkdownText into stateless widget
This commit is contained in:
parent
e1608d9f32
commit
eee965fba1
|
@ -1,14 +1,14 @@
|
|||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'comment_tree.dart';
|
||||
import 'markdown_text.dart';
|
||||
import 'widgets/comment_tree.dart';
|
||||
import 'widgets/markdown_text.dart';
|
||||
|
||||
class CommentWidget extends StatelessWidget {
|
||||
class Comment extends StatelessWidget {
|
||||
final int indent;
|
||||
final int postCreatorId;
|
||||
final CommentTree commentTree;
|
||||
CommentWidget(
|
||||
Comment(
|
||||
this.commentTree, {
|
||||
this.indent = 0,
|
||||
@required this.postCreatorId,
|
||||
|
@ -47,8 +47,7 @@ class CommentWidget extends StatelessWidget {
|
|||
style: TextStyle(fontStyle: FontStyle.italic),
|
||||
));
|
||||
} else {
|
||||
body =
|
||||
Flexible(child: MarkdownText(commentTree.comment.content, context));
|
||||
body = Flexible(child: MarkdownText(commentTree.comment.content));
|
||||
}
|
||||
return Column(
|
||||
children: [
|
||||
|
@ -108,7 +107,7 @@ class CommentWidget extends StatelessWidget {
|
|||
top: BorderSide(width: 0.2))),
|
||||
),
|
||||
for (var c in commentTree.children)
|
||||
CommentWidget(
|
||||
Comment(
|
||||
c,
|
||||
indent: indent + 1,
|
||||
postCreatorId: postCreatorId,
|
|
@ -2,24 +2,25 @@ 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.dart';
|
||||
import 'comment_tree.dart';
|
||||
|
||||
/// Manages comments section, sorts them
|
||||
class CommentsWidget extends HookWidget {
|
||||
class Comments extends HookWidget {
|
||||
final List<CommentView> rawComments;
|
||||
final List<CommentTree> comments;
|
||||
final int postCreatorId;
|
||||
|
||||
CommentsWidget(this.rawComments, this.postCreatorId)
|
||||
: comments = CommentTree.fromList(rawComments);
|
||||
Comments(this.rawComments, {@required this.postCreatorId})
|
||||
: comments = CommentTree.fromList(rawComments),
|
||||
assert(postCreatorId != null);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
var sorting = useState(SortType.active);
|
||||
return Column(children: [
|
||||
// sorting menu goes here
|
||||
if (comments.length == 0)
|
||||
if (comments.isEmpty)
|
||||
Padding(
|
||||
padding: EdgeInsets.symmetric(vertical: 50),
|
||||
child: Text(
|
||||
|
@ -27,8 +28,7 @@ class CommentsWidget extends HookWidget {
|
|||
style: TextStyle(fontStyle: FontStyle.italic),
|
||||
),
|
||||
),
|
||||
for (var com in comments)
|
||||
CommentWidget(com, postCreatorId: postCreatorId),
|
||||
for (var com in comments) Comment(com, postCreatorId: postCreatorId),
|
||||
]);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,23 +1,37 @@
|
|||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_markdown/flutter_markdown.dart';
|
||||
import 'package:markdown/markdown.dart' as md;
|
||||
|
||||
import '../url_launcher.dart';
|
||||
|
||||
Widget MarkdownText(String text, BuildContext context) {
|
||||
return MarkdownBody(
|
||||
data: text,
|
||||
extensionSet: md.ExtensionSet.gitHubWeb,
|
||||
onTapLink: (href) {
|
||||
urlLauncher(href)
|
||||
.catchError((e) => Scaffold.of(context).showSnackBar(SnackBar(
|
||||
content: Row(
|
||||
children: [
|
||||
Icon(Icons.warning),
|
||||
Text('couldn\'t open link'),
|
||||
],
|
||||
),
|
||||
)));
|
||||
},
|
||||
);
|
||||
class MarkdownText extends StatelessWidget {
|
||||
final String text;
|
||||
MarkdownText(this.text);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) => MarkdownBody(
|
||||
data: text,
|
||||
extensionSet: md.ExtensionSet.gitHubWeb,
|
||||
onTapLink: (href) {
|
||||
urlLauncher(href)
|
||||
.catchError((e) => Scaffold.of(context).showSnackBar(SnackBar(
|
||||
content: Row(
|
||||
children: [
|
||||
Icon(Icons.warning),
|
||||
Text('couldn\'t open link'),
|
||||
],
|
||||
),
|
||||
)));
|
||||
},
|
||||
imageBuilder: (uri, title, alt) => CachedNetworkImage(
|
||||
imageUrl: uri.toString(),
|
||||
errorWidget: (context, url, error) => Row(
|
||||
children: [
|
||||
Icon(Icons.warning),
|
||||
Text('couldn\'t load image, ${error.toString()}')
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -25,7 +25,7 @@ MediaType whatType(String url) {
|
|||
return MediaType.other;
|
||||
}
|
||||
|
||||
class PostWidget extends StatelessWidget {
|
||||
class Post extends StatelessWidget {
|
||||
final PostView post;
|
||||
final String hostUrl;
|
||||
|
||||
|
@ -35,7 +35,7 @@ class PostWidget extends StatelessWidget {
|
|||
ThemeData _theme;
|
||||
BuildContext _context;
|
||||
|
||||
PostWidget(this.post)
|
||||
Post(this.post)
|
||||
: hostUrl = post.communityActorId.split('/')[2],
|
||||
linkPostDomain = post.url != null ? post.url.split('/')[2] : null;
|
||||
|
||||
|
@ -327,7 +327,7 @@ class PostWidget extends StatelessWidget {
|
|||
Widget _textBody() {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.all(10),
|
||||
child: MarkdownText(post.body, _context),
|
||||
child: MarkdownText(post.body),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue