1
0
mirror of https://github.com/git-touch/git-touch synced 2025-02-15 19:10:45 +01:00

75 lines
2.7 KiB
Dart
Raw Normal View History

import 'dart:convert';
2019-03-02 18:17:46 +08:00
import 'package:flutter/material.dart';
2019-12-12 14:02:48 +08:00
import 'package:git_touch/models/github.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';
2019-09-24 20:45:55 +08:00
import 'package:git_touch/widgets/user_item.dart';
import 'package:http/http.dart' as http;
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';
2019-03-02 18:17:46 +08:00
2020-02-07 14:17:05 +08:00
class GhTrendingScreen extends StatelessWidget {
2019-03-02 18:17:46 +08:00
Widget build(BuildContext context) {
2019-12-30 19:55:59 +08:00
return TabStatefulScaffold<Iterable>(
2019-09-11 19:59:47 +08:00
title: AppBarTitle('Trending'),
2019-12-30 20:55:56 +08:00
tabs: ['Repositories', 'Developers'],
2019-09-30 17:37:51 +08:00
fetchData: (tabIndex) async {
2019-12-30 19:55:59 +08:00
final uri = Uri.parse('https://github-trending-api.now.sh')
2019-09-24 20:45:55 +08:00
.resolve(tabIndex == 1 ? '/developers' : '/');
2019-12-30 19:55:59 +08:00
final res = await http.get(uri);
return json.decode(res.body) as List;
},
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,
2019-12-30 19:55:59 +08:00
payload.map<Widget>((v) {
2019-09-24 20:45:55 +08:00
switch (activeTab) {
case 0:
2019-12-30 19:55:59 +08:00
final item = GithubTrendingItem.fromJson(v);
2020-01-11 19:52:17 +08:00
return RepositoryItem.gh(
2020-01-29 13:06:55 +08:00
owner: item.author,
avatarUrl: item.avatar,
name: item.name,
description: item.description,
starCount: item.stars ?? 0,
forkCount: item.forks ?? 0,
primaryLanguageName: item.language,
primaryLanguageColor: item.languageColor,
note: '${item.currentPeriodStars} stars today',
isPrivate: false,
isFork: false, // TODO:
2019-12-07 14:42:33 +08:00
);
2019-09-24 20:45:55 +08:00
case 1:
2019-12-30 19:55:59 +08:00
final item = GithubTrendingUser.fromJson(v);
2020-02-01 10:32:29 +08:00
return UserItem.gh(
2019-12-30 19:55:59 +08:00
login: item.username,
2020-02-01 10:32:29 +08:00
// name: item.name,
2019-12-07 14:42:33 +08:00
avatarUrl: item.avatar,
2020-01-02 13:56:50 +08:00
bio: Row(
children: <Widget>[
2020-01-12 16:18:37 +08:00
Icon(
Octicons.repo,
2020-01-14 13:33:02 +08:00
size: 15,
2020-01-27 15:11:51 +08:00
color: theme.palette.secondaryText,
2020-01-12 16:18:37 +08:00
),
2020-01-02 13:56:50 +08:00
SizedBox(width: 2),
2020-01-14 13:33:02 +08:00
Text(item.repo.name)
2020-01-02 13:56:50 +08:00
],
),
2019-09-24 20:45:55 +08:00
);
default:
throw '';
}
}).toList(),
2019-09-08 21:20:12 +08:00
),
2019-03-02 18:17:46 +08:00
);
},
);
}
}