forked from CarGuo/gsy_github_app_flutter
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathissue_item.dart
More file actions
166 lines (151 loc) · 5.33 KB
/
issue_item.dart
File metadata and controls
166 lines (151 loc) · 5.33 KB
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
import 'package:flutter/material.dart';
import 'package:gsy_github_app_flutter/common/model/Issue.dart';
import 'package:gsy_github_app_flutter/common/style/gsy_style.dart';
import 'package:gsy_github_app_flutter/common/utils/common_utils.dart';
import 'package:gsy_github_app_flutter/common/utils/navigator_utils.dart';
import 'package:gsy_github_app_flutter/widget/gsy_card_item.dart';
import 'package:gsy_github_app_flutter/widget/gsy_icon_text.dart';
import 'package:gsy_github_app_flutter/widget/gsy_markdown_widget.dart';
import 'package:gsy_github_app_flutter/widget/gsy_user_icon_widget.dart';
/**
* Issue相关item
* Created by guoshuyu
* Date: 2018-07-19
*/
class IssueItem extends StatelessWidget {
final IssueItemViewModel issueItemViewModel;
///点击
final GestureTapCallback onPressed;
///长按
final GestureTapCallback onLongPress;
///是否需要底部状态
final bool hideBottom;
///是否需要限制内容行数
final bool limitComment;
IssueItem(this.issueItemViewModel, {this.onPressed, this.onLongPress, this.hideBottom = false, this.limitComment = true});
///issue 底部状态
_renderBottomContainer() {
Color issueStateColor = issueItemViewModel.state == "open" ? Colors.green : Colors.red;
return (hideBottom)
? new Container()
: new Row(
children: <Widget>[
///issue 关闭打开状态
new GSYIConText(
GSYICons.ISSUE_ITEM_ISSUE,
issueItemViewModel.state,
TextStyle(
color: issueStateColor,
fontSize: GSYConstant.smallTextSize,
),
issueStateColor,
15.0,
padding: 2.0,
),
new Padding(padding: new EdgeInsets.all(2.0)),
///issue标号
new Expanded(
child: new Text(issueItemViewModel.issueTag, style: GSYConstant.smallSubText),
),
///评论数
new GSYIConText(
GSYICons.ISSUE_ITEM_COMMENT,
issueItemViewModel.commentCount,
GSYConstant.smallSubText,
Color(GSYColors.subTextColor),
15.0,
padding: 2.0,
),
],
);
}
///评论内容
_renderCommentText() {
return (limitComment)
? new Container(
child: new Text(
issueItemViewModel.issueComment,
style: GSYConstant.smallSubText,
maxLines: limitComment ? 2 : 1000,
),
margin: new EdgeInsets.only(top: 6.0, bottom: 2.0),
alignment: Alignment.topLeft,
)
: GSYMarkdownWidget(markdownData: issueItemViewModel.issueComment);
}
@override
Widget build(BuildContext context) {
return new GSYCardItem(
child: new InkWell(
onTap: onPressed,
onLongPress: onLongPress,
child: new Padding(
padding: new EdgeInsets.only(left: 5.0, top: 5.0, right: 10.0, bottom: 8.0),
child: new Row(crossAxisAlignment: CrossAxisAlignment.start, children: <Widget>[
///头像
new GSYUserIconWidget(
width: 30.0,
height: 30.0,
image: issueItemViewModel.actionUserPic,
onPressed: () {
NavigatorUtils.goPerson(context, issueItemViewModel.actionUser);
}),
new Expanded(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
new Row(
children: <Widget>[
///用户名
new Expanded(child: new Text(issueItemViewModel.actionUser, style: GSYConstant.smallTextBold)),
new Text(
issueItemViewModel.actionTime,
style: GSYConstant.smallSubText,
maxLines: 2,
overflow: TextOverflow.ellipsis,
),
],
),
///评论内容
_renderCommentText(),
new Padding(
padding: new EdgeInsets.only(left: 0.0, top: 2.0, right: 0.0, bottom: 0.0),
),
_renderBottomContainer(),
],
),
),
]),
),
),
);
}
}
class IssueItemViewModel {
String actionTime = "---";
String actionUser = "---";
String actionUserPic = "---";
String issueComment = "---";
String commentCount = "---";
String state = "---";
String issueTag = "---";
String number = "---";
String id = "";
IssueItemViewModel();
IssueItemViewModel.fromMap(Issue issueMap, {needTitle = true}) {
String fullName = CommonUtils.getFullName(issueMap.repoUrl);
actionTime = CommonUtils.getNewsTimeStr(issueMap.createdAt);
actionUser = issueMap.user.login;
actionUserPic = issueMap.user.avatar_url;
if (needTitle) {
issueComment = fullName + "- " + issueMap.title;
commentCount = issueMap.commentNum.toString();
state = issueMap.state;
issueTag = "#" + issueMap.number.toString();
number = issueMap.number.toString();
} else {
issueComment = issueMap.body ?? "";
id = issueMap.id.toString();
}
}
}