git-touch-android-ios-app/lib/screens/user.dart

126 lines
3.0 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
2019-01-25 13:35:20 +01:00
import 'package:flutter/cupertino.dart';
2019-02-03 07:42:50 +01:00
import '../widgets/loading.dart';
import '../providers/settings.dart';
2019-01-31 07:37:25 +01:00
import '../utils/utils.dart';
Future queryUser(String login) async {
var data = await query('''
{
user(login: "$login") {
name
avatarUrl
bio
email
repositories {
totalCount
}
starredRepositories {
totalCount
}
followers {
totalCount
}
following {
totalCount
}
}
}
''');
return data['user'];
}
final GlobalKey<RefreshIndicatorState> _refreshIndicatorKey =
new GlobalKey<RefreshIndicatorState>();
class UserScreen extends StatefulWidget {
final String login;
UserScreen(this.login);
_UserScreenState createState() => _UserScreenState();
}
class _UserScreenState extends State<UserScreen> {
2019-02-03 07:42:50 +01:00
var payload;
@override
void initState() {
super.initState();
2019-02-03 07:42:50 +01:00
_refresh();
}
Future _refresh() async {
queryUser(widget.login).then((_payload) {
setState(() {
2019-02-03 07:42:50 +01:00
payload = _payload;
});
});
}
2019-01-25 13:35:20 +01:00
2019-02-03 07:42:50 +01:00
Widget _buildBody(BuildContext context) {
if (payload == null) {
return Loading(more: false);
}
return Text('loaded');
// return SafeArea(
// child: CupertinoSliverRefreshControl(
// // key: _refreshIndicatorKey,
// onRefresh: _refresh,
// child: Column(
// children: <Widget>[
// Container(
// margin: EdgeInsets.symmetric(vertical: 20.0),
// child: ClipOval(
// child: Image.network(
// payload['avatarUrl'],
// fit: BoxFit.fill,
// width: 64,
// height: 64,
// ),
// ),
// ),
// Row(
// mainAxisAlignment: MainAxisAlignment.spaceEvenly,
// children: <Widget>[
// GestureDetector(
// child: Column(
// children: <Widget>[
// Text(payload['followers']['totalCount'].toString()),
// Text('Followers'),
// ],
// ),
// onTap: () {
// // print(1);
// },
// ),
// Column(
// children: <Widget>[
// Text(payload['following']['totalCount'].toString()),
// Text('Following')
// ],
// )
// ],
// ),
// ],
// ),
// ),
// );
}
2019-01-25 13:35:20 +01:00
@override
Widget build(BuildContext context) {
2019-02-03 07:42:50 +01:00
switch (SettingsProvider.of(context).layout) {
case LayoutMap.cupertino:
return CupertinoPageScaffold(
navigationBar: CupertinoNavigationBar(middle: Text(widget.login)),
child: _buildBody(context),
);
default:
return Scaffold(appBar: AppBar(title: Text(widget.login)));
}
2019-01-25 13:35:20 +01:00
}
}