2019-10-03 06:16:44 +02:00
|
|
|
import 'dart:io';
|
|
|
|
|
2019-10-13 05:01:29 +02:00
|
|
|
import 'package:fimber/fimber.dart';
|
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';
|
|
|
|
import 'package:provider/provider.dart';
|
|
|
|
|
|
|
|
class IssueFormScreen extends StatefulWidget {
|
|
|
|
final String owner;
|
|
|
|
final String name;
|
|
|
|
|
|
|
|
IssueFormScreen(this.owner, this.name);
|
|
|
|
|
|
|
|
@override
|
|
|
|
_IssueFormScreenState createState() => _IssueFormScreenState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _IssueFormScreenState extends State<IssueFormScreen> {
|
|
|
|
String get owner => widget.owner;
|
|
|
|
String get name => widget.name;
|
|
|
|
|
|
|
|
String _title = '';
|
|
|
|
String _body = '';
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return CommonScaffold(
|
|
|
|
title: Text('Submit an issue'),
|
|
|
|
body: Column(
|
|
|
|
children: <Widget>[
|
|
|
|
Padding(
|
|
|
|
padding: CommonStyle.padding,
|
|
|
|
child: CupertinoTextField(
|
|
|
|
placeholder: 'Title',
|
|
|
|
onChanged: (v) {
|
|
|
|
setState(() {
|
|
|
|
_title = v;
|
|
|
|
});
|
|
|
|
},
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Padding(
|
|
|
|
padding: CommonStyle.padding,
|
|
|
|
child: CupertinoTextField(
|
|
|
|
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 {
|
|
|
|
try {
|
|
|
|
var res =
|
|
|
|
await Provider.of<AuthModel>(context).postWithCredentials(
|
|
|
|
'/repos/$owner/$name/issues',
|
|
|
|
body: {'title': _title, 'body': _body},
|
|
|
|
);
|
|
|
|
if (res.statusCode != HttpStatus.created) {
|
|
|
|
throw 'Create fail, response: ${res.body}';
|
|
|
|
}
|
|
|
|
await Provider.of<ThemeModel>(context)
|
2019-10-03 06:55:17 +02:00
|
|
|
.showConfirm(context, Text('Issue created'));
|
2019-10-03 06:16:44 +02:00
|
|
|
Navigator.of(context).pop();
|
|
|
|
} catch (err) {
|
2019-10-13 05:01:29 +02:00
|
|
|
Fimber.e('postWithCredentials failed', ex: err); // TODO:
|
2019-10-03 06:16:44 +02:00
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|