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