2019-08-31 15:54:36 +02:00
|
|
|
import 'dart:convert';
|
2019-03-02 11:17:46 +01:00
|
|
|
import 'package:flutter/material.dart';
|
2019-08-31 15:54:36 +02:00
|
|
|
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 {
|
2019-08-31 15:54:36 +02:00
|
|
|
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) {
|
2019-03-06 04:26:10 +01:00
|
|
|
return {
|
2019-03-02 11:17:46 +01:00
|
|
|
'owner': {
|
2019-08-31 15:54:36 +02:00
|
|
|
'login': item['author'],
|
2019-03-02 11:17:46 +01:00
|
|
|
},
|
2019-08-31 15:54:36 +02:00
|
|
|
'name': item['name'],
|
|
|
|
'description': item['description'],
|
2019-03-02 11:17:46 +01:00
|
|
|
'stargazers': {
|
2019-08-31 15:54:36 +02:00
|
|
|
'totalCount': item['stars'],
|
2019-03-02 11:17:46 +01:00
|
|
|
},
|
|
|
|
'forks': {
|
2019-08-31 15:54:36 +02:00
|
|
|
'totalCount': item['forks'],
|
2019-03-02 11:17:46 +01:00
|
|
|
},
|
2019-08-31 15:54:36 +02:00
|
|
|
'primaryLanguage': item['language'] == null
|
2019-03-06 04:26:10 +01:00
|
|
|
? null
|
|
|
|
: {
|
2019-08-31 15:54:36 +02:00
|
|
|
'name': item['language'],
|
|
|
|
'color': item['languageColor'],
|
2019-03-06 04:26:10 +01:00
|
|
|
},
|
2019-03-02 11:17:46 +01:00
|
|
|
'isPrivate': false,
|
|
|
|
'isFork': false // TODO:
|
|
|
|
};
|
|
|
|
}).toList();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return RefreshScaffold(
|
|
|
|
title: Text('Trending'),
|
|
|
|
onRefresh: _fetchTrendingRepos,
|
|
|
|
bodyBuilder: (payload) {
|
|
|
|
return Column(
|
|
|
|
children: payload.map<Widget>((repo) {
|
|
|
|
return Container(
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
border: Border(bottom: BorderSide(color: Colors.black12))),
|
|
|
|
child: RepoItem(repo),
|
|
|
|
);
|
|
|
|
}).toList(),
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|