git-touch-android-ios-app/lib/widgets/issue_item.dart

161 lines
5.1 KiB
Dart
Raw Normal View History

2022-09-17 14:35:45 +02:00
import 'package:flutter/widgets.dart';
2019-11-08 11:29:08 +01:00
import 'package:git_touch/models/theme.dart';
2019-09-25 14:51:23 +02:00
import 'package:git_touch/widgets/avatar.dart';
2019-11-08 11:29:08 +01:00
import 'package:provider/provider.dart';
2019-09-25 14:51:23 +02:00
import 'package:timeago/timeago.dart' as timeago;
2022-09-17 14:35:45 +02:00
import 'package:git_touch/utils/utils.dart';
import 'package:git_touch/widgets/link.dart';
2019-09-25 14:51:23 +02:00
const issueGqlChunk = '''
2020-01-28 16:19:05 +01:00
url
2019-09-25 14:51:23 +02:00
number
title
updatedAt
author {
login
avatarUrl
}
repository {
owner {
login
}
name
}
labels(first: 10) {
nodes {
name
color
}
}
comments {
totalCount
}
''';
class IssueItem extends StatelessWidget {
2021-05-16 09:16:35 +02:00
final String? url;
final String subtitle;
2021-05-16 09:16:35 +02:00
final String? title;
final int? commentCount;
final DateTime? updatedAt;
final String? avatarUrl;
final String? author;
final Widget? labels;
2020-01-28 16:19:05 +01:00
final bool isPr;
2019-09-25 14:51:23 +02:00
2022-09-06 18:28:12 +02:00
const IssueItem({
2021-05-16 09:16:35 +02:00
required this.url,
required this.subtitle,
required this.title,
required this.commentCount,
required this.updatedAt,
required this.avatarUrl,
required this.author,
2020-01-28 16:19:05 +01:00
this.labels,
this.isPr = false,
});
2019-09-25 14:51:23 +02:00
@override
Widget build(BuildContext context) {
2019-11-08 11:29:08 +01:00
final theme = Provider.of<ThemeModel>(context);
2021-05-16 09:16:35 +02:00
return LinkWidget(
2020-01-28 16:19:05 +01:00
url: url,
2019-09-25 14:51:23 +02:00
child: Container(
2019-10-02 10:09:54 +02:00
padding: CommonStyle.padding,
2019-09-25 14:51:23 +02:00
// color: payload.unread ? Colors.white : Colors.black12,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
2020-01-28 16:19:05 +01:00
Icon(isPr ? Octicons.git_pull_request : Octicons.issue_opened,
color: GithubPalette.open, size: 20),
2022-09-06 18:28:12 +02:00
const SizedBox(width: 6),
2019-09-25 14:51:23 +02:00
Expanded(
child: Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
2022-09-06 18:28:12 +02:00
children: join(const SizedBox(height: 8), [
2019-10-03 05:00:59 +02:00
Text.rich(
2020-01-12 08:44:07 +01:00
TextSpan(
children: [
2020-01-28 16:19:05 +01:00
TextSpan(text: '$title '),
2020-01-12 08:44:07 +01:00
TextSpan(
2022-09-06 18:28:12 +02:00
text: subtitle,
2020-01-12 08:44:07 +01:00
style: TextStyle(
2020-01-27 08:11:51 +01:00
color: theme.palette.tertiaryText,
2020-01-14 06:33:02 +01:00
fontWeight: FontWeight.normal,
2020-01-12 08:44:07 +01:00
),
),
],
),
2019-09-25 14:51:23 +02:00
style: TextStyle(
2020-01-12 08:44:07 +01:00
fontSize: 17,
2020-01-27 08:11:51 +01:00
color: theme.palette.text,
2019-09-25 14:51:23 +02:00
fontWeight: FontWeight.w600,
),
),
2021-05-16 09:16:35 +02:00
if (labels != null) labels!,
2019-09-25 14:51:23 +02:00
DefaultTextStyle(
style: TextStyle(
2020-01-12 08:44:07 +01:00
fontSize: 14,
2020-01-27 08:11:51 +01:00
color: theme.palette.secondaryText,
2020-01-12 08:44:07 +01:00
),
2019-09-25 14:51:23 +02:00
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
// FIXME: Deleted user
2020-01-28 16:19:05 +01:00
if (avatarUrl != null) ...[
2020-01-14 06:33:02 +01:00
Avatar(
size: AvatarSize.extraSmall,
2020-01-28 16:19:05 +01:00
url: avatarUrl,
2019-09-25 14:51:23 +02:00
),
2022-09-06 18:28:12 +02:00
const SizedBox(width: 4),
2019-09-25 14:51:23 +02:00
Text(
2021-05-16 09:16:35 +02:00
author!,
2022-09-17 14:35:45 +02:00
style: const TextStyle(
fontWeight: FontWeight.w600),
2019-09-25 14:51:23 +02:00
),
],
2021-01-06 07:57:31 +01:00
Expanded(
child: Text(
2022-09-06 18:28:12 +02:00
' opened ${timeago.format(updatedAt!)}',
2021-01-06 07:57:31 +01:00
style: TextStyle(
fontSize: 17,
color: theme.palette.secondaryText,
),
overflow: TextOverflow.ellipsis,
)),
2021-05-16 09:16:35 +02:00
if (commentCount! > 0) ...[
2022-09-06 18:28:12 +02:00
const Expanded(child: SizedBox()),
2019-09-25 14:51:23 +02:00
Icon(Octicons.comment,
2020-01-12 08:44:07 +01:00
size: 14,
2020-01-27 08:11:51 +01:00
color: theme.palette.secondaryText),
2022-09-06 18:28:12 +02:00
const SizedBox(width: 3),
2020-01-28 16:19:05 +01:00
Text(numberFormat.format(commentCount))
2019-09-25 14:51:23 +02:00
],
],
),
)
]),
),
),
),
// Column(
// children: <Widget>[
// Icon(Octicons.check, color: Colors.black45),
// Icon(Octicons.unmute, color: Colors.black45)
// ],
// ),
],
),
],
),
),
);
}
}