import 'package:finnow_app/api/main.dart'; import 'package:finnow_app/auth/model.dart'; import 'package:flutter/material.dart'; import 'package:get_it/get_it.dart'; import 'package:go_router/go_router.dart'; import 'package:watch_it/watch_it.dart'; import 'app.dart'; import 'login_page.dart'; import 'profiles_page.dart'; import 'register_page.dart'; final getIt = GetIt.instance; void main() { setup(); runApp(const FinnowApp()); } void setup() { getIt.registerSingleton(FinnowApi()); getIt.registerSingleton(AuthenticationModel()); getIt.registerSingleton(getRouterConfig()); } GoRouter getRouterConfig() { return GoRouter(routes: [ GoRoute(path: '/login', builder: (context, state) => const LoginPage()), GoRoute( path: '/register', builder: (context, state) => const RegisterPage()), // Once a user has logged in, they're directed to a scaffold for the /profiles page. ShellRoute( builder: (context, state, child) => Scaffold( body: child, appBar: AppBar( title: const Text('Finnow'), backgroundColor: Colors.grey, actions: [ TextButton( onPressed: () => getIt().state = Unauthenticated(), child: const Text('Logout')) ], ), ), redirect: (context, state) { final bool authenticated = getIt().state.authenticated(); return authenticated ? null : '/login'; }, routes: [ GoRoute( path: '/', redirect: (context, state) { final bool authenticated = getIt().state.authenticated(); return authenticated ? '/profiles' : '/login'; }), GoRoute( path: '/profiles', builder: (context, state) => const ProfilesPage(), ) ]), ]); }