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

118 lines
4.3 KiB
Dart
Raw Normal View History

2022-09-24 20:46:37 +02:00
import 'package:antd_mobile/antd_mobile.dart';
2022-09-17 14:35:45 +02:00
import 'package:flutter/widgets.dart';
import 'package:git_touch/models/auth.dart';
import 'package:git_touch/models/bitbucket.dart';
2022-09-17 14:35:45 +02:00
import 'package:git_touch/models/theme.dart';
import 'package:git_touch/scaffolds/refresh_stateful.dart';
import 'package:git_touch/utils/utils.dart';
import 'package:git_touch/widgets/action_entry.dart';
import 'package:git_touch/widgets/avatar.dart';
import 'package:git_touch/widgets/comment_item.dart';
2022-09-17 14:35:45 +02:00
import 'package:git_touch/widgets/link.dart';
import 'package:primer/primer.dart';
import 'package:provider/provider.dart';
import 'package:tuple/tuple.dart';
class BbIssueScreen extends StatelessWidget {
2022-09-21 18:28:21 +02:00
const BbIssueScreen(this.owner, this.name, this.number, {this.isPr = false});
final String owner;
final String name;
final String number;
final bool isPr;
@override
Widget build(BuildContext context) {
2021-06-14 08:02:52 +02:00
return RefreshStatefulScaffold<Tuple2<BbIssues, Iterable<BbComment>>>(
title: Text('Issue: #$number'),
fetch: () async {
final auth = context.read<AuthModel>();
2021-06-14 08:02:52 +02:00
final res = await Future.wait([
auth
.fetchBbJson('/repositories/$owner/$name/issues/$number')
.then((value) => BbIssues.fromJson(value)),
auth
.fetchBbWithPage(
'/repositories/$owner/$name/issues/$number/comments')
.then(
(value) => [for (var v in value.items) BbComment.fromJson(v)])
]);
2021-06-14 08:02:52 +02:00
return Tuple2(res[0] as BbIssues, res[1] as Iterable<BbComment>);
},
actionBuilder: (data, _) => ActionEntry(
iconData: Octicons.plus,
url: '/bitbucket/$owner/$name/issues/$number/comment',
),
bodyBuilder: (data, _) {
final issue = data.item1;
final comments = data.item2;
final theme = context.read<ThemeModel>();
return Column(children: <Widget>[
Container(
padding: CommonStyle.padding,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
2021-05-16 09:16:35 +02:00
LinkWidget(
url: '/bitbucket/$owner/$name',
child: Row(
children: <Widget>[
Avatar(
2021-05-16 09:16:35 +02:00
url: issue.reporter!.avatarUrl,
size: AvatarSize.extraSmall,
),
2022-09-06 18:28:12 +02:00
const SizedBox(width: 4),
Text(
'$owner / $name',
style: TextStyle(
fontSize: 17,
2022-09-24 20:46:37 +02:00
color: AntTheme.of(context).colorTextSecondary,
),
),
2022-09-06 18:28:12 +02:00
const SizedBox(width: 4),
Text(
'#$number',
style: TextStyle(
fontSize: 17,
2022-09-24 20:46:37 +02:00
color: AntTheme.of(context).colorWeak,
),
),
],
),
),
2022-09-06 18:28:12 +02:00
const SizedBox(height: 8),
Text(
2021-05-16 09:16:35 +02:00
issue.title!,
2022-09-06 18:28:12 +02:00
style: const TextStyle(
fontSize: 20,
fontWeight: FontWeight.w600,
),
),
2022-09-06 18:28:12 +02:00
const SizedBox(height: 8),
StateLabel(StateLabelStatus.issueOpened),
2022-09-06 18:28:12 +02:00
const SizedBox(height: 16),
CommonStyle.border,
],
)),
Column(children: [
for (var comment in comments) ...[
Padding(
2022-09-06 18:28:12 +02:00
padding: const EdgeInsets.only(left: 10),
child: CommentItem(
avatar: Avatar(
2021-05-16 09:16:35 +02:00
url: comment.user!.avatarUrl,
linkUrl: '/bitbucket/${comment.user!.displayName}',
),
2021-05-16 09:16:35 +02:00
createdAt: DateTime.parse(comment.createdOn!),
body: comment.content!.raw,
login: comment.user!.displayName,
prefix: 'bitbucket')),
CommonStyle.border,
2022-09-06 18:28:12 +02:00
const SizedBox(height: 16),
],
]),
]);
},
);
}
}