feat: create issue

This commit is contained in:
Rongjian Zhang 2019-10-03 12:16:44 +08:00
parent 2acf85742b
commit 4b8807e2f1
3 changed files with 112 additions and 9 deletions

View File

@ -212,19 +212,32 @@ class AuthModel with ChangeNotifier {
.timeout(_timeoutDuration);
}
Future<void> putWithCredentials(String url,
{String contentType, String body}) async {
await http
.put(_apiPrefix + url, headers: _headers, body: body ?? {})
Future<http.Response> putWithCredentials(
String url, {
String contentType = 'application/json',
Map<String, dynamic> body = const {},
}) async {
return http
.put(
_apiPrefix + url,
headers: {..._headers, HttpHeaders.contentTypeHeader: contentType},
body: json.encode(body),
)
.timeout(_timeoutDuration);
}
Future<void> postWithCredentials(String url,
{String contentType, String body}) async {
final res = await http
.post(_apiPrefix + url, headers: _headers, body: body ?? {})
Future<http.Response> postWithCredentials(
String url, {
String contentType = 'application/json',
Map<String, dynamic> body = const {},
}) async {
return http
.post(
_apiPrefix + url,
headers: {..._headers, HttpHeaders.contentTypeHeader: contentType},
body: json.encode(body),
)
.timeout(_timeoutDuration);
// print(res.body);
}
Future<void> deleteWithCredentials(String url) async {

View File

@ -0,0 +1,80 @@
import 'dart:io';
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;
});
},
),
),
CupertinoButton(
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)
.showConfirm(context, 'Issue created');
Navigator.of(context).pop();
} catch (err) {
print(err); // TODO:
}
},
),
],
),
);
}
}

View File

@ -1,6 +1,9 @@
import 'package:flutter/material.dart';
import 'package:git_touch/models/auth.dart';
import 'package:git_touch/models/theme.dart';
import 'package:git_touch/scaffolds/list_stateful.dart';
import 'package:git_touch/screens/issue_form.dart';
import 'package:git_touch/widgets/action_entry.dart';
import 'package:git_touch/widgets/app_bar_title.dart';
import 'package:git_touch/widgets/issue_item.dart';
import 'package:provider/provider.dart';
@ -50,6 +53,13 @@ class IssuesScreen extends StatelessWidget {
Widget build(BuildContext context) {
return ListStatefulScaffold(
title: AppBarTitle((isPullRequest ? 'Pull requests' : 'Issues')),
actionBuilder: () => ActionEntry(
iconData: Octicons.plus,
onTap: () {
Provider.of<ThemeModel>(context).pushRoute(
context, (_) => IssueFormScreen(owner, name),
fullscreenDialog: true);
}),
onRefresh: () => _query(context),
onLoadMore: (cursor) => _query(context, cursor),
itemBuilder: (payload) =>