mirror of
https://github.com/git-touch/git-touch
synced 2024-12-25 23:34:01 +01:00
64 lines
1.1 KiB
Dart
64 lines
1.1 KiB
Dart
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;
|
|
}
|