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

92 lines
2.5 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-14 11:19:33 +02:00
import 'package:primer/primer.dart';
2019-09-21 19:23:38 +02:00
const userGqlChunk = '''
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-25 14:51:23 +02:00
UserItem(
this.login, {
this.name,
this.avatarUrl,
this.bio,
this.inUserScreen = false,
this.isOrganization = false,
});
UserItem.fromData(data, {this.isOrganization = false})
: login = data['login'],
name = data['name'],
avatarUrl = data['avatarUrl'],
bio = data['bio'],
inUserScreen = false;
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,
fontSize: 18,
fontWeight: FontWeight.w600,
),
2019-09-14 11:19:33 +02:00
),
2019-09-14 20:05:34 +02:00
SizedBox(width: 8),
Text(
login,
style:
TextStyle(color: PrimerColors.gray700, fontSize: 16),
),
],
),
SizedBox(height: 6),
if (bio != null && bio.isNotEmpty)
2019-09-14 11:19:33 +02:00
Text(
2019-09-14 20:05:34 +02:00
bio,
style: TextStyle(color: PrimerColors.gray700, fontSize: 15),
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
}
}