Repository navigation
Expand file tree
/
Copy pathReposItem.dart
More file actions
148 lines (135 loc) · 5.26 KB
/
Copy pathReposItem.dart
File metadata and controls
148 lines (135 loc) · 5.26 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
import 'package:flutter/material.dart';
import 'package:gsy_github_app_flutter/common/model/Repository.dart';
import 'package:gsy_github_app_flutter/common/style/GSYStyle.dart';
import 'package:gsy_github_app_flutter/common/utils/NavigatorUtils.dart';
import 'package:gsy_github_app_flutter/widget/GSYCardItem.dart';
import 'package:gsy_github_app_flutter/widget/GSYIConText.dart';
import 'package:gsy_github_app_flutter/widget/GSYUserIconWidget.dart';
/**
* 仓库Item
* Created by guoshuyu
* Date: 2018-07-16
*/
class ReposItem extends StatelessWidget {
final ReposViewModel reposViewModel;
final VoidCallback onPressed;
ReposItem(this.reposViewModel, {this.onPressed}) : super();
///仓库item的底部状态,比如star数量等
_getBottomItem(IconData icon, String text, {int flex = 2}) {
return new Expanded(
flex: flex,
child: new Center(
child: new GSYIConText(
icon,
text,
GSYConstant.smallSubText,
Color(GSYColors.subTextColor),
15.0,
padding: 5.0,
),
),
);
}
@override
Widget build(BuildContext context) {
return new Container(
child: new GSYCardItem(
child: new FlatButton(
onPressed: onPressed,
child: new Padding(
padding: new EdgeInsets.only(left: 0.0, top: 10.0, right: 10.0, bottom: 10.0),
child: new Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
new Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
///头像
new GSYUserIconWidget(
padding: const EdgeInsets.only(top: 0.0, right: 5.0, left: 0.0),
width: 40.0,
height: 40.0,
image: reposViewModel.ownerPic,
onPressed: () {
NavigatorUtils.goPerson(context, reposViewModel.ownerName);
}),
new Expanded(
child: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
///仓库名
new Text(reposViewModel.repositoryName, style: GSYConstant.normalTextBold),
///用户名
new GSYIConText(
GSYICons.REPOS_ITEM_USER,
reposViewModel.ownerName,
GSYConstant.smallSubLightText,
Color(GSYColors.subLightTextColor),
10.0,
padding: 3.0,
),
],
),
),
///仓库语言
new Text(reposViewModel.repositoryType, style: GSYConstant.smallSubText),
],
),
new Container(
///仓库描述
child: new Text(
reposViewModel.repositoryDes,
style: GSYConstant.smallSubText,
maxLines: 3,
overflow: TextOverflow.ellipsis,
),
margin: new EdgeInsets.only(top: 6.0, bottom: 2.0),
alignment: Alignment.topLeft),
new Padding(padding: EdgeInsets.all(10.0)),
///仓库状态数值
new Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
_getBottomItem(GSYICons.REPOS_ITEM_STAR, reposViewModel.repositoryStar),
_getBottomItem(GSYICons.REPOS_ITEM_FORK, reposViewModel.repositoryFork),
_getBottomItem(GSYICons.REPOS_ITEM_ISSUE, reposViewModel.repositoryWatch, flex: 4),
],
),
],
),
))),
);
}
}
class ReposViewModel {
String ownerName;
String ownerPic;
String repositoryName;
String repositoryStar;
String repositoryFork;
String repositoryWatch;
String hideWatchIcon;
String repositoryType = "";
String repositoryDes;
ReposViewModel();
ReposViewModel.fromMap(Repository data) {
ownerName = data.owner.login;
ownerPic = data.owner.avatar_url;
repositoryName = data.name;
repositoryStar = data.watchersCount.toString();
repositoryFork = data.forksCount.toString();
repositoryWatch = data.openIssuesCount.toString();
repositoryType = data.language ?? '---';
repositoryDes = data.description ?? '---';
}
ReposViewModel.fromTrendMap(model) {
ownerName = model.name;
ownerPic = model.contributors[0];
repositoryName = model.reposName;
repositoryStar = model.starCount;
repositoryFork = model.forkCount;
repositoryWatch = model.meta;
repositoryType = model.language;
repositoryDes = model.description;
}
}