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'; 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, List>>( title: Text('Issue #$iid'), fetchData: () async { final type = isMr ? 'merge_requests' : 'issues'; final items = await Future.wait([ Provider.of(context) .fetchGitlab('/projects/$projectId/$type/$iid'), Provider.of(context) .fetchGitlab('/projects/$projectId/$type/$iid/notes?sort=asc'), Provider.of(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: [ 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: [ 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, ), ) ], ) ], ); }, ); } }