-
Notifications
You must be signed in to change notification settings - Fork 13
/
post_list_item.dart
127 lines (121 loc) · 3.89 KB
/
post_list_item.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
import 'package:clientf/enginf_clientf_service/enginf.post.model.dart';
import 'package:clientf/globals.dart';
import 'package:clientf/pages/post_list/widgets/comment_box.dart';
import 'package:clientf/pages/post_list/widgets/comment_list.dart';
import 'package:clientf/services/app.defines.dart';
import 'package:clientf/services/app.i18n.dart';
import 'package:clientf/services/app.service.dart';
import 'package:flutter/material.dart';
class PostListItem extends StatefulWidget {
PostListItem(
this.post, {
Key key,
}) : super(key: key);
final EnginePost post;
@override
_PostListItemState createState() => _PostListItemState();
}
class _PostListItemState extends State<PostListItem> {
bool showContent = true;
bool showCommentBox = true;
@override
@override
Widget build(BuildContext context) {
// if ( widget.post == null ) return SizedBox.shrink();
if (showContent) {
return Column(
children: <Widget>[
Padding(
padding: EdgeInsets.all(20),
child: Column(
children: <Widget>[
Text(
'title: ${widget.post.title}',
style: TextStyle(fontSize: 32),
),
Text('author: ${widget.post.uid}'),
Text('created: ${widget.post.createdAt}'),
Text('content: ${widget.post.content}'),
],
),
),
Row(
children: <Widget>[
RaisedButton(
onPressed: () {
setState(() {
showCommentBox = !showCommentBox;
});
},
child: Text('Reply'),
),
RaisedButton(
onPressed: () async {
print('go to edit page:');
print(widget.post);
final EnginePost post = await open(AppRoutes.postUpdate,
arguments: {'post': widget.post});
/// TODO: update post list after updating a post.
print(post);
},
child: Text('Edit'),
),
RaisedButton(
onPressed: () async {
print(widget.post);
//// 여기서 부터. 게시글 삭제. 게시글 삭제 후. 코멘트 CRUD.
AppService.confirm(
title: 'confirm',
content: 'do you want to delete?',
onYes: () async {
// print('yes');
try {
final re = await app.f.postDelete(widget.post.id);
print(re);
if (re.deletedAt is int) {
AppService.alert(null, t('post deleted'));
}
} catch (e) {}
},
onNo: () {
// print('no');
},
);
},
child: Text('Delete'),
),
RaisedButton(
onPressed: () {
setState(() {
showContent = false;
});
},
child: Text('Close'),
),
],
),
if (showCommentBox)
CommentBox(
widget.post,
key: ValueKey(widget.post.id),
),
CommentList(widget.post)
],
);
} else {
return ListTile(
title: Padding(
padding: EdgeInsets.only(top: 20.0, bottom: 20.0),
/// This padding is for testing.
child: Text(widget.post.title ?? 'No title'),
),
trailing: Icon(Icons.keyboard_arrow_down),
onTap: () {
setState(() {
showContent = true;
});
},
);
}
}
}