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
2019-09-14 23:48:01 +08:00

59 lines
1.6 KiB
Dart

import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:git_touch/utils/utils.dart';
import 'package:git_touch/widgets/app_bar_title.dart';
import 'package:http/http.dart' as http;
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);
return items.map((item) {
return {
'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:
};
}).toList();
}
@override
Widget build(BuildContext context) {
return RefreshScaffold(
title: AppBarTitle('Trending'),
onRefresh: _fetchTrendingRepos,
bodyBuilder: (payload) {
return Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: join(
borderView,
payload.map<Widget>((item) => RepoItem(item)).toList(),
),
);
},
);
}
}