2019-02-04 14:38:29 +01:00
|
|
|
import 'dart:convert';
|
2019-01-27 17:37:44 +01:00
|
|
|
import 'package:flutter/material.dart';
|
2019-02-04 14:38:29 +01:00
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
import 'package:flutter_markdown/flutter_markdown.dart';
|
2019-02-07 07:35:19 +01:00
|
|
|
import '../providers/settings.dart';
|
2019-02-08 07:06:48 +01:00
|
|
|
import '../scaffolds/refresh.dart';
|
2019-02-04 14:38:29 +01:00
|
|
|
import '../widgets/repo_item.dart';
|
|
|
|
import '../widgets/entry_item.dart';
|
|
|
|
import '../screens/issues.dart';
|
|
|
|
import '../screens/pull_requests.dart';
|
2019-02-08 03:48:25 +01:00
|
|
|
import '../utils/utils.dart';
|
2019-02-04 14:38:29 +01:00
|
|
|
|
2019-02-07 07:35:19 +01:00
|
|
|
class RepoScreen extends StatefulWidget {
|
|
|
|
final String owner;
|
|
|
|
final String name;
|
|
|
|
|
|
|
|
RepoScreen(this.owner, this.name);
|
|
|
|
|
|
|
|
@override
|
|
|
|
_RepoScreenState createState() => _RepoScreenState();
|
2019-02-04 14:38:29 +01:00
|
|
|
}
|
|
|
|
|
2019-02-07 07:35:19 +01:00
|
|
|
class _RepoScreenState extends State<RepoScreen> {
|
|
|
|
Map<String, dynamic> payload;
|
|
|
|
String readme;
|
2019-02-08 03:48:25 +01:00
|
|
|
bool loading = true;
|
2019-02-07 07:35:19 +01:00
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
2019-02-08 03:48:25 +01:00
|
|
|
nextTick(_refresh);
|
2019-02-07 07:35:19 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Future queryRepo(BuildContext context) async {
|
|
|
|
var owner = widget.owner;
|
|
|
|
var name = widget.name;
|
|
|
|
var data = await SettingsProvider.of(context).query('''
|
2019-02-04 14:38:29 +01:00
|
|
|
{
|
|
|
|
repository(owner: "$owner", name: "$name") {
|
|
|
|
owner {
|
|
|
|
login
|
|
|
|
}
|
|
|
|
name
|
|
|
|
isPrivate
|
|
|
|
isFork
|
|
|
|
description
|
|
|
|
stargazers {
|
|
|
|
totalCount
|
|
|
|
}
|
|
|
|
forks {
|
|
|
|
totalCount
|
|
|
|
}
|
|
|
|
primaryLanguage {
|
|
|
|
color
|
|
|
|
name
|
|
|
|
}
|
|
|
|
issues(states: OPEN) {
|
|
|
|
totalCount
|
|
|
|
}
|
|
|
|
pullRequests(states: OPEN) {
|
|
|
|
totalCount
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
''');
|
2019-02-07 07:35:19 +01:00
|
|
|
return data['repository'];
|
|
|
|
}
|
2019-02-06 15:28:04 +01:00
|
|
|
|
2019-02-07 07:35:19 +01:00
|
|
|
Future fetchReadme(BuildContext context) async {
|
|
|
|
var owner = widget.owner;
|
|
|
|
var name = widget.name;
|
|
|
|
var data = await SettingsProvider.of(context)
|
|
|
|
.getWithCredentials('/repos/$owner/$name/readme');
|
|
|
|
var bits = base64.decode(data['content'].replaceAll('\n', ''));
|
|
|
|
var str = utf8.decode(bits);
|
|
|
|
return str;
|
2019-02-06 15:28:04 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
Future<void> _refresh() async {
|
|
|
|
setState(() {
|
|
|
|
loading = true;
|
|
|
|
});
|
|
|
|
List items = await Future.wait([
|
2019-02-07 07:35:19 +01:00
|
|
|
queryRepo(context),
|
|
|
|
fetchReadme(context),
|
2019-02-06 15:28:04 +01:00
|
|
|
]);
|
2019-02-08 12:44:10 +01:00
|
|
|
if (mounted) {
|
|
|
|
setState(() {
|
|
|
|
loading = false;
|
|
|
|
payload = items[0];
|
|
|
|
readme = items[1];
|
|
|
|
});
|
|
|
|
}
|
2019-02-06 15:28:04 +01:00
|
|
|
}
|
2019-02-04 14:38:29 +01:00
|
|
|
|
2019-01-25 13:35:20 +01:00
|
|
|
@override
|
2019-01-27 17:37:44 +01:00
|
|
|
Widget build(BuildContext context) {
|
2019-02-04 14:38:29 +01:00
|
|
|
return RefreshScaffold(
|
2019-02-06 15:28:04 +01:00
|
|
|
loading: loading,
|
2019-02-04 14:38:29 +01:00
|
|
|
title: Text(widget.owner + '/' + widget.name),
|
2019-02-06 15:28:04 +01:00
|
|
|
onRefresh: _refresh,
|
2019-02-04 14:38:29 +01:00
|
|
|
bodyBuilder: () {
|
|
|
|
return Column(
|
|
|
|
children: <Widget>[
|
|
|
|
RepoItem(payload),
|
|
|
|
Container(
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
border: Border(
|
|
|
|
bottom: BorderSide(color: Colors.black12),
|
|
|
|
top: BorderSide(color: Colors.black12),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
child: Row(
|
|
|
|
children: <Widget>[
|
|
|
|
EntryItem(
|
|
|
|
count: payload['issues']['totalCount'],
|
|
|
|
text: 'Issues',
|
2019-02-07 12:17:29 +01:00
|
|
|
screenBuilder: (context) => IssuesScreen(),
|
2019-02-04 14:38:29 +01:00
|
|
|
),
|
|
|
|
EntryItem(
|
|
|
|
count: payload['pullRequests']['totalCount'],
|
|
|
|
text: 'Pull Requests',
|
2019-02-07 12:17:29 +01:00
|
|
|
screenBuilder: (context) => PullRequestsScreen(),
|
2019-02-04 14:38:29 +01:00
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Container(
|
|
|
|
padding: EdgeInsets.all(16),
|
|
|
|
child: MarkdownBody(data: readme),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
);
|
|
|
|
},
|
2019-01-25 13:35:20 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|