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

95 lines
3.3 KiB
Dart
Raw Normal View History

2022-09-17 14:35:45 +02:00
import 'package:flutter/widgets.dart';
import 'package:flutter_gen/gen_l10n/S.dart';
import 'package:git_touch/models/auth.dart';
2019-12-04 15:00:39 +01:00
import 'package:git_touch/models/gitlab.dart';
2019-11-01 18:12:17 +01:00
import 'package:git_touch/scaffolds/refresh_stateful.dart';
import 'package:git_touch/utils/utils.dart';
import 'package:git_touch/widgets/avatar.dart';
2020-01-30 11:57:39 +01:00
import 'package:git_touch/widgets/comment_item.dart';
2019-11-01 18:12:17 +01:00
import 'package:provider/provider.dart';
2019-12-04 15:00:39 +01:00
import 'package:tuple/tuple.dart';
2019-11-01 18:12:17 +01:00
2020-02-07 15:26:37 +01:00
class GlIssueScreen extends StatelessWidget {
2022-09-21 18:28:21 +02:00
const GlIssueScreen(this.projectId, this.iid, {this.isMr = false});
2019-11-01 18:12:17 +01:00
final int projectId;
2019-12-04 15:00:39 +01:00
final int iid;
2019-11-01 18:12:17 +01:00
final bool isMr;
@override
Widget build(BuildContext context) {
2019-12-04 15:00:39 +01:00
return RefreshStatefulScaffold<
2021-05-16 09:16:35 +02:00
Tuple3<GitlabTodoTarget, Iterable<GitlabIssueNote>, List?>>(
2022-09-06 18:28:12 +02:00
title: Text('${AppLocalizations.of(context)!.issue}#$iid'),
fetch: () async {
2019-11-01 18:12:17 +01:00
final type = isMr ? 'merge_requests' : 'issues';
2020-10-04 14:37:23 +02:00
final auth = context.read<AuthModel>();
2019-11-01 18:12:17 +01:00
final items = await Future.wait([
2020-10-04 14:37:23 +02:00
auth.fetchGitlab('/projects/$projectId/$type/$iid'),
auth.fetchGitlab('/projects/$projectId/$type/$iid/notes?sort=asc'),
auth.fetchGitlab('/projects/$projectId/$type/$iid/award_emoji'),
2019-11-01 18:12:17 +01:00
]);
2019-12-04 15:00:39 +01:00
return Tuple3(
2020-01-28 16:39:26 +01:00
GitlabTodoTarget.fromJson(items[0]),
2019-12-04 15:00:39 +01:00
(items[1] as List).map((v) => GitlabIssueNote.fromJson(v)),
2021-05-16 09:16:35 +02:00
items[2] as List?,
2019-12-04 15:00:39 +01:00
);
2019-11-01 18:12:17 +01:00
},
2019-11-02 13:54:23 +01:00
bodyBuilder: (data, _) {
2019-12-04 15:00:39 +01:00
final issue = data.item1;
final notes = data.item2;
2021-01-30 08:42:02 +01:00
// final emoji = data.item3;
2019-11-01 18:12:17 +01:00
return Column(
children: <Widget>[
Container(
padding: CommonStyle.padding,
2020-01-30 11:57:39 +01:00
child: CommentItem(
avatar: Avatar(
2021-05-16 09:16:35 +02:00
url: issue.author!.avatarUrl,
linkUrl: '/gitlab/user/${issue.author!.id}',
2020-01-30 11:57:39 +01:00
),
createdAt: issue.createdAt,
body: issue.description,
2021-05-16 09:16:35 +02:00
login: issue.author!.username,
prefix: 'gitlab',
2019-11-01 18:12:17 +01:00
),
),
CommonStyle.border,
Column(
2020-01-30 11:57:39 +01:00
children: <Widget>[
for (var note in notes)
2021-05-16 09:16:35 +02:00
if (note.system!)
2020-01-30 11:57:39 +01:00
Container(
padding: CommonStyle.padding,
child: Text.rich(
TextSpan(children: [
2021-05-30 19:07:31 +02:00
WidgetSpan(
child: Avatar(url: note.author!.avatarUrl)),
2021-05-16 09:16:35 +02:00
TextSpan(text: note.author!.name),
2020-01-30 11:57:39 +01:00
TextSpan(text: note.body),
]),
),
)
else
Container(
padding: CommonStyle.padding,
child: CommentItem(
avatar: Avatar(
2021-05-16 09:16:35 +02:00
url: note.author!.avatarUrl,
linkUrl: '/gitlab/user/${note.author!.id}',
2020-01-30 11:57:39 +01:00
),
createdAt: note.createdAt,
body: note.body,
2021-05-16 09:16:35 +02:00
login: note.author!.username,
prefix: 'gitlab',
2019-11-01 18:12:17 +01:00
),
2020-01-30 11:57:39 +01:00
)
],
2019-11-01 18:12:17 +01:00
)
],
);
},
);
}
}