feat: add user screen
This commit is contained in:
parent
992c7e0cc6
commit
3c83804b3d
|
@ -1,6 +1,6 @@
|
|||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import '../components/event.dart';
|
||||
import '../widgets/event.dart';
|
||||
import '../providers/event.dart';
|
||||
import '../models/event.dart';
|
||||
|
||||
|
|
|
@ -1,11 +1,9 @@
|
|||
// import 'dart:async';
|
||||
// import 'dart:convert';
|
||||
// import '../utils.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import '../widgets/user.dart';
|
||||
|
||||
class ProfileScreen extends StatelessWidget {
|
||||
@override
|
||||
Widget build(context) {
|
||||
return Text('Profile');
|
||||
return UserScreen('pd4d10');
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,63 @@
|
|||
import 'package:flutter/widgets.dart';
|
||||
import 'dart:async';
|
||||
import 'package:rxdart/subjects.dart';
|
||||
import 'package:rxdart/rxdart.dart';
|
||||
import '../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'];
|
||||
}
|
||||
|
||||
class UserBloc {
|
||||
Map<String, dynamic> _userDict = {};
|
||||
|
||||
final _user = BehaviorSubject(seedValue: null);
|
||||
|
||||
fetchUser(String login) async {
|
||||
var user = await queryUser(login);
|
||||
_userDict[login] = user;
|
||||
return user;
|
||||
}
|
||||
|
||||
UserBloc() {}
|
||||
}
|
||||
|
||||
class UserProvider extends InheritedWidget {
|
||||
final UserBloc bloc;
|
||||
|
||||
UserProvider({
|
||||
Key key,
|
||||
Widget child,
|
||||
@required UserBloc bloc,
|
||||
}) : bloc = bloc,
|
||||
super(key: key, child: child);
|
||||
|
||||
@override
|
||||
bool updateShouldNotify(InheritedWidget oldWidget) => true;
|
||||
|
||||
static UserBloc of(BuildContext context) =>
|
||||
(context.inheritFromWidgetOfExactType(UserProvider) as UserProvider).bloc;
|
||||
}
|
|
@ -30,8 +30,8 @@ Future<dynamic> postWithCredentials(String url, String body) async {
|
|||
Future<dynamic> query(String query) async {
|
||||
final data =
|
||||
await postWithCredentials('/graphql', json.encode({'query': query}));
|
||||
if (data['error'] != null) {
|
||||
throw new Exception(data['error'].toString());
|
||||
if (data['errors'] != null) {
|
||||
throw new Exception(data['errors'].toString());
|
||||
}
|
||||
print(data);
|
||||
return data['data'];
|
||||
|
|
|
@ -0,0 +1,106 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:git_flux/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> {
|
||||
var user = null;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
queryUser(widget.login).then((_user) {
|
||||
setState(() {
|
||||
user = _user;
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SafeArea(
|
||||
child: RefreshIndicator(
|
||||
key: _refreshIndicatorKey,
|
||||
onRefresh: () async {
|
||||
var _user = await queryUser(widget.login);
|
||||
setState(() {
|
||||
user = _user;
|
||||
});
|
||||
},
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
Container(
|
||||
margin: EdgeInsets.symmetric(vertical: 20.0),
|
||||
child: ClipOval(
|
||||
child: Image.network(
|
||||
user['avatarUrl'],
|
||||
fit: BoxFit.fill,
|
||||
width: 64,
|
||||
height: 64,
|
||||
),
|
||||
),
|
||||
),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
|
||||
children: <Widget>[
|
||||
GestureDetector(
|
||||
child: Column(
|
||||
children: <Widget>[
|
||||
Text(user['followers']['totalCount'].toString()),
|
||||
Text('Followers'),
|
||||
],
|
||||
),
|
||||
onTap: () {
|
||||
// print(1);
|
||||
},
|
||||
),
|
||||
Column(
|
||||
children: <Widget>[
|
||||
Text(user['following']['totalCount'].toString()),
|
||||
Text('Following')
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
],
|
||||
)),
|
||||
);
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue