1
0
mirror of https://github.com/git-touch/git-touch synced 2025-03-07 12:47:42 +01:00

57 lines
1.7 KiB
Dart
Raw Normal View History

import 'dart:convert';
2019-03-02 18:17:46 +08:00
import 'package:flutter/material.dart';
2019-09-08 21:20:12 +08:00
import 'package:git_touch/utils/utils.dart';
2019-09-11 19:59:47 +08:00
import 'package:git_touch/widgets/app_bar_title.dart';
import 'package:http/http.dart' as http;
2019-03-02 18:17:46 +08:00
import '../scaffolds/refresh.dart';
2019-09-23 18:28:33 +08:00
import 'package:git_touch/widgets/repository_item.dart';
2019-03-02 18:17:46 +08:00
class TrendingScreen extends StatefulWidget {
@override
_TrendingScreenState createState() => _TrendingScreenState();
}
class _TrendingScreenState extends State<TrendingScreen> {
@override
Widget build(BuildContext context) {
return RefreshScaffold(
2019-09-11 19:59:47 +08:00
title: AppBarTitle('Trending'),
onRefresh: (_) 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();
},
2019-03-02 18:17:46 +08:00
bodyBuilder: (payload) {
return Column(
2019-09-08 21:20:12 +08:00
crossAxisAlignment: CrossAxisAlignment.stretch,
children: join(
2019-09-14 23:48:01 +08:00
borderView,
2019-09-23 18:28:33 +08:00
payload.map<Widget>((item) => RepositoryItem(item)).toList(),
2019-09-08 21:20:12 +08:00
),
2019-03-02 18:17:46 +08:00
);
},
);
}
}