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

61 lines
2.0 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';
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';
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) {
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);
2019-12-07 07:42:33 +01:00
return RepositoryItem.raw(
item.author,
item.avatar,
item.name,
item.description,
Octicons.repo,
2019-12-07 07:43:35 +01:00
item.stars ?? 0,
item.forks ?? 0,
2019-12-07 07:42:33 +01:00
item.language,
item.languageColor,
[],
);
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,
2019-09-24 14:45:55 +02:00
bio: '',
);
default:
throw '';
}
}).toList(),
2019-09-08 15:20:12 +02:00
),
2019-03-02 11:17:46 +01:00
);
},
);
}
}