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

81 lines
2.6 KiB
Dart
Raw Normal View History

2022-09-24 20:46:37 +02:00
import 'package:antd_mobile/antd_mobile.dart';
import 'package:flutter/cupertino.dart';
2022-09-22 19:50:45 +02:00
import 'package:flutter_gen/gen_l10n/S.dart';
import 'package:git_touch/models/auth.dart';
import 'package:git_touch/scaffolds/common.dart';
import 'package:git_touch/utils/utils.dart';
import 'package:provider/provider.dart';
class GeIssueCommentScreen extends StatefulWidget {
2022-09-21 18:28:21 +02:00
const GeIssueCommentScreen(this.owner, this.name, this.number,
{this.isPr = false, this.body = '', this.id = ''});
final String owner;
final String name;
final String number;
final bool isPr;
final String body;
final String id;
@override
2022-10-03 19:05:29 +02:00
State<GeIssueCommentScreen> createState() => _GeIssueCommentScreenState();
}
class _GeIssueCommentScreenState extends State<GeIssueCommentScreen> {
bool isEdit = false;
2022-09-06 18:28:12 +02:00
final TextEditingController _controller = TextEditingController();
@override
void initState() {
super.initState();
_controller.text = widget.body;
if (_controller.text != '') {
isEdit = true;
}
}
@override
Widget build(BuildContext 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,
2022-09-24 20:46:37 +02:00
style: TextStyle(color: AntTheme.of(context).colorText),
placeholder: AppLocalizations.of(context)!.body,
maxLines: 10,
),
),
2022-10-04 19:51:53 +02:00
AntButton(
color: AntTheme.of(context).colorPrimary,
2022-09-06 18:28:12 +02:00
child: const Text('Comment'),
2022-10-04 19:51:53 +02:00
onClick: () async {
if (!isEdit) {
2021-01-30 08:42:02 +01:00
await auth.fetchGitee(
'/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.fetchGitee(
'/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, '');
2022-09-22 19:50:45 +02:00
await context.pushUrl(
'/gitee/${widget.owner}/${widget.name}/${widget.isPr ? 'pulls' : 'issues'}/${widget.number}',
replace: true,
);
},
),
],
),
);
}
}