2019-10-03 06:16:44 +02:00
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
2020-01-07 11:33:41 +01:00
|
|
|
import 'package:git_touch/graphql/gh.dart';
|
2019-10-03 06:16:44 +02:00
|
|
|
import 'package:git_touch/models/auth.dart';
|
|
|
|
import 'package:git_touch/models/theme.dart';
|
|
|
|
import 'package:git_touch/scaffolds/common.dart';
|
|
|
|
import 'package:git_touch/utils/utils.dart';
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
2020-02-07 07:17:05 +01:00
|
|
|
class GhIssueFormScreen extends StatefulWidget {
|
2019-10-03 06:16:44 +02:00
|
|
|
final String owner;
|
|
|
|
final String name;
|
2020-02-07 07:17:05 +01:00
|
|
|
GhIssueFormScreen(this.owner, this.name);
|
2019-10-03 06:16:44 +02:00
|
|
|
|
|
|
|
@override
|
2020-02-07 07:17:05 +01:00
|
|
|
_GhIssueFormScreenState createState() => _GhIssueFormScreenState();
|
2019-10-03 06:16:44 +02:00
|
|
|
}
|
|
|
|
|
2020-02-07 07:17:05 +01:00
|
|
|
class _GhIssueFormScreenState extends State<GhIssueFormScreen> {
|
2020-01-07 11:33:41 +01:00
|
|
|
var _title = '';
|
|
|
|
var _body = '';
|
2019-10-03 06:16:44 +02:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2020-02-01 10:18:21 +01:00
|
|
|
final theme = Provider.of<ThemeModel>(context);
|
2019-10-03 06:16:44 +02:00
|
|
|
return CommonScaffold(
|
|
|
|
title: Text('Submit an issue'),
|
|
|
|
body: Column(
|
|
|
|
children: <Widget>[
|
|
|
|
Padding(
|
|
|
|
padding: CommonStyle.padding,
|
|
|
|
child: CupertinoTextField(
|
2020-02-01 10:18:21 +01:00
|
|
|
style: TextStyle(color: theme.palette.text),
|
2019-10-03 06:16:44 +02:00
|
|
|
placeholder: 'Title',
|
|
|
|
onChanged: (v) {
|
|
|
|
setState(() {
|
|
|
|
_title = v;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: CommonStyle.padding,
|
|
|
|
child: CupertinoTextField(
|
2020-02-01 10:18:21 +01:00
|
|
|
style: TextStyle(color: theme.palette.text),
|
2019-10-03 06:16:44 +02:00
|
|
|
placeholder: 'Body',
|
|
|
|
onChanged: (v) {
|
|
|
|
setState(() {
|
|
|
|
_body = v;
|
|
|
|
});
|
|
|
|
},
|
2019-10-03 06:57:21 +02:00
|
|
|
maxLines: 10,
|
2019-10-03 06:16:44 +02:00
|
|
|
),
|
|
|
|
),
|
2019-10-03 06:57:21 +02:00
|
|
|
CupertinoButton.filled(
|
2019-10-03 06:16:44 +02:00
|
|
|
child: Text('Submit'),
|
|
|
|
onPressed: () async {
|
2020-01-07 11:33:41 +01:00
|
|
|
final auth = Provider.of<AuthModel>(context);
|
|
|
|
final theme = Provider.of<ThemeModel>(context);
|
|
|
|
final r0 = await auth.gqlClient.execute(
|
|
|
|
GhRepoIdQuery(
|
|
|
|
variables:
|
|
|
|
GhRepoIdArguments(owner: widget.owner, name: widget.name),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
final res = await auth.gqlClient.execute(GhCreateIssueQuery(
|
|
|
|
variables: GhCreateIssueArguments(
|
|
|
|
repoId: r0.data.repository.id, title: _title, body: _body),
|
|
|
|
));
|
|
|
|
final issue = res.data.createIssue.issue;
|
|
|
|
await theme.push(
|
|
|
|
context,
|
|
|
|
'/${issue.repository.owner.login}/${issue.repository.name}/issues/${issue.number}',
|
|
|
|
replace: true,
|
|
|
|
);
|
2019-10-03 06:16:44 +02:00
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|