-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rename AuthProvider to AuthManager and introduce AuthProvider wrapping widget BREAKING CHANGE: Rename AuthProvider to AuthManager
- Loading branch information
Showing
11 changed files
with
48 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,8 @@ | ||
## 0.0.5 | ||
|
||
* Update dev dependencies. | ||
* Add simple example project. | ||
|
||
## 0.0.4 | ||
|
||
* Upgrade dev dependencies. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import 'package:flutter_auth_provider/flutter_auth_provider.dart'; | ||
import 'package:flutter_auth_provider_example/auth/user.dart'; | ||
|
||
typedef MyAuthProvider = AuthProvider<User>; | ||
typedef MyAuthManager = AuthManager<User>; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,53 +1,22 @@ | ||
import 'package:flutter/foundation.dart'; | ||
import 'package:flutter_auth_provider/src/auth_store.dart'; | ||
import 'package:flutter_auth_provider/src/core.dart'; | ||
import 'package:flutter_auth_provider/src/listener.dart'; | ||
import 'package:flutter/widgets.dart'; | ||
import 'package:flutter_auth_provider/flutter_auth_provider.dart'; | ||
import 'package:provider/provider.dart'; | ||
|
||
/// Auth provider. | ||
class AuthProvider<U> extends AuthService<U> with ChangeNotifier { | ||
final List<LoginListener<U>> _loginListeners = []; | ||
final List<LogoutListener> _logoutListeners = []; | ||
class AuthProvider<U> extends StatelessWidget { | ||
final AuthStore<U> store; | ||
final Widget child; | ||
|
||
/// Initialize AuthProvide with [AuthStore] implementation to store logged in [U]. | ||
AuthProvider(AuthStore<U> store) : super(store); | ||
const AuthProvider({ | ||
Key? key, | ||
required this.store, | ||
required this.child, | ||
}) : super(key: key); | ||
|
||
/// This function should be called after user [U] credentials got authenticated. | ||
/// Authenticated [user] must be provided. | ||
@override | ||
Future<void> onLogin(U user) async { | ||
super.onLogin(user); | ||
for (LoginListener listener in _loginListeners) { | ||
listener.onLogin(user); | ||
} | ||
} | ||
|
||
/// This function should be called when you want to logged out current user. | ||
/// Store will get cleared and [LogoutListener] will get called. | ||
@override | ||
Future<void> logout() async { | ||
super.logout(); | ||
for (LogoutListener listener in _logoutListeners) { | ||
listener.onLogout(); | ||
} | ||
} | ||
|
||
@override | ||
void setUser(U? user) { | ||
super.setUser(user); | ||
notifyListeners(); | ||
} | ||
|
||
/// Add [listener] to LoginListeners. | ||
/// The listeners will get called with logged in user [U]. | ||
/// Setting up Sentry user and other login related activities can be done using the listener. | ||
void addLoginListener(LoginListener<U> onLogin) { | ||
_loginListeners.add(onLogin); | ||
} | ||
|
||
/// Add [listener] to LogoutListeners. | ||
/// The listeners will get called when user logout is called. | ||
/// Clearing Sentry user other cache clearing can be done using the listener | ||
void addLogoutListener(LogoutListener onLogout) { | ||
_logoutListeners.add(onLogout); | ||
Widget build(BuildContext context) { | ||
return ChangeNotifierProvider( | ||
create: (_) => AuthManager<U>(store)..initialize(), | ||
child: child, | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters