2019-01-23 15:55:16 +01:00
|
|
|
import 'dart:async';
|
2019-01-26 15:10:18 +01:00
|
|
|
import 'package:flutter/widgets.dart';
|
2019-01-23 15:55:16 +01:00
|
|
|
import 'package:rxdart/subjects.dart';
|
|
|
|
import 'package:rxdart/rxdart.dart';
|
2019-01-31 07:37:25 +01:00
|
|
|
import '../utils/utils.dart';
|
2019-01-23 15:55:16 +01:00
|
|
|
|
|
|
|
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;
|
|
|
|
}
|