mirror of
https://github.com/git-touch/git-touch
synced 2025-02-01 08:26:53 +01:00
fix: trending user data
This commit is contained in:
parent
3be1a92ea2
commit
396fe550c4
@ -211,3 +211,27 @@ class 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 username;
|
||||
String description;
|
||||
|
||||
GithubTrendingUserRepo();
|
||||
|
||||
factory GithubTrendingUserRepo.fromJson(Map<String, dynamic> json) =>
|
||||
_$GithubTrendingUserRepoFromJson(json);
|
||||
}
|
||||
|
@ -246,3 +246,35 @@ Map<String, dynamic> _$GithubTrendingItemToJson(GithubTrendingItem instance) =>
|
||||
'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()
|
||||
..username = json['username'] as String
|
||||
..description = json['description'] as String;
|
||||
}
|
||||
|
||||
Map<String, dynamic> _$GithubTrendingUserRepoToJson(
|
||||
GithubTrendingUserRepo instance) =>
|
||||
<String, dynamic>{
|
||||
'username': instance.username,
|
||||
'description': instance.description,
|
||||
};
|
||||
|
@ -10,24 +10,24 @@ import 'package:git_touch/widgets/repository_item.dart';
|
||||
|
||||
class TrendingScreen extends StatelessWidget {
|
||||
Widget build(BuildContext context) {
|
||||
return TabStatefulScaffold<Iterable<GithubTrendingItem>>(
|
||||
return TabStatefulScaffold<Iterable>(
|
||||
title: AppBarTitle('Trending'),
|
||||
tabs: ['Repositories', 'Users'],
|
||||
fetchData: (tabIndex) async {
|
||||
var uri = Uri.parse('https://github-trending-api.now.sh')
|
||||
final uri = Uri.parse('https://github-trending-api.now.sh')
|
||||
.resolve(tabIndex == 1 ? '/developers' : '/');
|
||||
var res = await http.get(uri);
|
||||
return (json.decode(res.body) as List)
|
||||
.map((v) => GithubTrendingItem.fromJson(v));
|
||||
final res = await http.get(uri);
|
||||
return json.decode(res.body) as List;
|
||||
},
|
||||
bodyBuilder: (payload, activeTab) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.stretch,
|
||||
children: join(
|
||||
CommonStyle.border,
|
||||
payload.map<Widget>((item) {
|
||||
payload.map<Widget>((v) {
|
||||
switch (activeTab) {
|
||||
case 0:
|
||||
final item = GithubTrendingItem.fromJson(v);
|
||||
return RepositoryItem.raw(
|
||||
item.author,
|
||||
item.avatar,
|
||||
@ -41,8 +41,9 @@ class TrendingScreen extends StatelessWidget {
|
||||
[],
|
||||
);
|
||||
case 1:
|
||||
final item = GithubTrendingUser.fromJson(v);
|
||||
return UserItem(
|
||||
login: item.author,
|
||||
login: item.username,
|
||||
name: item.name,
|
||||
avatarUrl: item.avatar,
|
||||
bio: '',
|
||||
|
Loading…
x
Reference in New Issue
Block a user