2020-04-06 06:03:44 +02:00
|
|
|
import 'dart:convert';
|
|
|
|
|
2019-10-03 06:16:44 +02:00
|
|
|
import 'package:flutter/cupertino.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
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';
|
2020-04-06 06:03:44 +02:00
|
|
|
import 'package:github/github.dart';
|
2019-10-03 06:16:44 +02:00
|
|
|
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);
|
2020-04-06 06:03:44 +02:00
|
|
|
|
|
|
|
final slug = RepositorySlug(widget.owner, widget.name);
|
|
|
|
|
|
|
|
// TODO: https://github.com/SpinlockLabs/github.dart/issues/211
|
|
|
|
// final res = await auth.ghClient.issues
|
|
|
|
// .create(slug, IssueRequest(title: _title, body: _body));
|
|
|
|
|
|
|
|
final response = await auth.ghClient.request(
|
|
|
|
'POST',
|
|
|
|
'/repos/${slug.fullName}/issues',
|
|
|
|
body: jsonEncode({'title': _title, 'body': _body}),
|
2020-01-07 11:33:41 +01:00
|
|
|
);
|
2020-04-06 06:03:44 +02:00
|
|
|
final res = Issue.fromJson(
|
|
|
|
jsonDecode(response.body) as Map<String, dynamic>);
|
2020-01-07 11:33:41 +01:00
|
|
|
await theme.push(
|
|
|
|
context,
|
2020-04-06 06:03:44 +02:00
|
|
|
'/${widget.owner}/${widget.name}/issues/${res.number}',
|
2020-01-07 11:33:41 +01:00
|
|
|
replace: true,
|
|
|
|
);
|
2019-10-03 06:16:44 +02:00
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|