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

90 lines
2.5 KiB
Dart
Raw Normal View History

2019-10-03 06:16:44 +02:00
import 'dart:io';
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';
2019-12-13 06:13:45 +01:00
final issueAddRouter = RouterScreen(
'/:owner/:name/issues/new',
(context, params) {
return IssueFormScreen(params['owner'].first, params['name'].first);
},
);
2019-12-13 06:13:45 +01:00
2019-10-03 06:16:44 +02:00
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) {
Fimber.e('postWithCredentials failed', ex: err); // TODO:
2019-10-03 06:16:44 +02:00
}
},
),
],
),
);
}
}