git-touch-android-ios-app/lib/screens/trending.dart

69 lines
2.3 KiB
Dart
Raw Normal View History

import 'dart:convert';
2019-03-02 11:17:46 +01:00
import 'package:flutter/material.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-09-25 11:06:36 +02:00
return TabStatefulScaffold(
2019-09-11 13:59:47 +02:00
title: AppBarTitle('Trending'),
2019-09-24 14:45:55 +02:00
tabs: ['Repositories', 'Users'],
onRefresh: (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;
},
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-09-14 17:48:01 +02:00
borderView,
2019-09-24 14:45:55 +02:00
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(
2019-09-27 15:02:55 +02:00
login: item['username'],
2019-09-24 14:45:55 +02:00
name: item['name'],
avatarUrl: item['avatar'],
bio: '',
);
default:
throw '';
}
}).toList(),
2019-09-08 15:20:12 +02:00
),
2019-03-02 11:17:46 +01:00
);
},
);
}
}