1
0
mirror of https://github.com/git-touch/git-touch synced 2025-02-08 23:58:46 +01:00

91 lines
3.6 KiB
Dart
Raw Normal View History

2019-03-02 18:17:46 +08:00
import 'package:flutter/material.dart';
2020-01-12 16:18:37 +08:00
import 'package:git_touch/models/theme.dart';
2019-09-25 17:06:36 +08:00
import 'package:git_touch/scaffolds/tab_stateful.dart';
2019-09-08 21:20:12 +08:00
import 'package:git_touch/utils/utils.dart';
2019-09-11 19:59:47 +08:00
import 'package:git_touch/widgets/app_bar_title.dart';
import 'package:git_touch/widgets/link.dart';
2019-09-24 20:45:55 +08:00
import 'package:git_touch/widgets/user_item.dart';
2020-02-09 17:57:12 +08:00
import 'package:github_trending/github_trending.dart';
2019-09-23 18:28:33 +08:00
import 'package:git_touch/widgets/repository_item.dart';
2020-01-12 16:18:37 +08:00
import 'package:provider/provider.dart';
import 'package:flutter_gen/gen_l10n/S.dart';
2019-03-02 18:17:46 +08:00
2020-02-07 14:17:05 +08:00
class GhTrendingScreen extends StatelessWidget {
static final trending = GithubTrending(prefix: 'https://gtrend.yapie.me');
2019-03-02 18:17:46 +08:00
Widget build(BuildContext context) {
2020-02-09 17:57:12 +08:00
return TabStatefulScaffold<List>(
title: AppBarTitle(AppLocalizations.of(context).trending),
tabs: [
AppLocalizations.of(context).repositories,
AppLocalizations.of(context).developers
],
2019-09-30 17:37:51 +08:00
fetchData: (tabIndex) async {
2020-02-09 17:57:12 +08:00
if (tabIndex == 0) {
return trending.getTrendingRepositories();
2020-02-09 17:57:12 +08:00
} else {
return trending.getTrendingDevelopers();
2020-02-09 17:57:12 +08:00
}
},
2019-09-24 20:45:55 +08:00
bodyBuilder: (payload, activeTab) {
2020-01-12 16:18:37 +08:00
final theme = Provider.of<ThemeModel>(context);
2019-03-02 18:17:46 +08:00
return Column(
2019-09-08 21:20:12 +08:00
crossAxisAlignment: CrossAxisAlignment.stretch,
children: join(
2019-10-02 16:09:54 +08:00
CommonStyle.border,
2020-02-09 17:57:12 +08: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 15:55:26 +08:00
UserItem.github(
2020-02-09 17:57:12 +08:00
login: v.username,
2020-10-08 15:55:26 +08:00
name: v.name,
2020-02-09 17:57:12 +08:00
avatarUrl: v.avatar,
2020-10-03 14:26:01 +08: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 11:36:48 +08:00
),
2020-10-03 14:26:01 +08:00
),
2020-02-09 17:57:12 +08:00
)
],
2019-09-08 21:20:12 +08:00
),
2019-03-02 18:17:46 +08:00
);
},
);
}
}