git-touch-android-ios-app/lib/screens/gh_trending.dart

88 lines
3.5 KiB
Dart
Raw Normal View History

2019-03-02 11:17:46 +01:00
import 'package:flutter/material.dart';
2020-01-12 09:18:37 +01:00
import 'package:git_touch/models/theme.dart';
2019-09-25 11:06:36 +02:00
import 'package:git_touch/scaffolds/tab_stateful.dart';
2019-09-08 15:20:12 +02:00
import 'package:git_touch/utils/utils.dart';
2019-09-11 13:59:47 +02:00
import 'package:git_touch/widgets/app_bar_title.dart';
import 'package:git_touch/widgets/link.dart';
2019-09-24 14:45:55 +02:00
import 'package:git_touch/widgets/user_item.dart';
2020-02-09 10:57:12 +01:00
import 'package:github_trending/github_trending.dart';
2019-09-23 12:28:33 +02:00
import 'package:git_touch/widgets/repository_item.dart';
2020-01-12 09:18:37 +01:00
import 'package:provider/provider.dart';
import '../generated/l10n.dart';
2019-03-02 11:17:46 +01:00
2020-02-07 07:17:05 +01:00
class GhTrendingScreen extends StatelessWidget {
static final trending = GithubTrending(prefix: 'https://gtrend.yapie.me');
2019-03-02 11:17:46 +01:00
Widget build(BuildContext context) {
2020-02-09 10:57:12 +01:00
return TabStatefulScaffold<List>(
title: AppBarTitle(S.of(context).trending),
tabs: [S.of(context).repositories, S.of(context).developers],
2019-09-30 11:37:51 +02:00
fetchData: (tabIndex) async {
2020-02-09 10:57:12 +01:00
if (tabIndex == 0) {
return trending.getTrendingRepositories();
2020-02-09 10:57:12 +01:00
} else {
return trending.getTrendingDevelopers();
2020-02-09 10:57:12 +01:00
}
},
2019-09-24 14:45:55 +02:00
bodyBuilder: (payload, activeTab) {
2020-01-12 09:18:37 +01:00
final theme = Provider.of<ThemeModel>(context);
2019-03-02 11:17:46 +01:00
return Column(
2019-09-08 15:20:12 +02:00
crossAxisAlignment: CrossAxisAlignment.stretch,
children: join(
2019-10-02 10:09:54 +02:00
CommonStyle.border,
2020-02-09 10:57:12 +01:00
activeTab == 0
? [
for (var v in payload.cast<GithubTrendingRepository>())
RepositoryItem.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>())
2020-10-08 09:55:26 +02:00
UserItem.github(
2020-02-09 10:57:12 +01:00
login: v.username,
2020-10-08 09:55:26 +02:00
name: v.name,
2020-02-09 10:57:12 +01:00
avatarUrl: v.avatar,
2020-10-03 08:26:01 +02:00
bio: v.repo == null
? null
: Link(
url: '/github/${v.username}/${v.repo.name}',
child: Row(
children: <Widget>[
Icon(
Octicons.repo,
size: 17,
color: theme.palette.secondaryText,
),
SizedBox(width: 4),
Expanded(
child: Text(
'${v.username} / ${v.repo.name}',
style: TextStyle(
fontSize: 17,
color: theme.palette.secondaryText,
),
overflow: TextOverflow.ellipsis,
))
],
2020-04-16 05:36:48 +02:00
),
2020-10-03 08:26:01 +02:00
),
2020-02-09 10:57:12 +01:00
)
],
2019-09-08 15:20:12 +02:00
),
2019-03-02 11:17:46 +01:00
);
},
);
}
}