2019-01-27 17:37:44 +01:00
|
|
|
import 'package:flutter/material.dart';
|
2019-01-25 13:35:20 +01:00
|
|
|
import 'package:flutter/cupertino.dart';
|
2019-02-08 12:34:07 +01:00
|
|
|
import 'package:url_launcher/url_launcher.dart';
|
2019-02-10 11:50:40 +01:00
|
|
|
import 'package:share/share.dart';
|
2019-03-07 14:10:52 +01:00
|
|
|
import 'package:flutter_svg/flutter_svg.dart';
|
|
|
|
import 'package:github_contributions/github_contributions.dart';
|
2019-02-07 07:35:19 +01:00
|
|
|
import '../providers/settings.dart';
|
2019-02-08 07:06:48 +01:00
|
|
|
import '../scaffolds/refresh.dart';
|
2019-02-03 08:50:17 +01:00
|
|
|
import '../widgets/avatar.dart';
|
2019-02-04 14:38:29 +01:00
|
|
|
import '../widgets/entry_item.dart';
|
2019-02-03 16:10:10 +01:00
|
|
|
import '../widgets/list_group.dart';
|
|
|
|
import '../widgets/repo_item.dart';
|
2019-02-08 12:34:07 +01:00
|
|
|
import '../widgets/link.dart';
|
2019-02-20 09:31:22 +01:00
|
|
|
import '../widgets/action.dart';
|
2019-02-04 11:32:39 +01:00
|
|
|
import '../screens/repos.dart';
|
2019-02-04 14:38:29 +01:00
|
|
|
import '../screens/users.dart';
|
2019-02-08 12:34:07 +01:00
|
|
|
import '../screens/settings.dart';
|
2019-01-31 07:37:25 +01:00
|
|
|
import '../utils/utils.dart';
|
2019-01-27 17:37:44 +01:00
|
|
|
|
2019-02-07 07:35:19 +01:00
|
|
|
class UserScreen extends StatefulWidget {
|
|
|
|
final String login;
|
2019-02-08 12:34:07 +01:00
|
|
|
final bool showSettings;
|
2019-02-07 07:35:19 +01:00
|
|
|
|
2019-02-08 12:34:07 +01:00
|
|
|
UserScreen(this.login, {this.showSettings = false});
|
2019-02-07 07:35:19 +01:00
|
|
|
|
|
|
|
_UserScreenState createState() => _UserScreenState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _UserScreenState extends State<UserScreen> {
|
2019-03-10 16:34:34 +01:00
|
|
|
Future query() async {
|
2019-02-07 07:35:19 +01:00
|
|
|
var login = widget.login;
|
|
|
|
var data = await SettingsProvider.of(context).query('''
|
2019-01-27 17:37:44 +01:00
|
|
|
{
|
|
|
|
user(login: "$login") {
|
|
|
|
name
|
|
|
|
avatarUrl
|
|
|
|
bio
|
2019-03-10 16:34:34 +01:00
|
|
|
websiteUrl
|
2019-01-27 17:37:44 +01:00
|
|
|
email
|
2019-02-08 12:34:07 +01:00
|
|
|
company
|
|
|
|
location
|
2019-01-27 17:37:44 +01:00
|
|
|
starredRepositories {
|
|
|
|
totalCount
|
|
|
|
}
|
|
|
|
followers {
|
|
|
|
totalCount
|
|
|
|
}
|
|
|
|
following {
|
|
|
|
totalCount
|
|
|
|
}
|
2019-02-10 12:15:50 +01:00
|
|
|
repositories(first: $pageSize, ownerAffiliations: OWNER, orderBy: {field: STARGAZERS, direction: DESC}) {
|
2019-02-03 08:50:17 +01:00
|
|
|
totalCount
|
|
|
|
nodes {
|
2019-02-04 11:32:39 +01:00
|
|
|
$repoChunk
|
2019-02-03 08:50:17 +01:00
|
|
|
}
|
|
|
|
}
|
2019-02-10 12:15:50 +01:00
|
|
|
pinnedRepositories(first: $pageSize) {
|
2019-02-03 08:50:17 +01:00
|
|
|
nodes {
|
2019-02-04 11:32:39 +01:00
|
|
|
$repoChunk
|
2019-02-03 08:50:17 +01:00
|
|
|
}
|
|
|
|
}
|
2019-02-10 11:50:40 +01:00
|
|
|
viewerCanFollow
|
|
|
|
viewerIsFollowing
|
|
|
|
url
|
2019-01-27 17:37:44 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
''');
|
2019-02-07 07:35:19 +01:00
|
|
|
return data['user'];
|
2019-02-06 15:28:04 +01:00
|
|
|
}
|
2019-02-04 11:32:39 +01:00
|
|
|
|
2019-02-08 13:52:10 +01:00
|
|
|
Widget _buildRepos(payload) {
|
2019-02-04 11:32:39 +01:00
|
|
|
String title;
|
|
|
|
List items;
|
|
|
|
if (payload['pinnedRepositories']['nodes'].length == 0) {
|
|
|
|
title = 'Popular repositories';
|
|
|
|
items = payload['repositories']['nodes'];
|
|
|
|
} else {
|
|
|
|
title = 'Pinned repositories';
|
|
|
|
items = payload['pinnedRepositories']['nodes'];
|
|
|
|
}
|
|
|
|
|
|
|
|
return ListGroup(
|
2019-03-10 14:26:05 +01:00
|
|
|
title: Text(
|
|
|
|
title,
|
|
|
|
style: TextStyle(fontSize: 16),
|
|
|
|
),
|
|
|
|
items: items,
|
|
|
|
itemBuilder: (item, _) {
|
|
|
|
return RepoItem(
|
|
|
|
item,
|
|
|
|
showOwner: item['owner']['login'] != widget.login,
|
|
|
|
);
|
|
|
|
},
|
|
|
|
);
|
2019-02-04 11:32:39 +01:00
|
|
|
}
|
|
|
|
|
2019-03-10 16:34:34 +01:00
|
|
|
Widget _buildInfo(payload) {
|
2019-02-08 12:34:07 +01:00
|
|
|
// TODO: redesign the UI to show all information
|
|
|
|
String email = payload['email'] ?? '';
|
|
|
|
if (email.isNotEmpty) {
|
|
|
|
return Link(
|
2019-02-10 11:50:40 +01:00
|
|
|
material: false,
|
2019-02-08 12:34:07 +01:00
|
|
|
child: Row(children: <Widget>[
|
|
|
|
Icon(
|
|
|
|
Octicons.mail,
|
|
|
|
color: Colors.black54,
|
|
|
|
size: 16,
|
|
|
|
),
|
|
|
|
Padding(padding: EdgeInsets.only(left: 4)),
|
2019-02-10 12:45:08 +01:00
|
|
|
Text(email, style: TextStyle(color: Colors.black54, fontSize: 15))
|
2019-02-08 12:34:07 +01:00
|
|
|
]),
|
2019-02-21 11:43:41 +01:00
|
|
|
onTap: () {
|
2019-02-08 12:34:07 +01:00
|
|
|
launch('mailto:' + email);
|
|
|
|
},
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
String company = payload['company'] ?? '';
|
|
|
|
if (company.isNotEmpty) {
|
|
|
|
return Row(children: <Widget>[
|
|
|
|
Icon(
|
|
|
|
Octicons.organization,
|
|
|
|
color: Colors.black54,
|
|
|
|
size: 16,
|
|
|
|
),
|
|
|
|
Padding(padding: EdgeInsets.only(left: 4)),
|
|
|
|
Text(company, style: TextStyle(color: Colors.black54, fontSize: 16))
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
String location = payload['location'] ?? '';
|
|
|
|
if (location.isNotEmpty) {
|
|
|
|
return Row(children: <Widget>[
|
|
|
|
Icon(
|
|
|
|
Octicons.location,
|
|
|
|
color: Colors.black54,
|
|
|
|
size: 16,
|
|
|
|
),
|
|
|
|
Padding(padding: EdgeInsets.only(left: 4)),
|
|
|
|
Text(location, style: TextStyle(color: Colors.black54, fontSize: 16))
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return Container();
|
|
|
|
}
|
|
|
|
|
2019-01-25 13:35:20 +01:00
|
|
|
@override
|
2019-01-27 17:37:44 +01:00
|
|
|
Widget build(BuildContext context) {
|
2019-02-03 08:50:17 +01:00
|
|
|
return RefreshScaffold(
|
2019-03-07 14:10:52 +01:00
|
|
|
onRefresh: () {
|
|
|
|
return Future.wait(
|
2019-03-10 16:34:34 +01:00
|
|
|
[query(), getContributionsSvg(widget.login)],
|
2019-03-07 14:10:52 +01:00
|
|
|
);
|
|
|
|
},
|
2019-02-03 16:10:10 +01:00
|
|
|
title: Text(widget.login),
|
2019-03-07 14:10:52 +01:00
|
|
|
trailingBuilder: (data) {
|
|
|
|
var payload = data[0];
|
2019-02-10 11:50:40 +01:00
|
|
|
if (widget.showSettings) {
|
|
|
|
return Link(
|
|
|
|
child: Icon(Icons.settings, size: 24),
|
|
|
|
screenBuilder: (_) => SettingsScreen(),
|
|
|
|
material: false,
|
|
|
|
fullscreenDialog: true,
|
|
|
|
);
|
|
|
|
} else {
|
2019-02-20 09:31:22 +01:00
|
|
|
List<Action> actions = [];
|
|
|
|
|
|
|
|
if (payload['viewerCanFollow']) {
|
|
|
|
actions.add(Action(
|
|
|
|
text: payload['viewerIsFollowing'] ? 'Unfollow' : 'Follow',
|
|
|
|
onPress: () async {
|
|
|
|
if (payload['viewerIsFollowing']) {
|
|
|
|
await SettingsProvider.of(context)
|
|
|
|
.deleteWithCredentials('/user/following/${widget.login}');
|
|
|
|
payload['viewerIsFollowing'] = false;
|
|
|
|
} else {
|
|
|
|
SettingsProvider.of(context)
|
|
|
|
.putWithCredentials('/user/following/${widget.login}');
|
|
|
|
payload['viewerIsFollowing'] = true;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
actions.addAll([
|
|
|
|
Action(
|
|
|
|
text: 'Share',
|
|
|
|
onPress: () {
|
|
|
|
Share.share(payload['url']);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
Action(
|
|
|
|
text: 'Open in Browser',
|
|
|
|
onPress: () {
|
|
|
|
launch(payload['url']);
|
|
|
|
},
|
|
|
|
),
|
|
|
|
]);
|
|
|
|
|
|
|
|
return ActionButton(title: 'User Actions', actions: actions);
|
2019-02-10 11:50:40 +01:00
|
|
|
}
|
|
|
|
},
|
2019-03-07 14:10:52 +01:00
|
|
|
bodyBuilder: (data) {
|
|
|
|
var payload = data[0];
|
|
|
|
var contributions = data[1];
|
|
|
|
|
2019-02-03 16:10:10 +01:00
|
|
|
return Column(
|
|
|
|
children: <Widget>[
|
|
|
|
Container(
|
|
|
|
padding: EdgeInsets.all(10),
|
|
|
|
child: Row(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: <Widget>[
|
2019-03-09 10:03:33 +01:00
|
|
|
Avatar(url: payload['avatarUrl'], size: 28),
|
2019-02-03 16:10:10 +01:00
|
|
|
Padding(padding: EdgeInsets.only(left: 10)),
|
|
|
|
Expanded(
|
|
|
|
child: Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
children: <Widget>[
|
2019-02-10 12:45:08 +01:00
|
|
|
Text(
|
|
|
|
payload['name'] ?? widget.login,
|
|
|
|
style: TextStyle(height: 1.2, fontSize: 16),
|
|
|
|
),
|
2019-02-03 16:10:10 +01:00
|
|
|
Padding(padding: EdgeInsets.only(top: 10)),
|
2019-03-10 16:34:34 +01:00
|
|
|
_buildInfo(payload),
|
2019-02-03 16:10:10 +01:00
|
|
|
],
|
|
|
|
),
|
|
|
|
)
|
|
|
|
],
|
|
|
|
),
|
2019-02-03 08:50:17 +01:00
|
|
|
),
|
2019-02-03 16:10:10 +01:00
|
|
|
Container(
|
|
|
|
decoration: BoxDecoration(
|
2019-02-04 14:38:29 +01:00
|
|
|
border: Border(
|
|
|
|
bottom: BorderSide(color: Colors.black12),
|
|
|
|
top: BorderSide(color: Colors.black12),
|
|
|
|
),
|
|
|
|
),
|
2019-02-03 16:10:10 +01:00
|
|
|
child: Row(
|
|
|
|
children: <Widget>[
|
2019-02-04 14:38:29 +01:00
|
|
|
EntryItem(
|
|
|
|
count: payload['repositories']['totalCount'],
|
|
|
|
text: 'Repositories',
|
2019-02-09 06:42:18 +01:00
|
|
|
screenBuilder: (context) =>
|
|
|
|
ReposScreen(login: widget.login),
|
2019-02-04 14:38:29 +01:00
|
|
|
),
|
|
|
|
EntryItem(
|
|
|
|
count: payload['starredRepositories']['totalCount'],
|
|
|
|
text: 'Stars',
|
2019-02-09 06:42:18 +01:00
|
|
|
screenBuilder: (context) =>
|
|
|
|
ReposScreen(login: widget.login, star: true),
|
2019-02-04 14:38:29 +01:00
|
|
|
),
|
|
|
|
EntryItem(
|
|
|
|
count: payload['followers']['totalCount'],
|
|
|
|
text: 'Followers',
|
2019-02-09 07:06:18 +01:00
|
|
|
screenBuilder: (context) =>
|
|
|
|
UsersScreen(login: widget.login),
|
2019-02-04 14:38:29 +01:00
|
|
|
),
|
|
|
|
EntryItem(
|
|
|
|
count: payload['following']['totalCount'],
|
|
|
|
text: 'Following',
|
2019-02-09 07:06:18 +01:00
|
|
|
screenBuilder: (context) =>
|
|
|
|
UsersScreen(login: widget.login, following: true),
|
2019-02-04 14:38:29 +01:00
|
|
|
),
|
2019-02-03 16:10:10 +01:00
|
|
|
],
|
|
|
|
),
|
2019-02-03 08:50:17 +01:00
|
|
|
),
|
2019-03-07 14:10:52 +01:00
|
|
|
Container(
|
|
|
|
child: SvgPicture.string(contributions),
|
|
|
|
padding: EdgeInsets.symmetric(horizontal: 10),
|
|
|
|
),
|
2019-02-08 13:52:10 +01:00
|
|
|
_buildRepos(payload),
|
2019-02-03 16:10:10 +01:00
|
|
|
],
|
|
|
|
);
|
|
|
|
},
|
2019-02-03 08:50:17 +01:00
|
|
|
);
|
2019-01-25 13:35:20 +01:00
|
|
|
}
|
|
|
|
}
|