2024-09-11 20:15:53 +00:00
|
|
|
import 'package:finnow_app/api/main.dart';
|
|
|
|
import 'package:finnow_app/auth/model.dart';
|
2024-07-24 20:03:47 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2024-09-11 20:15:53 +00:00
|
|
|
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;
|
2024-07-24 20:03:47 +00:00
|
|
|
|
|
|
|
void main() {
|
2024-09-11 20:15:53 +00:00
|
|
|
setup();
|
2024-07-24 20:03:47 +00:00
|
|
|
runApp(const FinnowApp());
|
|
|
|
}
|
|
|
|
|
2024-09-11 20:15:53 +00:00
|
|
|
void setup() {
|
|
|
|
getIt.registerSingleton<FinnowApi>(FinnowApi());
|
|
|
|
getIt.registerSingleton<AuthenticationModel>(AuthenticationModel());
|
|
|
|
getIt.registerSingleton<GoRouter>(getRouterConfig());
|
2024-07-24 20:03:47 +00:00
|
|
|
}
|
|
|
|
|
2024-09-11 20:15:53 +00:00
|
|
|
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<AuthenticationModel>().state =
|
|
|
|
Unauthenticated(),
|
|
|
|
child: const Text('Logout'))
|
|
|
|
],
|
|
|
|
),
|
2024-07-24 20:03:47 +00:00
|
|
|
),
|
2024-09-11 20:15:53 +00:00
|
|
|
redirect: (context, state) {
|
|
|
|
final bool authenticated =
|
|
|
|
getIt<AuthenticationModel>().state.authenticated();
|
|
|
|
return authenticated ? null : '/login';
|
|
|
|
},
|
|
|
|
routes: [
|
|
|
|
GoRoute(
|
|
|
|
path: '/',
|
|
|
|
redirect: (context, state) {
|
|
|
|
final bool authenticated =
|
|
|
|
getIt<AuthenticationModel>().state.authenticated();
|
|
|
|
return authenticated ? '/profiles' : '/login';
|
|
|
|
}),
|
|
|
|
GoRoute(
|
|
|
|
path: '/profiles',
|
|
|
|
builder: (context, state) => const ProfilesPage(),
|
|
|
|
)
|
|
|
|
]),
|
|
|
|
]);
|
2024-07-24 20:03:47 +00:00
|
|
|
}
|