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

89 lines
2.1 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
2019-01-25 18:43:09 +01:00
import 'package:flutter/cupertino.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';
2019-02-06 06:06:11 +01:00
import '../widgets/comment_item.dart';
2019-01-25 18:43:09 +01:00
Future queryIssue(int id, String owner, String name) async {
var data = await query('''
{
repository(owner: "$owner", name: "$name") {
issue(number: $id) {
$graphqlChunk1
timeline(first: $pageSize) {
pageInfo {
hasNextPage
endCursor
}
nodes {
$graghqlChunk
}
}
}
}
}
''');
return data['repository']['issue'];
}
2019-02-03 07:42:50 +01:00
class IssueScreen extends StatefulWidget {
final int id;
final String owner;
final String name;
IssueScreen(this.id, this.owner, this.name);
2019-02-03 07:42:50 +01:00
@override
_IssueScreenState createState() => _IssueScreenState();
}
class _IssueScreenState extends State<IssueScreen> {
Map<String, dynamic> payload;
Widget _buildHeader() {
2019-02-06 06:06:11 +01:00
return Column(children: <Widget>[
Container(
// padding: EdgeInsets.all(10),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
payload['title'],
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
height: 1.2,
),
),
CommentItem(payload),
],
),
)
]);
2019-02-03 07:42:50 +01:00
}
get _fullName => widget.owner + '/' + widget.name;
List get _items => payload == null ? [] : payload['timeline']['nodes'];
2019-01-25 18:43:09 +01:00
@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 {
var _payload = await queryIssue(widget.id, widget.owner, widget.name);
2019-02-06 14:35:52 +01:00
if (mounted) {
setState(() {
payload = _payload;
});
}
2019-02-03 07:42:50 +01:00
},
// onLoadMore: () => ,
2019-01-25 18:43:09 +01:00
);
}
}