Skip to content

Commit

Permalink
.
Browse files Browse the repository at this point in the history
  • Loading branch information
EluvK authored Dec 23, 2024
1 parent b629114 commit d5a14d0
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 33 deletions.
5 changes: 1 addition & 4 deletions lib/components/post_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -130,10 +130,7 @@ class _PostCardState extends State<PostCard> {
});
postController.editLocalPostStatus(post);
}
Get.toNamed('/view-post', arguments: [
post.id,
post.author == settingController.currentUserId.value
]);
Get.toNamed('/view-post', arguments: [post]);
},
minLeadingWidth: 0,
leading: Column(
Expand Down
55 changes: 32 additions & 23 deletions lib/components/post_viewer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,26 @@ class _PostViewerState extends State<PostViewer> {
Widget build(BuildContext context) {
return FutureBuilder<Post>(
future: postController.getPostUnwrap(widget.postId),
builder: (context, AsyncSnapshot<Post> post) {
if (post.hasData) {
builder: (context, AsyncSnapshot<Post> getPost) {
if (getPost.hasData) {
var post = getPost.data!;
return Padding(
padding: const EdgeInsets.all(12.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
_title(post.data!),
// todo tags maybe?
// title:
Text(
"${post.category} | ${detailedDateStr(post.updatedAt)}",
style: const TextStyle(fontSize: 13),
),
const Divider(),
Expanded(child: _content(post.data!.content)),
// content:
Expanded(
child: ListView(
children: [MarkdownRenderer(data: post.content)],
),
),
],
),
);
Expand All @@ -40,23 +49,23 @@ class _PostViewerState extends State<PostViewer> {
});
}

Widget _title(Post post) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
post.title,
style: const TextStyle(fontSize: 22),
),
Text(
"${post.category} | ${detailedDateStr(post.updatedAt)}",
style: const TextStyle(fontSize: 13),
),
],
);
}
// Widget _title(Post post) {
// return Column(
// crossAxisAlignment: CrossAxisAlignment.start,
// children: [
// Text(
// post.title,
// style: const TextStyle(fontSize: 22),
// ),
// Text(
// "${post.category} | ${detailedDateStr(post.updatedAt)}",
// style: const TextStyle(fontSize: 13),
// ),
// ],
// );
// }

Widget _content(String content) {
return ListView(children: [MarkdownRenderer(data: content)]);
}
// Widget _content(String content) {
// return ListView(children: [MarkdownRenderer(data: content)]);
// }
}
14 changes: 9 additions & 5 deletions lib/pages/view_post.dart
Original file line number Diff line number Diff line change
@@ -1,31 +1,35 @@
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:xbb/components/post_viewer.dart';
import 'package:xbb/controller/setting.dart';
import 'package:xbb/model/post.dart';

class ViewPostPage extends StatelessWidget {
const ViewPostPage({super.key});

@override
Widget build(BuildContext context) {
final args = Get.arguments;
final String postId = args[0];
final bool editable = args[1];
final Post post = args[0];
final settingController = Get.find<SettingController>();
// todo
bool editable = (post.author == settingController.currentUserId.value);
return Scaffold(
appBar: AppBar(
title: const Text('viewPost'),
title: Text('view_post'.trParams({"postName": post.title})),
actions: [
Visibility(
visible: editable,
child: IconButton(
onPressed: () {
Get.toNamed('/edit-post', arguments: [postId]);
Get.toNamed('/edit-post', arguments: [post.id]);
},
icon: const Icon(Icons.edit),
),
),
],
),
body: PostViewer(postId: postId),
body: PostViewer(postId: post.id),
);
}
}
4 changes: 4 additions & 0 deletions lib/utils/translation.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ class _TranslationHelper {
"en_US": "Edit Post `@postName`",
"zh_CN": "修改 `@postName`",
},
"view_post": {
"en_US": "@postName",
"zh_CN": "@postName",
},
"update_failed": {
"en_US": "Update Failed",
"zh_CN": "更新失败",
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.
version: 0.0.6+73
version: 0.0.7+75

environment:
sdk: ^3.5.1
Expand Down

0 comments on commit d5a14d0

Please sign in to comment.