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

59 lines
1.6 KiB
Dart
Raw Normal View History

import 'dart:convert';
2019-03-02 11:17:46 +01:00
import 'package:flutter/material.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';
import 'package:http/http.dart' as http;
2019-03-02 11:17:46 +01:00
import '../scaffolds/refresh.dart';
import '../widgets/repo_item.dart';
class TrendingScreen extends StatefulWidget {
@override
_TrendingScreenState createState() => _TrendingScreenState();
}
class _TrendingScreenState extends State<TrendingScreen> {
Future<List<dynamic>> _fetchTrendingRepos() async {
var res = await http.get('https://github-trending-api.now.sh');
var items = json.decode(res.body);
2019-03-02 11:17:46 +01:00
return items.map((item) {
return {
2019-09-08 15:20:12 +02:00
'owner': {'login': item['author'], 'avatarUrl': item['avatar']},
'name': item['name'],
'description': item['description'],
2019-03-02 11:17:46 +01:00
'stargazers': {
'totalCount': item['stars'],
2019-03-02 11:17:46 +01:00
},
'forks': {
'totalCount': item['forks'],
2019-03-02 11:17:46 +01:00
},
'primaryLanguage': item['language'] == null
? null
: {
'name': item['language'],
'color': item['languageColor'],
},
2019-03-02 11:17:46 +01:00
'isPrivate': false,
'isFork': false // TODO:
};
}).toList();
}
@override
Widget build(BuildContext context) {
return RefreshScaffold(
2019-09-11 13:59:47 +02:00
title: AppBarTitle('Trending'),
2019-03-02 11:17:46 +01:00
onRefresh: _fetchTrendingRepos,
bodyBuilder: (payload) {
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-08 15:20:12 +02:00
payload.map<Widget>((item) => RepoItem(item)).toList(),
),
2019-03-02 11:17:46 +01:00
);
},
);
}
}