refactor: use list extension
This commit is contained in:
parent
b65ce98077
commit
7ca3fe03c5
|
@ -30,9 +30,7 @@ class GhTrendingScreen extends StatelessWidget {
|
|||
bodyBuilder: (payload, activeTab) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: join(
|
||||
CommonStyle.border,
|
||||
activeTab == 0
|
||||
children: (activeTab == 0
|
||||
? [
|
||||
for (var v in payload.cast<GithubTrendingRepository>())
|
||||
RepoItem.gh(
|
||||
|
@ -82,8 +80,8 @@ class GhTrendingScreen extends StatelessWidget {
|
|||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
])
|
||||
.withSeparator(CommonStyle.border),
|
||||
);
|
||||
},
|
||||
);
|
||||
|
|
|
@ -77,32 +77,17 @@ class GithubPalette {
|
|||
// final pageSize = 5;
|
||||
const kPageSize = 30;
|
||||
|
||||
List<T> join<T>(T seperator, List<T> xs) {
|
||||
extension MyList on List {
|
||||
List<T> withSeparator<T>(T separator) {
|
||||
final result = <T>[];
|
||||
xs.asMap().forEach((index, x) {
|
||||
if (x == null) return;
|
||||
|
||||
result.add(x);
|
||||
if (index < xs.length - 1) {
|
||||
result.add(seperator);
|
||||
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;
|
||||
}
|
||||
|
||||
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