1
0
mirror of https://github.com/git-touch/git-touch synced 2024-12-26 07:46:59 +01:00
git-touch-android-ios-app/lib/screens/trending.dart

75 lines
2.7 KiB
Dart
Raw Normal View History

import 'dart:convert';
2019-03-02 11:17:46 +01:00
import 'package:flutter/material.dart';
2019-12-12 07:02:48 +01:00
import 'package:git_touch/models/github.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';
2019-09-24 14:45:55 +02:00
import 'package:git_touch/widgets/user_item.dart';
import 'package:http/http.dart' as http;
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
2019-09-24 14:45:55 +02:00
class TrendingScreen extends StatelessWidget {
2019-03-02 11:17:46 +01:00
Widget build(BuildContext context) {
2019-12-30 12:55:59 +01:00
return TabStatefulScaffold<Iterable>(
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 {
2019-12-30 12:55:59 +01:00
final uri = Uri.parse('https://github-trending-api.now.sh')
2019-09-24 14:45:55 +02:00
.resolve(tabIndex == 1 ? '/developers' : '/');
2019-12-30 12:55:59 +01:00
final res = await http.get(uri);
return json.decode(res.body) as List;
},
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,
2019-12-30 12:55:59 +01:00
payload.map<Widget>((v) {
2019-09-24 14:45:55 +02:00
switch (activeTab) {
case 0:
2019-12-30 12:55:59 +01:00
final item = GithubTrendingItem.fromJson(v);
2020-01-11 12:52:17 +01:00
return RepositoryItem.gh(
2020-01-29 06:06:55 +01: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 07:42:33 +01:00
);
2019-09-24 14:45:55 +02:00
case 1:
2019-12-30 12:55:59 +01:00
final item = GithubTrendingUser.fromJson(v);
2019-09-24 14:45:55 +02:00
return UserItem(
2019-12-30 12:55:59 +01:00
login: item.username,
2019-12-07 07:42:33 +01:00
name: item.name,
avatarUrl: item.avatar,
2020-01-02 06:56:50 +01:00
bio: Row(
children: <Widget>[
2020-01-12 09:18:37 +01:00
Icon(
Octicons.repo,
2020-01-14 06:33:02 +01:00
size: 15,
2020-01-27 08:11:51 +01:00
color: theme.palette.secondaryText,
2020-01-12 09:18:37 +01:00
),
2020-01-02 06:56:50 +01:00
SizedBox(width: 2),
2020-01-14 06:33:02 +01:00
Text(item.repo.name)
2020-01-02 06:56:50 +01:00
],
),
2019-09-24 14:45:55 +02:00
);
default:
throw '';
}
}).toList(),
2019-09-08 15:20:12 +02:00
),
2019-03-02 11:17:46 +01:00
);
},
);
}
}