git-touch-android-ios-app/lib/screens/pull_request.dart

164 lines
3.9 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
2019-02-07 07:35:19 +01:00
import '../providers/settings.dart';
2019-01-31 07:37:25 +01:00
import '../utils/utils.dart';
2019-02-03 07:42:50 +01:00
import '../widgets/list_scaffold.dart';
import '../widgets/timeline_item.dart';
import '../widgets/comment_item.dart';
2019-02-07 07:35:19 +01:00
class PullRequestScreen extends StatefulWidget {
final int id;
final String owner;
final String name;
PullRequestScreen(this.id, this.owner, this.name);
@override
_PullRequestScreenState createState() => _PullRequestScreenState();
}
class _PullRequestScreenState extends State<PullRequestScreen> {
Map<String, dynamic> payload;
Future queryPullRequest(BuildContext context) async {
var owner = widget.owner;
var id = widget.id;
var name = widget.name;
var data = await SettingsProvider.of(context).query('''
{
repository(owner: "$owner", name: "$name") {
pullRequest(number: $id) {
$graphqlChunk1
merged
permalink
additions
deletions
commits {
totalCount
}
timeline(first: $pageSize) {
pageInfo {
hasNextPage
endCursor
}
nodes {
$graghqlChunk
... on ReviewRequestedEvent {
createdAt
actor {
login
}
requestedReviewer {
... on User {
login
}
}
}
... on PullRequestReview {
createdAt
state
author {
login
}
}
... on MergedEvent {
createdAt
mergeRefName
actor {
login
}
commit {
oid
url
}
}
... on HeadRefDeletedEvent {
createdAt
actor {
login
}
headRefName
}
}
}
}
}
}
''');
2019-02-07 07:35:19 +01:00
return data['repository']['pullRequest'];
}
2019-02-03 07:42:50 +01:00
Widget _buildBadge() {
2019-02-03 07:42:50 +01:00
bool merged = payload['merged'];
2019-02-06 12:14:11 +01:00
Color bgColor = merged ? Palette.purple : Palette.green;
2019-02-03 07:42:50 +01:00
IconData iconData = merged ? Octicons.git_merge : Octicons.git_pull_request;
String text = merged ? 'Merged' : 'Open';
return Container(
decoration: BoxDecoration(
2019-02-06 12:14:11 +01:00
color: bgColor,
2019-02-03 07:42:50 +01:00
borderRadius: BorderRadius.all(Radius.circular(4)),
),
padding: EdgeInsets.all(6),
child: Row(
children: <Widget>[
Icon(iconData, color: Colors.white, size: 15),
2019-02-06 06:06:11 +01:00
Text(
text,
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.w600,
),
),
2019-02-03 07:42:50 +01:00
],
),
);
}
get _fullName => widget.owner + '/' + widget.name;
Widget _buildHeader() {
return Column(children: <Widget>[
Container(
// padding: EdgeInsets.all(10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
_buildBadge(),
Text(
payload['title'],
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
height: 1.2,
),
),
CommentItem(payload),
],
),
)
]);
}
2019-02-03 07:42:50 +01:00
List get _items => payload == null ? [] : payload['timeline']['nodes'];
@override
Widget build(BuildContext context) {
2019-02-03 07:42:50 +01:00
return ListScaffold(
2019-02-05 13:57:05 +01:00
title: Text(_fullName + ' #' + widget.id.toString()),
2019-02-03 07:42:50 +01:00
header: payload == null ? null : _buildHeader(),
itemCount: _items.length,
itemBuilder: (context, index) => TimelineItem(_items[index], payload),
onRefresh: () async {
2019-02-07 07:35:19 +01:00
var _payload = await queryPullRequest(context);
2019-02-06 14:35:52 +01:00
if (mounted) {
setState(() {
payload = _payload;
});
}
2019-02-03 07:42:50 +01:00
},
// onLoadMore: () => ,
);
}
}