Advertisement
Guest User

Untitled

a guest
Oct 22nd, 2019
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Dart 0.93 KB | None | 0 0
  1. class AuthManager extends ChangeNotifier{
  2.  
  3.   AuthManager(){
  4.     _userInfo = UserInfo.initial();
  5.   }
  6.  
  7.   UserInfo _userInfo;
  8.   UserInfo get userInfo => _userInfo;
  9.  
  10.  
  11.   void setUserInfo(UserInfo userInfo){
  12.     _userInfo = userInfo;
  13.     notifyListeners();
  14.   }
  15. }
  16.  
  17.  
  18. class ApiClient {
  19.   final AuthManager authManager;
  20.  
  21.   Dio _httpClient;
  22.   Dio get httpClient => _httpClient;
  23.   GraphQLClient _graphQLClient;
  24.   GraphQLClient get graphQLClient => _graphQLClient;
  25.  
  26.   ApiClient({
  27.     @required Dio Function(String token) httpClientBuilder,
  28.     @required GraphQLClient Function(String token) graphQlClientBuilder,
  29.     @required this.authManager
  30.   }) {
  31.     void _buildClients(){
  32.       _httpClient = httpClientBuilder(authManager.userInfo.accessToken);
  33.       _graphQLClient = graphQlClientBuilder(authManager.userInfo.accessToken);
  34.     }
  35.     _buildClients();
  36.     authManager.addListener(() {
  37.       _buildClients();
  38.     });
  39.   }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement