1
0
mirror of https://github.com/git-touch/git-touch synced 2024-12-17 10:48:50 +01:00
git-touch-android-ios-app/lib/screens/trending.dart
2019-10-02 16:10:31 +08:00

69 lines
2.3 KiB
Dart

import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:git_touch/scaffolds/tab_stateful.dart';
import 'package:git_touch/utils/utils.dart';
import 'package:git_touch/widgets/app_bar_title.dart';
import 'package:git_touch/widgets/user_item.dart';
import 'package:http/http.dart' as http;
import 'package:git_touch/widgets/repository_item.dart';
class TrendingScreen extends StatelessWidget {
Widget build(BuildContext context) {
return TabStatefulScaffold(
title: AppBarTitle('Trending'),
tabs: ['Repositories', 'Users'],
fetchData: (tabIndex) async {
var uri = Uri.parse('https://github-trending-api.now.sh')
.resolve(tabIndex == 1 ? '/developers' : '/');
var res = await http.get(uri);
var items = json.decode(res.body) as List;
return items;
},
bodyBuilder: (payload, activeTab) {
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: join(
CommonStyle.border,
payload.map<Widget>((item) {
switch (activeTab) {
case 0:
return RepositoryItem({
'owner': {
'login': item['author'],
'avatarUrl': item['avatar']
},
'name': item['name'],
'description': item['description'],
'stargazers': {
'totalCount': item['stars'],
},
'forks': {
'totalCount': item['forks'],
},
'primaryLanguage': item['language'] == null
? null
: {
'name': item['language'],
'color': item['languageColor'],
},
'isPrivate': false,
'isFork': false // TODO:
});
case 1:
return UserItem(
login: item['username'],
name: item['name'],
avatarUrl: item['avatar'],
bio: '',
);
default:
throw '';
}
}).toList(),
),
);
},
);
}
}