refactor(gh): use github_trending lib
This commit is contained in:
parent
7d2bf09f93
commit
02e535a271
|
@ -193,49 +193,6 @@ class GithubNotificationItemRepo {
|
|||
_$GithubNotificationItemRepoFromJson(json);
|
||||
}
|
||||
|
||||
// Trending
|
||||
@JsonSerializable()
|
||||
class GithubTrendingItem {
|
||||
String author;
|
||||
String name;
|
||||
String avatar;
|
||||
String description;
|
||||
String language;
|
||||
String languageColor;
|
||||
int stars;
|
||||
int forks;
|
||||
int currentPeriodStars;
|
||||
|
||||
GithubTrendingItem();
|
||||
|
||||
factory GithubTrendingItem.fromJson(Map<String, dynamic> json) =>
|
||||
_$GithubTrendingItemFromJson(json);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class GithubTrendingUser {
|
||||
String username;
|
||||
String name;
|
||||
String avatar;
|
||||
GithubTrendingUserRepo repo;
|
||||
|
||||
GithubTrendingUser();
|
||||
|
||||
factory GithubTrendingUser.fromJson(Map<String, dynamic> json) =>
|
||||
_$GithubTrendingUserFromJson(json);
|
||||
}
|
||||
|
||||
@JsonSerializable()
|
||||
class GithubTrendingUserRepo {
|
||||
String name;
|
||||
String description;
|
||||
|
||||
GithubTrendingUserRepo();
|
||||
|
||||
factory GithubTrendingUserRepo.fromJson(Map<String, dynamic> json) =>
|
||||
_$GithubTrendingUserRepoFromJson(json);
|
||||
}
|
||||
|
||||
@JsonSerializable(fieldRename: FieldRename.snake)
|
||||
class GithubTreeItem {
|
||||
String name;
|
||||
|
|
|
@ -221,64 +221,6 @@ Map<String, dynamic> _$GithubNotificationItemRepoToJson(
|
|||
'full_name': instance.fullName,
|
||||
};
|
||||
|
||||
GithubTrendingItem _$GithubTrendingItemFromJson(Map<String, dynamic> json) {
|
||||
return GithubTrendingItem()
|
||||
..author = json['author'] as String
|
||||
..name = json['name'] as String
|
||||
..avatar = json['avatar'] as String
|
||||
..description = json['description'] as String
|
||||
..language = json['language'] as String
|
||||
..languageColor = json['languageColor'] as String
|
||||
..stars = json['stars'] as int
|
||||
..forks = json['forks'] as int
|
||||
..currentPeriodStars = json['currentPeriodStars'] as int;
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$GithubTrendingItemToJson(GithubTrendingItem instance) =>
|
||||
<String, dynamic>{
|
||||
'author': instance.author,
|
||||
'name': instance.name,
|
||||
'avatar': instance.avatar,
|
||||
'description': instance.description,
|
||||
'language': instance.language,
|
||||
'languageColor': instance.languageColor,
|
||||
'stars': instance.stars,
|
||||
'forks': instance.forks,
|
||||
'currentPeriodStars': instance.currentPeriodStars,
|
||||
};
|
||||
|
||||
GithubTrendingUser _$GithubTrendingUserFromJson(Map<String, dynamic> json) {
|
||||
return GithubTrendingUser()
|
||||
..username = json['username'] as String
|
||||
..name = json['name'] as String
|
||||
..avatar = json['avatar'] as String
|
||||
..repo = json['repo'] == null
|
||||
? null
|
||||
: GithubTrendingUserRepo.fromJson(json['repo'] as Map<String, dynamic>);
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$GithubTrendingUserToJson(GithubTrendingUser instance) =>
|
||||
<String, dynamic>{
|
||||
'username': instance.username,
|
||||
'name': instance.name,
|
||||
'avatar': instance.avatar,
|
||||
'repo': instance.repo,
|
||||
};
|
||||
|
||||
GithubTrendingUserRepo _$GithubTrendingUserRepoFromJson(
|
||||
Map<String, dynamic> json) {
|
||||
return GithubTrendingUserRepo()
|
||||
..name = json['name'] as String
|
||||
..description = json['description'] as String;
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$GithubTrendingUserRepoToJson(
|
||||
GithubTrendingUserRepo instance) =>
|
||||
<String, dynamic>{
|
||||
'name': instance.name,
|
||||
'description': instance.description,
|
||||
};
|
||||
|
||||
GithubTreeItem _$GithubTreeItemFromJson(Map<String, dynamic> json) {
|
||||
return GithubTreeItem()
|
||||
..name = json['name'] as String
|
||||
|
|
|
@ -1,26 +1,25 @@
|
|||
import 'dart:convert';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:git_touch/models/github.dart';
|
||||
import 'package:git_touch/models/theme.dart';
|
||||
import 'package:git_touch/scaffolds/tab_stateful.dart';
|
||||
import 'package:git_touch/utils/utils.dart';
|
||||
import 'package:git_touch/widgets/app_bar_title.dart';
|
||||
import 'package:git_touch/widgets/link.dart';
|
||||
import 'package:git_touch/widgets/user_item.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:github_trending/github_trending.dart';
|
||||
import 'package:git_touch/widgets/repository_item.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
class GhTrendingScreen extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
return TabStatefulScaffold<Iterable>(
|
||||
return TabStatefulScaffold<List>(
|
||||
title: AppBarTitle('Trending'),
|
||||
tabs: ['Repositories', 'Developers'],
|
||||
fetchData: (tabIndex) async {
|
||||
final uri = Uri.parse('https://github-trending-api.now.sh')
|
||||
.resolve(tabIndex == 1 ? '/developers' : '/');
|
||||
final res = await http.get(uri);
|
||||
return json.decode(res.body) as List;
|
||||
if (tabIndex == 0) {
|
||||
return getTrendingRepositories();
|
||||
} else {
|
||||
return getTrendingDevelopers();
|
||||
}
|
||||
},
|
||||
bodyBuilder: (payload, activeTab) {
|
||||
final theme = Provider.of<ThemeModel>(context);
|
||||
|
@ -28,54 +27,51 @@ class GhTrendingScreen extends StatelessWidget {
|
|||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: join(
|
||||
CommonStyle.border,
|
||||
payload.map<Widget>((v) {
|
||||
switch (activeTab) {
|
||||
case 0:
|
||||
final item = GithubTrendingItem.fromJson(v);
|
||||
return RepositoryItem.gh(
|
||||
owner: item.author,
|
||||
avatarUrl: item.avatar,
|
||||
name: item.name,
|
||||
description: item.description,
|
||||
starCount: item.stars ?? 0,
|
||||
forkCount: item.forks ?? 0,
|
||||
primaryLanguageName: item.language,
|
||||
primaryLanguageColor: item.languageColor,
|
||||
note: '${item.currentPeriodStars} stars today',
|
||||
isPrivate: false,
|
||||
isFork: false, // TODO:
|
||||
);
|
||||
case 1:
|
||||
final item = GithubTrendingUser.fromJson(v);
|
||||
return UserItem.gh(
|
||||
login: item.username,
|
||||
// name: item.name,
|
||||
avatarUrl: item.avatar,
|
||||
bio: Link(
|
||||
url: '/${item.username}/${item.repo.name}',
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Icon(
|
||||
Octicons.repo,
|
||||
size: 17,
|
||||
color: theme.palette.secondaryText,
|
||||
activeTab == 0
|
||||
? [
|
||||
for (var v in payload.cast<GithubTrendingRepository>())
|
||||
RepositoryItem.gh(
|
||||
owner: v.author,
|
||||
avatarUrl: v.avatar,
|
||||
name: v.name,
|
||||
description: v.description,
|
||||
starCount: v.stars ?? 0,
|
||||
forkCount: v.forks ?? 0,
|
||||
primaryLanguageName: v.language,
|
||||
primaryLanguageColor: v.languageColor,
|
||||
note: '${v.currentPeriodStars} stars today',
|
||||
isPrivate: false,
|
||||
isFork: false, // TODO:
|
||||
)
|
||||
]
|
||||
: [
|
||||
for (var v in payload.cast<GithubTrendingDeveloper>())
|
||||
UserItem.gh(
|
||||
login: v.username,
|
||||
// name: v.name,
|
||||
avatarUrl: v.avatar,
|
||||
bio: Link(
|
||||
url: '/${v.username}/${v.repo.name}',
|
||||
child: Row(
|
||||
children: <Widget>[
|
||||
Icon(
|
||||
Octicons.repo,
|
||||
size: 17,
|
||||
color: theme.palette.secondaryText,
|
||||
),
|
||||
SizedBox(width: 4),
|
||||
Text(
|
||||
'${v.username} / ${v.repo.name}',
|
||||
style: TextStyle(
|
||||
fontSize: 17,
|
||||
color: theme.palette.secondaryText,
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
SizedBox(width: 4),
|
||||
Text(
|
||||
'${item.username} / ${item.repo.name}',
|
||||
style: TextStyle(
|
||||
fontSize: 17,
|
||||
color: theme.palette.secondaryText,
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
default:
|
||||
throw '';
|
||||
}
|
||||
}).toList(),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
|
|
|
@ -45,6 +45,7 @@ dependencies:
|
|||
# url: git://github.com/pd4d10/github.dart.git
|
||||
# ref: patch-1
|
||||
# path: ../../github/github.dart
|
||||
github_trending: ^0.2.0
|
||||
# The following adds the Cupertino Icons font to your application.
|
||||
# Use with the CupertinoIcons class for iOS style icons.
|
||||
cupertino_icons: ^0.1.2
|
||||
|
|
Loading…
Reference in New Issue