refactor: use list extension
This commit is contained in:
parent
b65ce98077
commit
7ca3fe03c5
|
@ -30,60 +30,58 @@ class GhTrendingScreen extends StatelessWidget {
|
|||
bodyBuilder: (payload, activeTab) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: join(
|
||||
CommonStyle.border,
|
||||
activeTab == 0
|
||||
? [
|
||||
for (var v in payload.cast<GithubTrendingRepository>())
|
||||
RepoItem.gh(
|
||||
owner: v.author,
|
||||
avatarUrl: v.avatar,
|
||||
name: v.name,
|
||||
description: v.description,
|
||||
starCount: v.stars ?? 0,
|
||||
forkCount: v.forks ?? 0,
|
||||
primaryLanguageName: v.language,
|
||||
primaryLanguageColor: v.languageColor,
|
||||
note: '${v.currentPeriodStars} stars today',
|
||||
isPrivate: false,
|
||||
isFork: false, // TODO:
|
||||
)
|
||||
]
|
||||
: [
|
||||
for (var v in payload.cast<GithubTrendingDeveloper>())
|
||||
UserItem.github(
|
||||
login: v.username,
|
||||
name: v.name,
|
||||
avatarUrl: v.avatar,
|
||||
bio: v.repo == null
|
||||
? null
|
||||
: LinkWidget(
|
||||
url: '/github/${v.username}/${v.repo!.name}',
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Icon(
|
||||
Octicons.repo,
|
||||
size: 17,
|
||||
color: AntTheme.of(context)
|
||||
.colorTextSecondary,
|
||||
),
|
||||
const SizedBox(width: 4),
|
||||
Expanded(
|
||||
child: Text(
|
||||
'${v.username} / ${v.repo!.name}',
|
||||
style: TextStyle(
|
||||
fontSize: 17,
|
||||
children: (activeTab == 0
|
||||
? [
|
||||
for (var v in payload.cast<GithubTrendingRepository>())
|
||||
RepoItem.gh(
|
||||
owner: v.author,
|
||||
avatarUrl: v.avatar,
|
||||
name: v.name,
|
||||
description: v.description,
|
||||
starCount: v.stars ?? 0,
|
||||
forkCount: v.forks ?? 0,
|
||||
primaryLanguageName: v.language,
|
||||
primaryLanguageColor: v.languageColor,
|
||||
note: '${v.currentPeriodStars} stars today',
|
||||
isPrivate: false,
|
||||
isFork: false, // TODO:
|
||||
)
|
||||
]
|
||||
: [
|
||||
for (var v in payload.cast<GithubTrendingDeveloper>())
|
||||
UserItem.github(
|
||||
login: v.username,
|
||||
name: v.name,
|
||||
avatarUrl: v.avatar,
|
||||
bio: v.repo == null
|
||||
? null
|
||||
: LinkWidget(
|
||||
url: '/github/${v.username}/${v.repo!.name}',
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Icon(
|
||||
Octicons.repo,
|
||||
size: 17,
|
||||
color: AntTheme.of(context)
|
||||
.colorTextSecondary,
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))
|
||||
],
|
||||
const SizedBox(width: 4),
|
||||
Expanded(
|
||||
child: Text(
|
||||
'${v.username} / ${v.repo!.name}',
|
||||
style: TextStyle(
|
||||
fontSize: 17,
|
||||
color: AntTheme.of(context)
|
||||
.colorTextSecondary,
|
||||
),
|
||||
overflow: TextOverflow.ellipsis,
|
||||
))
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
)
|
||||
])
|
||||
.withSeparator(CommonStyle.border),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
|
|
@ -77,32 +77,17 @@ class GithubPalette {
|
|||
// final pageSize = 5;
|
||||
const kPageSize = 30;
|
||||
|
||||
List<T> join<T>(T seperator, List<T> xs) {
|
||||
final result = <T>[];
|
||||
xs.asMap().forEach((index, x) {
|
||||
if (x == null) return;
|
||||
|
||||
result.add(x);
|
||||
if (index < xs.length - 1) {
|
||||
result.add(seperator);
|
||||
extension MyList on List {
|
||||
List<T> withSeparator<T>(T separator) {
|
||||
final result = <T>[];
|
||||
for (var i = 0; i < length; i++) {
|
||||
if (i != 0) {
|
||||
result.add(separator);
|
||||
}
|
||||
result.add(this[i]);
|
||||
}
|
||||
});
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
List<T> joinAll<T>(T seperator, List<List<T>> xss) {
|
||||
final result = <T>[];
|
||||
xss.asMap().forEach((index, x) {
|
||||
if (x.isEmpty) return;
|
||||
|
||||
result.addAll(x);
|
||||
if (index < xss.length - 1) {
|
||||
result.add(seperator);
|
||||
}
|
||||
});
|
||||
|
||||
return result;
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
final numberFormat = NumberFormat();
|
||||
|
|
|
@ -56,7 +56,7 @@ class EventItem extends StatelessWidget {
|
|||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: join(const SizedBox(height: 6), [
|
||||
children: [
|
||||
Text.rich(
|
||||
TextSpan(
|
||||
style: TextStyle(
|
||||
|
@ -81,7 +81,7 @@ class EventItem extends StatelessWidget {
|
|||
],
|
||||
),
|
||||
if (card != null) card
|
||||
]),
|
||||
].withSeparator(const SizedBox(height: 6)),
|
||||
),
|
||||
),
|
||||
],
|
||||
|
@ -233,7 +233,7 @@ class EventItem extends StatelessWidget {
|
|||
borderRadius: const BorderRadius.all(Radius.circular(4))),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: join(const SizedBox(height: 6), [
|
||||
children: [
|
||||
Row(
|
||||
children: <Widget>[
|
||||
IssueIcon(state, size: 20),
|
||||
|
@ -285,7 +285,7 @@ class EventItem extends StatelessWidget {
|
|||
]
|
||||
],
|
||||
)
|
||||
]),
|
||||
].withSeparator(const SizedBox(height: 6)),
|
||||
),
|
||||
),
|
||||
);
|
||||
|
|
|
@ -68,7 +68,7 @@ class IssueItem extends StatelessWidget {
|
|||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: join(const SizedBox(height: 8), [
|
||||
children: [
|
||||
Text.rich(
|
||||
TextSpan(
|
||||
children: [
|
||||
|
@ -129,7 +129,7 @@ class IssueItem extends StatelessWidget {
|
|||
],
|
||||
),
|
||||
)
|
||||
]),
|
||||
].withSeparator(const SizedBox(height: 8)),
|
||||
),
|
||||
),
|
||||
// Column(
|
||||
|
|
|
@ -30,7 +30,7 @@ class RepoHeader extends StatelessWidget {
|
|||
padding: CommonStyle.padding,
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: join(const SizedBox(height: 12), [
|
||||
children: [
|
||||
Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
|
@ -73,7 +73,7 @@ class RepoHeader extends StatelessWidget {
|
|||
),
|
||||
),
|
||||
if (trailings != null) ...trailings!
|
||||
]),
|
||||
].withSeparator(const SizedBox(height: 12)),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue