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

84 lines
3.2 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';
2019-03-02 11:17:46 +01:00
2020-02-07 07:17:05 +01:00
class GhTrendingScreen extends StatelessWidget {
2019-03-02 11:17:46 +01:00
Widget build(BuildContext context) {
2020-02-09 10:57:12 +01:00
return TabStatefulScaffold<List>(
2019-09-11 13:59:47 +02:00
title: AppBarTitle('Trending'),
2019-12-30 13:55:56 +01:00
tabs: ['Repositories', 'Developers'],
2019-09-30 11:37:51 +02:00
fetchData: (tabIndex) async {
2020-02-09 10:57:12 +01:00
if (tabIndex == 0) {
return getTrendingRepositories();
} else {
return getTrendingDevelopers();
}
},
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>())
UserItem.gh(
login: v.username,
// name: v.name,
avatarUrl: v.avatar,
bio: Link(
url: '/${v.username}/${v.repo.name}',
child: Row(
children: <Widget>[
Icon(
Octicons.repo,
size: 17,
color: theme.palette.secondaryText,
),
SizedBox(width: 4),
2020-02-13 10:46:07 +01:00
Expanded(
child: Text(
'${v.username} / ${v.repo.name}',
style: TextStyle(
fontSize: 17,
color: theme.palette.secondaryText,
),
overflow: TextOverflow.ellipsis,
)
2020-02-09 10:57:12 +01: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
);
},
);
}
}