From 1c768c6ca38361a5c3db9df19227a8aca3eeb7cc Mon Sep 17 00:00:00 2001 From: Rongjian Zhang Date: Sat, 31 Aug 2019 21:54:36 +0800 Subject: [PATCH] refactor: using github-trending-api instead of parsing html --- lib/screens/trending.dart | 22 ++++++++++++---------- pubspec.yaml | 1 - 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/lib/screens/trending.dart b/lib/screens/trending.dart index 2a35b0d..c1cffee 100644 --- a/lib/screens/trending.dart +++ b/lib/screens/trending.dart @@ -1,5 +1,6 @@ +import 'dart:convert'; import 'package:flutter/material.dart'; -import 'package:github_trending/github_trending.dart'; +import 'package:http/http.dart' as http; import '../scaffolds/refresh.dart'; import '../widgets/repo_item.dart'; @@ -10,26 +11,27 @@ class TrendingScreen extends StatefulWidget { class _TrendingScreenState extends State { Future> _fetchTrendingRepos() async { - var items = await getTrendingRepositories(); + 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.owner, + 'login': item['author'], }, - 'name': item.name, - 'description': item.description, + 'name': item['name'], + 'description': item['description'], 'stargazers': { - 'totalCount': item.starCount, + 'totalCount': item['stars'], }, 'forks': { - 'totalCount': item.forkCount, + 'totalCount': item['forks'], }, - 'primaryLanguage': item.primaryLanguage == null + 'primaryLanguage': item['language'] == null ? null : { - 'name': item.primaryLanguage.name, - 'color': item.primaryLanguage.color, + 'name': item['language'], + 'color': item['languageColor'], }, 'isPrivate': false, 'isFork': false // TODO: diff --git a/pubspec.yaml b/pubspec.yaml index 6a87e97..7e18f83 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -26,7 +26,6 @@ dependencies: nanoid: ^0.0.6 share: ^0.6.0 flutter_vector_icons: ^0.0.2 - github_trending: ^0.1.2 github_contributions: ^0.1.1 flutter_svg: ^0.13.0 launch_review: ^2.0.0