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

175 lines
4.6 KiB
Dart
Raw Normal View History

2022-09-23 20:22:17 +02:00
import 'package:antd_mobile/antd_mobile.dart';
2022-09-17 14:35:45 +02:00
import 'package:flutter/widgets.dart';
2022-10-07 18:55:47 +02:00
import 'package:flutter_vector_icons/flutter_vector_icons.dart';
2019-10-02 09:39:47 +02:00
import 'package:git_touch/utils/utils.dart';
2019-09-14 11:19:33 +02:00
import 'package:git_touch/widgets/avatar.dart';
import 'package:gql_github/users.data.gql.dart';
2019-09-14 11:19:33 +02:00
2019-09-21 19:23:38 +02:00
const userGqlChunk = '''
2019-09-27 15:02:55 +02:00
login
2019-09-21 19:23:38 +02:00
name
avatarUrl
bio
''';
2021-01-17 15:08:32 +01:00
class GhBioWidget extends StatelessWidget {
2022-09-21 18:28:21 +02:00
const GhBioWidget({this.location, required this.createdAt});
2022-09-18 10:51:59 +02:00
final String? location;
final DateTime createdAt;
2021-01-17 15:08:32 +01:00
@override
Widget build(BuildContext context) {
2022-10-08 20:52:20 +02:00
final theme = AntTheme.of(context);
2022-10-03 22:09:36 +02:00
if (location != null) {
2021-01-17 15:08:32 +01:00
return Row(
children: <Widget>[
Icon(
Octicons.location,
size: 15,
2022-10-08 20:52:20 +02:00
color: theme.colorTextSecondary,
2021-01-17 15:08:32 +01:00
),
2022-09-06 18:28:12 +02:00
const SizedBox(width: 4),
2022-09-18 10:51:59 +02:00
Expanded(child: Text(location!, overflow: TextOverflow.ellipsis)),
2021-01-17 15:08:32 +01:00
],
);
}
return Row(
children: <Widget>[
Icon(
Octicons.clock,
size: 15,
2022-10-08 20:52:20 +02:00
color: theme.colorTextSecondary,
2021-01-17 15:08:32 +01:00
),
2022-09-06 18:28:12 +02:00
const SizedBox(width: 4),
2021-01-17 15:08:32 +01:00
Expanded(
2022-09-18 10:51:59 +02:00
child: Text('Joined on ${dateFormat.format(createdAt)}',
2021-01-17 15:08:32 +01:00
overflow: TextOverflow.ellipsis)),
],
);
}
}
2019-09-14 11:19:33 +02:00
class UserItem extends StatelessWidget {
2022-09-06 18:28:12 +02:00
const UserItem.github({
2021-05-16 09:16:35 +02:00
required this.login,
required this.name,
required this.avatarUrl,
required this.bio,
}) : url = '/github/$login';
2019-09-14 11:19:33 +02:00
2022-09-18 10:51:59 +02:00
UserItem.fromGqlUser(GUserParts p)
: login = p.login,
name = p.name,
avatarUrl = p.avatarUrl,
url = '/github/${p.login}',
bio = GhBioWidget(location: p.location, createdAt: p.createdAt);
UserItem.fromGqlOrg(GOrgParts p)
2021-01-17 15:08:32 +01:00
: login = p.login,
name = p.name,
avatarUrl = p.avatarUrl,
2022-09-06 18:28:12 +02:00
url = '/github/${p.login}',
2022-09-18 10:51:59 +02:00
bio = GhBioWidget(location: p.location, createdAt: p.createdAt);
2021-01-17 15:08:32 +01:00
2022-09-06 18:28:12 +02:00
const UserItem.gitlab({
2021-05-16 09:16:35 +02:00
required this.login,
required this.name,
required this.avatarUrl,
required this.bio,
required int? id,
}) : url = '/gitlab/user/$id';
2022-09-06 18:28:12 +02:00
const UserItem.gitlabGroup({
2021-05-16 09:16:35 +02:00
required this.login,
required this.name,
required this.avatarUrl,
required this.bio,
required int? id,
2020-10-08 09:55:26 +02:00
}) : url = '/gitlab/group/$id';
2022-09-06 18:28:12 +02:00
const UserItem.gitea({
2021-05-16 09:16:35 +02:00
required this.login,
required this.name,
required this.avatarUrl,
required this.bio,
2020-10-08 09:55:26 +02:00
}) : url = '/gitea/$login';
2022-09-06 18:28:12 +02:00
const UserItem.gitee({
2021-05-16 09:16:35 +02:00
required this.login,
required this.name,
required this.avatarUrl,
required this.bio,
2020-10-17 12:18:26 +02:00
}) : url = '/gitee/$login';
2022-09-06 18:28:12 +02:00
const UserItem.bitbucket({
2021-05-16 09:16:35 +02:00
required this.login,
required this.name,
required this.avatarUrl,
required this.bio,
2020-10-08 09:55:26 +02:00
}) : url = '/bitbucket/$login?team=1';
2019-09-14 11:19:33 +02:00
2022-09-06 18:28:12 +02:00
const UserItem.gogs({
2021-05-16 09:16:35 +02:00
required this.login,
required this.name,
required this.avatarUrl,
required this.bio,
2021-01-23 15:08:05 +01:00
}) : url = '/gogs/$login';
2022-09-21 18:28:21 +02:00
final String? login;
final String? name;
final String? avatarUrl;
final Widget? bio;
final String url;
2021-01-23 15:08:05 +01:00
2019-09-14 11:19:33 +02:00
@override
Widget build(BuildContext context) {
2022-10-08 20:52:20 +02:00
final theme = AntTheme.of(context);
2022-09-23 20:22:17 +02:00
return AntListItem(
onClick: () {
context.pushUrl(url);
},
child: Row(
children: <Widget>[
Avatar(url: avatarUrl, size: AvatarSize.large),
2022-10-08 20:52:20 +02:00
const SizedBox(width: 12),
2022-09-23 20:22:17 +02:00
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Row(
2022-10-08 20:52:20 +02:00
children: [
if (name != null)
2022-09-23 20:22:17 +02:00
Text(
name!,
2022-10-08 20:52:20 +02:00
style: const TextStyle(
fontSize: 18, fontWeight: FontWeight.w500),
2020-01-02 06:56:50 +01:00
),
2022-09-23 20:22:17 +02:00
Expanded(
child: Text(
login!,
2022-10-08 20:52:20 +02:00
style:
TextStyle(fontSize: 16, color: theme.colorPrimary),
2022-09-23 20:22:17 +02:00
overflow: TextOverflow.ellipsis,
2020-01-02 06:56:50 +01:00
),
2019-12-21 09:16:17 +01:00
),
2022-10-08 20:52:20 +02:00
].withSeparator(const SizedBox(width: 8)),
2022-09-23 20:22:17 +02:00
),
if (bio != null)
2022-10-08 20:52:20 +02:00
Builder(builder: (context) {
return DefaultTextStyle(
style: DefaultTextStyle.of(context).style.copyWith(
color: theme.colorTextSecondary, fontSize: 16),
child: bio!,
);
}),
2022-09-23 20:22:17 +02:00
],
),
)
],
2019-09-14 20:05:34 +02:00
),
2019-09-14 11:19:33 +02:00
);
}
}