2021-01-10 07:20:03 +01:00
|
|
|
import 'package:flutter/cupertino.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';
|
2021-06-17 05:02:41 +02:00
|
|
|
import 'package:flutter_gen/gen_l10n/S.dart';
|
2021-01-10 07:20:03 +01:00
|
|
|
|
|
|
|
class GtIssueCommentScreen extends StatefulWidget {
|
|
|
|
final String owner;
|
|
|
|
final String name;
|
|
|
|
final String number;
|
|
|
|
final bool isPr;
|
|
|
|
final String body;
|
|
|
|
final String id;
|
2022-09-06 18:28:12 +02:00
|
|
|
const GtIssueCommentScreen(this.owner, this.name, this.number,
|
|
|
|
{this.isPr = false, this.body = '', this.id = ''});
|
2021-01-10 07:20:03 +01:00
|
|
|
|
|
|
|
@override
|
|
|
|
_GtIssueCommentScreenState createState() => _GtIssueCommentScreenState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _GtIssueCommentScreenState extends State<GtIssueCommentScreen> {
|
|
|
|
bool isEdit = false;
|
2022-09-06 18:28:12 +02:00
|
|
|
final TextEditingController _controller = TextEditingController();
|
2021-01-10 07:20:03 +01:00
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
_controller.text = widget.body;
|
|
|
|
if (_controller.text != '') {
|
|
|
|
isEdit = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
final theme = Provider.of<ThemeModel>(context);
|
|
|
|
final auth = Provider.of<AuthModel>(context);
|
|
|
|
return CommonScaffold(
|
|
|
|
title: Text(isEdit ? 'Update Comment' : 'New Comment'),
|
|
|
|
body: Column(
|
|
|
|
children: <Widget>[
|
|
|
|
Padding(
|
|
|
|
padding: CommonStyle.padding,
|
|
|
|
child: CupertinoTextField(
|
|
|
|
controller: _controller,
|
|
|
|
style: TextStyle(color: theme.palette.text),
|
2021-06-17 05:02:41 +02:00
|
|
|
placeholder: AppLocalizations.of(context)!.body,
|
2021-01-10 07:20:03 +01:00
|
|
|
maxLines: 10,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
CupertinoButton.filled(
|
2022-09-06 18:28:12 +02:00
|
|
|
child: const Text('Comment'),
|
2021-01-10 07:20:03 +01:00
|
|
|
onPressed: () async {
|
|
|
|
if (!isEdit) {
|
2021-01-30 08:42:02 +01:00
|
|
|
await auth.fetchGitea(
|
2021-01-10 07:20:03 +01:00
|
|
|
'/repos/${widget.owner}/${widget.name}/${widget.isPr ? 'pulls' : 'issues'}/${widget.number}/comments',
|
|
|
|
requestType: 'POST',
|
|
|
|
body: {'body': _controller.text, 'repo': widget.name},
|
|
|
|
);
|
|
|
|
} else {
|
2021-01-30 08:42:02 +01:00
|
|
|
await auth.fetchGitea(
|
2021-01-10 07:20:03 +01:00
|
|
|
'/repos/${widget.owner}/${widget.name}/${widget.isPr ? 'pulls' : 'issues'}/comments/${int.parse(widget.id)}',
|
|
|
|
requestType: 'PATCH',
|
|
|
|
body: {'body': _controller.text, 'repo': widget.name},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
Navigator.pop(context, '');
|
|
|
|
await theme.push(
|
|
|
|
context,
|
|
|
|
'/gitea/${widget.owner}/${widget.name}/${widget.isPr ? 'pulls' : 'issues'}/${widget.number}',
|
|
|
|
replace: true,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|