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