1
0
mirror of https://github.com/git-touch/git-touch synced 2024-12-19 03:33:42 +01:00
git-touch-android-ios-app/lib/widgets/user_item.dart

99 lines
2.7 KiB
Dart
Raw Normal View History

2019-09-14 11:19:33 +02:00
import 'package:flutter/material.dart';
2019-09-25 14:51:23 +02:00
import 'package:git_touch/screens/organization.dart';
2019-09-14 20:05:34 +02:00
import 'package:git_touch/screens/user.dart';
2019-09-14 11:19:33 +02:00
import 'package:git_touch/widgets/avatar.dart';
2019-09-14 20:05:34 +02:00
import 'package:git_touch/widgets/link.dart';
2019-09-27 12:23:47 +02:00
import 'package:git_touch/widgets/text_contains_organization.dart';
2019-09-14 11:19:33 +02:00
import 'package:primer/primer.dart';
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
''';
2019-09-14 11:19:33 +02:00
class UserItem extends StatelessWidget {
final String login;
final String name;
final String avatarUrl;
final String bio;
2019-09-14 20:05:34 +02:00
final bool inUserScreen;
2019-09-25 14:51:23 +02:00
final bool isOrganization;
2019-09-14 11:19:33 +02:00
2019-09-27 15:02:55 +02:00
UserItem({
this.login,
2019-09-25 14:51:23 +02:00
this.name,
this.avatarUrl,
this.bio,
this.inUserScreen = false,
this.isOrganization = false,
});
2019-09-27 15:02:55 +02:00
UserItem.fromData(
data, {
this.isOrganization = false,
this.inUserScreen = false,
}) : login = data['login'],
2019-09-25 14:51:23 +02:00
name = data['name'],
avatarUrl = data['avatarUrl'],
2019-09-27 15:02:55 +02:00
bio = data['bio'];
2019-09-14 11:19:33 +02:00
@override
Widget build(BuildContext context) {
2019-09-14 20:05:34 +02:00
final widget = Container(
padding: EdgeInsets.all(10),
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Avatar(url: avatarUrl, size: 24),
SizedBox(width: 10),
Expanded(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: <Widget>[
Text(
name ?? login,
style: TextStyle(
color: PrimerColors.blue500,
2019-09-27 15:02:55 +02:00
fontSize: inUserScreen ? 18 : 16,
2019-09-14 20:05:34 +02:00
fontWeight: FontWeight.w600,
),
2019-09-14 11:19:33 +02:00
),
2019-09-14 20:05:34 +02:00
SizedBox(width: 8),
Text(
login,
2019-09-27 15:02:55 +02:00
style: TextStyle(
color: PrimerColors.gray700,
fontSize: inUserScreen ? 16 : 14),
2019-09-14 20:05:34 +02:00
),
],
),
SizedBox(height: 6),
if (bio != null && bio.isNotEmpty)
2019-09-27 12:23:47 +02:00
TextContainsOrganization(
2019-09-14 20:05:34 +02:00
bio,
2019-09-27 15:02:55 +02:00
style: TextStyle(
color: PrimerColors.gray700,
fontSize: inUserScreen ? 15 : 14),
2019-09-14 11:19:33 +02:00
),
2019-09-14 20:05:34 +02:00
],
),
)
],
),
2019-09-14 11:19:33 +02:00
);
2019-09-14 20:05:34 +02:00
if (inUserScreen) {
return widget;
} else {
2019-09-25 14:51:23 +02:00
return Link(
screenBuilder: (_) =>
isOrganization ? OrganizationScreen(login) : UserScreen(login),
child: widget);
2019-09-14 20:05:34 +02:00
}
2019-09-14 11:19:33 +02:00
}
}