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

121 lines
3.8 KiB
Dart
Raw Normal View History

2022-09-20 20:00:03 +02:00
import 'package:antd_mobile/antd_mobile.dart';
2022-09-17 14:35:45 +02:00
import 'package:flutter/widgets.dart';
2022-09-13 19:19:52 +02:00
import 'package:flutter_gen/gen_l10n/S.dart';
2022-10-07 18:55:47 +02:00
import 'package:flutter_vector_icons/flutter_vector_icons.dart';
2022-10-06 09:55:35 +02:00
import 'package:git_touch/scaffolds/list_stateful.dart';
import 'package:git_touch/widgets/avatar.dart';
import 'package:git_touch/widgets/markdown_view.dart';
import 'package:gql_github/releases.data.gql.dart';
import 'package:timeago/timeago.dart' as timeago;
2022-10-06 09:55:35 +02:00
class ReleaseItem extends StatefulWidget {
const ReleaseItem({
required this.login,
required this.publishedAt,
required this.name,
required this.tagName,
required this.avatarUrl,
required this.description,
this.releaseAssets,
});
2022-09-21 18:28:21 +02:00
final String? login;
final DateTime? publishedAt;
final String? name;
final String? avatarUrl;
final String? tagName;
final String? description;
final GReleasesData_repository_releases_nodes_releaseAssets? releaseAssets;
2022-10-06 09:55:35 +02:00
@override
State<ReleaseItem> createState() => _ReleaseItemState();
}
class _ReleaseItemState extends State<ReleaseItem> {
var _isExpanded = false;
@override
Widget build(BuildContext context) {
return Column(
children: [
2022-09-06 18:28:12 +02:00
const SizedBox(
height: 12,
),
Row(children: <Widget>[
2022-10-06 09:55:35 +02:00
Avatar(url: widget.avatarUrl, size: AvatarSize.large),
2022-09-06 18:28:12 +02:00
const SizedBox(width: 10),
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Row(
children: <Widget>[
Text(
2022-10-06 09:55:35 +02:00
widget.tagName!,
style: TextStyle(
2022-09-24 20:46:37 +02:00
color: AntTheme.of(context).colorPrimary,
fontSize: 18,
fontWeight: FontWeight.w600,
),
),
],
),
2022-09-06 18:28:12 +02:00
const SizedBox(height: 6),
DefaultTextStyle(
style: TextStyle(
2022-09-24 20:46:37 +02:00
color: AntTheme.of(context).colorTextSecondary,
fontSize: 16,
),
2022-09-13 19:19:52 +02:00
child: Text(
2022-10-06 09:55:35 +02:00
'${widget.login!} ${AppLocalizations.of(context)!.released} ${timeago.format(widget.publishedAt!)}'),
),
],
),
),
]),
2022-10-06 09:55:35 +02:00
if (widget.description != null && widget.description!.isNotEmpty) ...[
MarkdownFlutterView(
2022-10-06 09:55:35 +02:00
widget.description,
),
2022-09-06 18:28:12 +02:00
const SizedBox(height: 10),
],
2022-10-06 09:55:35 +02:00
AntCollapse(
activeKey: _isExpanded ? [''] : [],
onChange: (_) {
setState(() {
_isExpanded = !_isExpanded;
});
},
panels: [
AntCollapsePanel(
key: '',
title:
Text('Assets (${widget.releaseAssets?.nodes?.length ?? 0})'),
child: AntList(
2022-09-22 17:37:06 +02:00
children: [
2022-10-06 09:55:35 +02:00
if (widget.releaseAssets != null)
for (var asset in widget.releaseAssets!.nodes!)
2022-09-20 20:00:03 +02:00
AntListItem(
2022-10-06 09:55:35 +02:00
arrow: const Icon(Ionicons.download_outline),
2022-09-13 19:19:52 +02:00
child: Text(
asset.name,
style: TextStyle(
2022-09-24 20:46:37 +02:00
color: AntTheme.of(context).colorPrimary,
fontSize: 14,
fontWeight: FontWeight.w400,
),
),
2022-10-06 09:55:35 +02:00
onClick: () {
context.pushUrl(asset.downloadUrl);
},
),
],
2022-10-06 09:55:35 +02:00
),
),
],
)
],
);
}
}