aboutsummaryrefslogtreecommitdiffhomepage
path: root/lib/auth.dart
diff options
context:
space:
mode:
Diffstat (limited to 'lib/auth.dart')
-rw-r--r--lib/auth.dart43
1 files changed, 0 insertions, 43 deletions
diff --git a/lib/auth.dart b/lib/auth.dart
deleted file mode 100644
index 6ee8a0b..0000000
--- a/lib/auth.dart
+++ /dev/null
@@ -1,43 +0,0 @@
-import 'package:beam_messenger/data/database_helper.dart';
-
-enum AuthState { LOGGED_IN, LOGGED_OUT }
-
-abstract class AuthStateListener {
- void onAuthStateChanged(AuthState state);
-}
-
-// A naive implementation of Observer/Subscriber Pattern. Will do for now.
-class AuthStateProvider {
- static final AuthStateProvider _instance = new AuthStateProvider.internal();
-
- List<AuthStateListener> _subscribers;
-
- factory AuthStateProvider() => _instance;
- AuthStateProvider.internal() {
- _subscribers = new List<AuthStateListener>();
- initState();
- }
-
- void initState() async {
- var db = new DatabaseHelper();
- var isLoggedIn = await db.isLoggedIn();
- if (isLoggedIn)
- notify(AuthState.LOGGED_IN);
- else
- notify(AuthState.LOGGED_OUT);
- }
-
- void subscribe(AuthStateListener listener) {
- _subscribers.add(listener);
- }
-
- void dispose(AuthStateListener listener) {
- for (var l in _subscribers) {
- if (l == listener) _subscribers.remove(l);
- }
- }
-
- void notify(AuthState state) {
- _subscribers.forEach((AuthStateListener s) => s.onAuthStateChanged(state));
- }
-}