1
0
mirror of https://github.com/git-touch/git-touch synced 2024-12-25 15:22:38 +01:00
git-touch-android-ios-app/lib/screens/gitlab_issue.dart
2020-01-30 18:57:39 +08:00

106 lines
3.5 KiB
Dart

import 'package:flutter/material.dart';
import 'package:git_touch/models/gitlab.dart';
import 'package:git_touch/scaffolds/refresh_stateful.dart';
import 'package:git_touch/utils/utils.dart';
import 'package:git_touch/widgets/avatar.dart';
import 'package:git_touch/widgets/comment_item.dart';
import 'package:git_touch/widgets/markdown_view.dart';
import 'package:provider/provider.dart';
import 'package:git_touch/models/auth.dart';
import 'package:timeago/timeago.dart' as timeago;
import 'package:tuple/tuple.dart';
final gitlabIssueRouter = RouterScreen(
'/gitlab/projects/:id/issues/:iid',
(context, params) {
return GitlabIssueScreen(
int.parse(params['id'].first),
int.parse(params['iid'].first),
);
},
);
class GitlabIssueScreen extends StatelessWidget {
final int projectId;
final int iid;
final bool isMr;
GitlabIssueScreen(this.projectId, this.iid, {this.isMr = false});
@override
Widget build(BuildContext context) {
return RefreshStatefulScaffold<
Tuple3<GitlabTodoTarget, Iterable<GitlabIssueNote>, List>>(
title: Text('Issue #$iid'),
fetchData: () async {
final type = isMr ? 'merge_requests' : 'issues';
final items = await Future.wait([
Provider.of<AuthModel>(context)
.fetchGitlab('/projects/$projectId/$type/$iid'),
Provider.of<AuthModel>(context)
.fetchGitlab('/projects/$projectId/$type/$iid/notes?sort=asc'),
Provider.of<AuthModel>(context)
.fetchGitlab('/projects/$projectId/$type/$iid/award_emoji'),
]);
return Tuple3(
GitlabTodoTarget.fromJson(items[0]),
(items[1] as List).map((v) => GitlabIssueNote.fromJson(v)),
items[2] as List,
);
},
bodyBuilder: (data, _) {
final issue = data.item1;
final notes = data.item2;
final emoji = data.item3;
return Column(
children: <Widget>[
Container(
padding: CommonStyle.padding,
child: CommentItem(
avatar: Avatar(
url: issue.author.avatarUrl,
linkUrl: '/gitlab/user/${issue.author.id}',
),
createdAt: issue.createdAt,
body: issue.description,
login: issue.author.username,
),
),
CommonStyle.border,
Column(
children: <Widget>[
for (var note in notes)
if (note.system)
Container(
padding: CommonStyle.padding,
child: Text.rich(
TextSpan(children: [
WidgetSpan(child: Avatar(url: note.author.avatarUrl)),
TextSpan(text: note.author.name),
TextSpan(text: note.body),
]),
),
)
else
Container(
padding: CommonStyle.padding,
child: CommentItem(
avatar: Avatar(
url: note.author.avatarUrl,
linkUrl: '/gitlab/user/${note.author.id}',
),
createdAt: note.createdAt,
body: note.body,
login: note.author.username,
),
)
],
)
],
);
},
);
}
}