From 294ff11a438b7dd8f976f85a448ea624c8afbdba Mon Sep 17 00:00:00 2001 From: Luca Coduri Date: Sat, 3 Sep 2022 20:30:18 +0200 Subject: [PATCH 1/3] pop fix + isAdmin fix --- lib/provider/auth_provider.dart | 6 ++-- lib/router/home_guard.dart | 2 ++ lib/router/router.dart | 5 +-- lib/router/router.gr.dart | 2 +- lib/screens/login.dart | 2 +- lib/screens/profile.dart | 4 ++- lib/screens/register.dart | 9 ++---- lib/widgets/register/register_third_page.dart | 2 +- pubspec.lock | 31 ++++++++++++------- 9 files changed, 33 insertions(+), 30 deletions(-) diff --git a/lib/provider/auth_provider.dart b/lib/provider/auth_provider.dart index 0a88589..a46dcfc 100644 --- a/lib/provider/auth_provider.dart +++ b/lib/provider/auth_provider.dart @@ -28,9 +28,9 @@ class AuthProvider extends ChangeNotifier { } Future signIn(String email, String password) async { - //final isConnected = await _auth.signIn(email: email, password: password); - final isConnected = - await _auth.signIn(email: "luca.coduri@heig-vd.ch", password: 'crepes'); + final isConnected = await _auth.signIn(email: email, password: password); + //final isConnected = + //await _auth.signIn(email: "luca.coduri@heig-vd.ch", password: 'crepes'); _isAdmin = await _auth.isDietitian(); if (isConnected) { fetchClient(); diff --git a/lib/router/home_guard.dart b/lib/router/home_guard.dart index fc674cd..5456093 100644 --- a/lib/router/home_guard.dart +++ b/lib/router/home_guard.dart @@ -1,3 +1,5 @@ +import 'dart:developer'; + import 'package:auto_route/auto_route.dart'; import 'package:get_it/get_it.dart'; import 'package:pdg_app/router/router.gr.dart'; diff --git a/lib/router/router.dart b/lib/router/router.dart index 2c0a5b8..bb8d3ff 100644 --- a/lib/router/router.dart +++ b/lib/router/router.dart @@ -29,10 +29,6 @@ import 'home_guard.dart'; guards: [AuthGuard], initial: true, children: [ - RedirectRoute( - path: '', - redirectTo: 'diary', - ), AutoRoute( page: EmptyRouterPage, name: 'ChatRouterPage', @@ -57,6 +53,7 @@ import 'home_guard.dart'; AutoRoute( page: EmptyRouterPage, name: "MainRouterPage", + initial: true, path: 'main', children: [ AutoRoute( diff --git a/lib/router/router.gr.dart b/lib/router/router.gr.dart index 113cb1f..689993c 100644 --- a/lib/router/router.gr.dart +++ b/lib/router/router.gr.dart @@ -141,7 +141,7 @@ class AppRouter extends _i16.RootStackRouter { _i16.RouteConfig('#redirect', path: '', parent: HomeScreenRoute.name, - redirectTo: 'diary', + redirectTo: 'main', fullMatch: true), _i16.RouteConfig(ChatRouterPage.name, path: 'chat', diff --git a/lib/screens/login.dart b/lib/screens/login.dart index 4c0125d..6ffa6a4 100644 --- a/lib/screens/login.dart +++ b/lib/screens/login.dart @@ -38,7 +38,7 @@ class _LoginScreenState extends State { await auth.signIn(_emailController.text, _passwordController.text); if (auth.isConnected()) { // ignore: use_build_context_synchronously - AutoRouter.of(context).navigate(const HomeScreenRoute()); + AutoRouter.of(context).replaceAll([const HomeScreenRoute()]); } else { // ignore: use_build_context_synchronously ScaffoldMessenger.of(context).showSnackBar( diff --git a/lib/screens/profile.dart b/lib/screens/profile.dart index 43c07ff..67c58fe 100644 --- a/lib/screens/profile.dart +++ b/lib/screens/profile.dart @@ -24,7 +24,9 @@ class ProfileScreen extends StatelessWidget { clientInsurance: "09734789789248943", onLogoutPressed: () { GetIt.I.get().signOut(); - AutoRouter.of(context).navigate(const LoginScreenRoute()); + context.router.replaceAll([ + const LoginScreenRoute(), + ]); }, ); } diff --git a/lib/screens/register.dart b/lib/screens/register.dart index 07325f3..a733b99 100644 --- a/lib/screens/register.dart +++ b/lib/screens/register.dart @@ -12,11 +12,8 @@ class RegisterScreen extends StatelessWidget { @override Widget build(BuildContext context) { - return Scaffold( - body: Register( - onRegisterPress: () => - AutoRouter.of(context).navigate(const RegisterScreenRoute()), - ), + return const Scaffold( + body: Register(), ); /// Navigating to the RegisterScreenRoute. @@ -24,12 +21,10 @@ class RegisterScreen extends StatelessWidget { } class Register extends StatelessWidget { - final void Function()? onRegisterPress; final double screenWidth; const Register({ this.screenWidth = 0, - this.onRegisterPress, Key? key, }) : super(key: key); diff --git a/lib/widgets/register/register_third_page.dart b/lib/widgets/register/register_third_page.dart index 693e7dc..0264ed2 100644 --- a/lib/widgets/register/register_third_page.dart +++ b/lib/widgets/register/register_third_page.dart @@ -47,7 +47,7 @@ class _RegisterThirdPageState extends State { registerProvider.createUser(), ); - router.push(const HomeScreenRoute()); + router.replaceAll([const HomeScreenRoute()]); }), ), ], diff --git a/pubspec.lock b/pubspec.lock index 54ee55e..70ea6bd 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -28,7 +28,7 @@ packages: name: async url: "https://pub.dartlang.org" source: hosted - version: "2.9.0" + version: "2.8.2" auto_route: dependency: "direct main" description: @@ -112,7 +112,14 @@ packages: name: characters url: "https://pub.dartlang.org" source: hosted - version: "1.2.1" + version: "1.2.0" + charcode: + dependency: transitive + description: + name: charcode + url: "https://pub.dartlang.org" + source: hosted + version: "1.3.1" checked_yaml: dependency: transitive description: @@ -126,7 +133,7 @@ packages: name: clock url: "https://pub.dartlang.org" source: hosted - version: "1.1.1" + version: "1.1.0" cloud_firestore: dependency: "direct main" description: @@ -245,7 +252,7 @@ packages: name: fake_async url: "https://pub.dartlang.org" source: hosted - version: "1.3.1" + version: "1.3.0" fake_cloud_firestore: dependency: "direct dev" description: @@ -596,21 +603,21 @@ packages: name: matcher url: "https://pub.dartlang.org" source: hosted - version: "0.12.12" + version: "0.12.11" material_color_utilities: dependency: transitive description: name: material_color_utilities url: "https://pub.dartlang.org" source: hosted - version: "0.1.5" + version: "0.1.4" meta: dependency: transitive description: name: meta url: "https://pub.dartlang.org" source: hosted - version: "1.8.0" + version: "1.7.0" mime: dependency: transitive description: @@ -638,7 +645,7 @@ packages: name: path url: "https://pub.dartlang.org" source: hosted - version: "1.8.2" + version: "1.8.1" path_provider: dependency: "direct main" description: @@ -804,7 +811,7 @@ packages: name: source_span url: "https://pub.dartlang.org" source: hosted - version: "1.9.0" + version: "1.8.2" stack_trace: dependency: transitive description: @@ -832,7 +839,7 @@ packages: name: string_scanner url: "https://pub.dartlang.org" source: hosted - version: "1.1.1" + version: "1.1.0" table_calendar: dependency: "direct main" description: @@ -846,14 +853,14 @@ packages: name: term_glyph url: "https://pub.dartlang.org" source: hosted - version: "1.2.1" + version: "1.2.0" test_api: dependency: transitive description: name: test_api url: "https://pub.dartlang.org" source: hosted - version: "0.4.12" + version: "0.4.9" timing: dependency: transitive description: From 4657553870ce368d437a371ba87c0519cd101ff5 Mon Sep 17 00:00:00 2001 From: Luca Coduri Date: Sat, 3 Sep 2022 20:48:02 +0200 Subject: [PATCH 2/3] 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(); From 55e67c901337ed26f4bb404b781cc8d8cee1a091 Mon Sep 17 00:00:00 2001 From: Luca Coduri Date: Sat, 3 Sep 2022 20:49:32 +0200 Subject: [PATCH 3/3] lint fix --- lib/router/home_guard.dart | 2 -- lib/screens/register.dart | 2 -- 2 files changed, 4 deletions(-) diff --git a/lib/router/home_guard.dart b/lib/router/home_guard.dart index 5456093..fc674cd 100644 --- a/lib/router/home_guard.dart +++ b/lib/router/home_guard.dart @@ -1,5 +1,3 @@ -import 'dart:developer'; - import 'package:auto_route/auto_route.dart'; import 'package:get_it/get_it.dart'; import 'package:pdg_app/router/router.gr.dart'; diff --git a/lib/screens/register.dart b/lib/screens/register.dart index a733b99..9be3cbc 100644 --- a/lib/screens/register.dart +++ b/lib/screens/register.dart @@ -5,8 +5,6 @@ import 'package:pdg_app/widgets/register/top_shape.dart'; import 'package:pdg_app/widgets/register/bottom_shape.dart'; import 'package:provider/provider.dart'; -import '../router/router.gr.dart'; - class RegisterScreen extends StatelessWidget { const RegisterScreen({Key? key}) : super(key: key);