1
0
mirror of https://github.com/git-touch/git-touch synced 2024-12-19 03:33:42 +01:00
git-touch-android-ios-app/lib/screens/trending.dart

62 lines
2.1 KiB
Dart
Raw Normal View History

import 'dart:convert';
2019-03-02 11:17:46 +01:00
import 'package:flutter/material.dart';
2019-12-07 07:42:33 +01:00
import 'package:git_touch/models/github_trending.dart';
2019-09-25 11:06:36 +02:00
import 'package:git_touch/scaffolds/tab_stateful.dart';
2019-12-07 07:42:33 +01:00
import 'package:git_touch/screens/repository.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-07 07:42:33 +01:00
return TabStatefulScaffold<Iterable<GithubTrendingItem>>(
2019-09-11 13:59:47 +02:00
title: AppBarTitle('Trending'),
2019-09-24 14:45:55 +02:00
tabs: ['Repositories', 'Users'],
2019-09-30 11:37:51 +02:00
fetchData: (tabIndex) async {
2019-09-24 14:45:55 +02:00
var uri = Uri.parse('https://github-trending-api.now.sh')
.resolve(tabIndex == 1 ? '/developers' : '/');
var res = await http.get(uri);
2019-12-07 07:42:33 +01:00
return (json.decode(res.body) as List)
.map((v) => GithubTrendingItem.fromJson(v));
},
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-09-24 14:45:55 +02:00
payload.map<Widget>((item) {
switch (activeTab) {
case 0:
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,
(_) => RepositoryScreen(item.author, item.name),
[],
);
2019-09-24 14:45:55 +02:00
case 1:
return UserItem(
2019-12-07 07:42:33 +01:00
login: item.author,
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
);
},
);
}
}