1
0
mirror of https://github.com/git-touch/git-touch synced 2025-02-21 22:07:51 +01:00

refactor: repository item

This commit is contained in:
Rongjian Zhang 2020-01-29 13:06:55 +08:00
parent df09ee4c17
commit 6ffef6eaf6
7 changed files with 81 additions and 80 deletions

View File

@ -40,19 +40,17 @@ class GiteaUserScreen extends StatelessWidget {
), ),
CommonStyle.border, CommonStyle.border,
Column( Column(
children: repos.map((v) { children: <Widget>[
return RepositoryItem( for (var v in repos)
v.owner.login, RepositoryItem(
v.owner.avatarUrl, owner: v.owner.login,
v.name, avatarUrl: v.owner.avatarUrl,
v.description, name: v.name,
v.starsCount, description: v.description,
v.forksCount, starCount: v.starsCount,
null, forkCount: v.forksCount,
null, )
null, ],
);
}).toList(),
) )
], ],
); );

View File

@ -60,19 +60,17 @@ class GitlabUserScreen extends StatelessWidget {
), ),
CommonStyle.border, CommonStyle.border,
Column( Column(
children: projects.map((v) { children: <Widget>[
return RepositoryItem( for (var v in projects)
v.owner.name, RepositoryItem(
v.owner.avatarUrl, owner: v.owner.username,
v.name, avatarUrl: v.owner.avatarUrl,
v.description, name: v.name,
v.starCount, description: v.description,
v.forksCount, starCount: v.starCount,
null, forkCount: v.forksCount,
null, )
null, ],
);
}).toList(),
) )
], ],
); );

View File

@ -64,15 +64,15 @@ class RepositoriesScreen extends StatelessWidget {
onLoadMore: (cursor) => _query(context, cursor), onLoadMore: (cursor) => _query(context, cursor),
itemBuilder: (v) { itemBuilder: (v) {
return RepositoryItem.gh( return RepositoryItem.gh(
v.owner.login, owner: v.owner.login,
v.owner.avatarUrl, avatarUrl: v.owner.avatarUrl,
v.name, name: v.name,
v.description, description: v.description,
v.stargazers.totalCount, starCount: v.stargazers.totalCount,
v.forks.totalCount, forkCount: v.forks.totalCount,
v.primaryLanguage?.name, primaryLanguageName: v.primaryLanguage?.name,
v.primaryLanguage?.color, primaryLanguageColor: v.primaryLanguage?.color,
'Updated ${timeago.format(v.updatedAt)}', note: 'Updated ${timeago.format(v.updatedAt)}',
isPrivate: v.isPrivate, isPrivate: v.isPrivate,
isFork: v.isFork, isFork: v.isFork,
); );

View File

@ -166,15 +166,19 @@ class _SearchScreenState extends State<SearchScreen> {
case 0: case 0:
final updatedAt = timeago.format(DateTime.parse(p['updatedAt'])); final updatedAt = timeago.format(DateTime.parse(p['updatedAt']));
return RepositoryItem.gh( return RepositoryItem.gh(
p['owner']['login'], owner: p['owner']['login'],
p['owner']['avatarUrl'], avatarUrl: p['owner']['avatarUrl'],
p['name'], name: p['name'],
p['description'], description: p['description'],
p['stargazers']['totalCount'], starCount: p['stargazers']['totalCount'],
p['forks']['totalCount'], forkCount: p['forks']['totalCount'],
p['primaryLanguage'] == null ? null : p['primaryLanguage']['name'], primaryLanguageName: p['primaryLanguage'] == null
p['primaryLanguage'] == null ? null : p['primaryLanguage']['color'], ? null
'Updated $updatedAt', : p['primaryLanguage']['name'],
primaryLanguageColor: p['primaryLanguage'] == null
? null
: p['primaryLanguage']['color'],
note: 'Updated $updatedAt',
isPrivate: p['isPrivate'], isPrivate: p['isPrivate'],
isFork: p['isFork'], isFork: p['isFork'],
); );

View File

@ -32,15 +32,17 @@ class TrendingScreen extends StatelessWidget {
case 0: case 0:
final item = GithubTrendingItem.fromJson(v); final item = GithubTrendingItem.fromJson(v);
return RepositoryItem.gh( return RepositoryItem.gh(
item.author, owner: item.author,
item.avatar, avatarUrl: item.avatar,
item.name, name: item.name,
item.description, description: item.description,
item.stars ?? 0, starCount: item.stars ?? 0,
item.forks ?? 0, forkCount: item.forks ?? 0,
item.language, primaryLanguageName: item.language,
item.languageColor, primaryLanguageColor: item.languageColor,
'${item.currentPeriodStars} stars today', note: '${item.currentPeriodStars} stars today',
isPrivate: false,
isFork: false, // TODO:
); );
case 1: case 1:
final item = GithubTrendingUser.fromJson(v); final item = GithubTrendingUser.fromJson(v);

View File

@ -67,15 +67,14 @@ class UserScreen extends StatelessWidget {
CommonStyle.border, CommonStyle.border,
items.map((v) { items.map((v) {
return RepositoryItem.gh( return RepositoryItem.gh(
v.owner.login, owner: v.owner.login,
v.owner.avatarUrl, avatarUrl: v.owner.avatarUrl,
v.name, name: v.name,
v.description, description: v.description,
v.stargazers.totalCount, starCount: v.stargazers.totalCount,
v.forks.totalCount, forkCount: v.forks.totalCount,
v.primaryLanguage?.name, primaryLanguageName: v.primaryLanguage?.name,
v.primaryLanguage?.color, primaryLanguageColor: v.primaryLanguage?.color,
null,
isPrivate: v.isPrivate, isPrivate: v.isPrivate,
isFork: v.isFork, isFork: v.isFork,
); );

View File

@ -18,31 +18,31 @@ class RepositoryItem extends StatelessWidget {
final String primaryLanguageColor; final String primaryLanguageColor;
final String note; final String note;
RepositoryItem( RepositoryItem({
this.owner, @required this.owner,
this.avatarUrl, @required this.avatarUrl,
this.name, @required this.name,
this.description, @required this.description,
this.starCount, @required this.starCount,
this.forkCount, @required this.forkCount,
this.primaryLanguageName, this.primaryLanguageName,
this.primaryLanguageColor, this.primaryLanguageColor,
this.note, { this.note,
this.iconData, this.iconData,
}); });
RepositoryItem.gh( RepositoryItem.gh({
this.owner, @required this.owner,
this.avatarUrl, @required this.avatarUrl,
this.name, @required this.name,
this.description, @required this.description,
this.starCount, @required this.starCount,
this.forkCount, @required this.forkCount,
this.primaryLanguageName, this.primaryLanguageName,
this.primaryLanguageColor, this.primaryLanguageColor,
this.note, { this.note,
bool isPrivate, @required bool isPrivate,
bool isFork, @required bool isFork,
}) : this.iconData = _buildIconData(isPrivate, isFork); }) : this.iconData = _buildIconData(isPrivate, isFork);
static IconData _buildIconData(bool isPrivate, bool isFork) { static IconData _buildIconData(bool isPrivate, bool isFork) {