From 4657553870ce368d437a371ba87c0519cd101ff5 Mon Sep 17 00:00:00 2001 From: Luca Coduri Date: Sat, 3 Sep 2022 20:48:02 +0200 Subject: [PATCH] fix data on reboot --- lib/main.dart | 1 + lib/provider/auth_provider.dart | 13 ++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/lib/main.dart b/lib/main.dart index c38aa71..5d23c2c 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -22,6 +22,7 @@ Future setup() async { clientApi: FirebaseUser(FirebaseFirestore.instance), ), ); + await GetIt.I.get().init(); } void main() async { diff --git a/lib/provider/auth_provider.dart b/lib/provider/auth_provider.dart index a46dcfc..718b9ab 100644 --- a/lib/provider/auth_provider.dart +++ b/lib/provider/auth_provider.dart @@ -17,6 +17,17 @@ class AuthProvider extends ChangeNotifier { : _auth = auth, _userApi = clientApi; + Future init() async { + if (isConnected()) { + final values = await Future.wait([ + fetchClient(), + _auth.isDietitian(), + ]); + + _isAdmin = values[1] as bool; + } + } + bool get isAdmin => _isAdmin; User? get user => _client; @@ -33,7 +44,7 @@ class AuthProvider extends ChangeNotifier { //await _auth.signIn(email: "luca.coduri@heig-vd.ch", password: 'crepes'); _isAdmin = await _auth.isDietitian(); if (isConnected) { - fetchClient(); + await fetchClient(); } notifyListeners();