-
Notifications
You must be signed in to change notification settings - Fork 13
/
repolist.dart
113 lines (101 loc) · 3.41 KB
/
repolist.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
import 'dart:async';
import 'package:flutter/material.dart';
import 'package:pull_to_refresh/pull_to_refresh.dart';
import '../github/graphql.dart';
import '../github/repository.dart';
import 'dashboard.dart';
class RepoListView extends StatefulWidget {
final Future<List<Repository>> repoList;
RepoListView(this.repoList);
@override
State<StatefulWidget> createState() => RepoListViewState(repoList);
}
class RepoListViewState extends State<RepoListView> {
Future<List<Repository>> repoList;
RefreshController rc = RefreshController();
RepoListViewState(this.repoList);
Widget _createRepoListWidget(BuildContext context, List<Repository> repos) {
return SmartRefresher(
enablePullDown: true,
onRefresh: _refreshRepoList,
controller: rc,
child: ListView(
children: repos
.map((repo) => Container(
child: ListTile(
title: Text("${repo.name}"),
subtitle: Text("${repo.nameWithOwner}"),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (_) => Dashboard(
repo,
getPRs(repo),
getIssues(repo),
getBranches(repo),
getReleases(repo))),
);
},
// TODO: Add a trailing widget indicating star count of
// the repo. Something like-
// trailing: StarWidget(pullRequest.repo.starCount),
),
))
.toList(),
));
}
void _refreshRepoList(bool b) {
repoList = fetchUserRepos();
//rc.sendBack(true, RefreshStatus.completed); // makes it break, but works without.
// can look into making this better later on
Navigator.pushReplacement(
context,
PageRouteBuilder(
pageBuilder: (
BuildContext context,
Animation<double> animation,
Animation<double> secondAnimation,
) {
return RepoListView(repoList);
},
transitionsBuilder: (
BuildContext context,
Animation<double> animation,
Animation<double> secondAnimation,
Widget child,
) {
return FadeTransition(
opacity: Tween(begin: 0.0, end: 10.0).animate(animation),
child: child);
},
),
);
b = true;
}
Widget _buildRepoList(
BuildContext context,
AsyncSnapshot<List<Repository>> snapshot,
) {
if (snapshot.connectionState == ConnectionState.done) {
return snapshot.data.length != 0
? _createRepoListWidget(context, snapshot.data)
: SmartRefresher(
enablePullDown: true,
onRefresh: _refreshRepoList,
controller: rc,
child: ListView(
children: <Widget>[Text('You have no repositories!')],
),
);
} else {
return Center(child: CircularProgressIndicator());
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: Text('Your Repositories')),
body: FutureBuilder(future: repoList, builder: _buildRepoList));
}
}