2019-02-04 14:38:29 +01:00
|
|
|
import 'package:flutter/material.dart';
|
2019-02-09 07:06:18 +01:00
|
|
|
import '../scaffolds/list.dart';
|
|
|
|
import '../providers/settings.dart';
|
|
|
|
import '../utils/utils.dart';
|
|
|
|
import '../widgets/link.dart';
|
|
|
|
import '../screens/user.dart';
|
2019-03-09 10:03:33 +01:00
|
|
|
import '../widgets/avatar.dart';
|
2019-02-04 14:38:29 +01:00
|
|
|
|
|
|
|
class UsersScreen extends StatefulWidget {
|
2019-02-09 07:06:18 +01:00
|
|
|
final String login;
|
|
|
|
final bool following;
|
|
|
|
|
|
|
|
UsersScreen({this.login, this.following = false});
|
|
|
|
|
2019-02-04 14:38:29 +01:00
|
|
|
@override
|
|
|
|
_UsersScreenState createState() => _UsersScreenState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _UsersScreenState extends State<UsersScreen> {
|
2019-02-09 07:06:18 +01:00
|
|
|
get login => widget.login;
|
|
|
|
get resource => widget.following ? 'following' : 'followers';
|
|
|
|
|
|
|
|
Future<ListPayload> _queryUsers([String cursor]) async {
|
|
|
|
var cursorChunk = cursor == null ? '' : ', after: "$cursor"';
|
|
|
|
|
|
|
|
var data = await SettingsProvider.of(context).query('''
|
|
|
|
{
|
|
|
|
user(login: "$login") {
|
|
|
|
$resource(first: $pageSize$cursorChunk) {
|
|
|
|
pageInfo {
|
|
|
|
hasNextPage
|
|
|
|
endCursor
|
|
|
|
}
|
|
|
|
nodes {
|
|
|
|
login
|
|
|
|
avatarUrl
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
''');
|
|
|
|
var repo = data["user"][resource];
|
|
|
|
|
|
|
|
return ListPayload(
|
|
|
|
cursor: repo["pageInfo"]["endCursor"],
|
2019-02-09 07:20:21 +01:00
|
|
|
hasMore: repo['pageInfo']['hasNextPage'],
|
2019-02-09 07:06:18 +01:00
|
|
|
items: repo["nodes"],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget _buildItem(payload) {
|
|
|
|
return Link(
|
|
|
|
screenBuilder: (_) => UserScreen(payload['login']),
|
|
|
|
child: Container(
|
|
|
|
padding: EdgeInsets.all(10),
|
|
|
|
child: Row(
|
|
|
|
children: <Widget>[
|
2019-03-09 10:03:33 +01:00
|
|
|
Avatar(url: payload['avatarUrl']),
|
2019-02-09 07:06:18 +01:00
|
|
|
Padding(padding: EdgeInsets.only(left: 10)),
|
|
|
|
Text(payload['login'], style: TextStyle(fontSize: 18))
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2019-02-04 14:38:29 +01:00
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2019-02-09 07:06:18 +01:00
|
|
|
return ListScaffold(
|
|
|
|
title: Text('$login\'s $resource'),
|
|
|
|
onRefresh: () => _queryUsers(),
|
|
|
|
onLoadMore: (cursor) => _queryUsers(cursor),
|
|
|
|
itemBuilder: _buildItem,
|
|
|
|
);
|
2019-02-04 14:38:29 +01:00
|
|
|
}
|
|
|
|
}
|