kopia lustrzana https://gitlab.com/mysocialportal/relatica
105 wiersze
2.9 KiB
Dart
105 wiersze
2.9 KiB
Dart
import 'package:go_router/go_router.dart';
|
|
|
|
import 'globals.dart';
|
|
import 'screens/editor.dart';
|
|
import 'screens/home.dart';
|
|
import 'screens/notifications_screen.dart';
|
|
import 'screens/profile_screen.dart';
|
|
import 'screens/sign_in.dart';
|
|
import 'screens/splash.dart';
|
|
import 'services/auth_service.dart';
|
|
|
|
class ScreenPaths {
|
|
static String splash = '/splash';
|
|
static String home = '/';
|
|
static String profile = '/profile';
|
|
static String notifications = '/notifications';
|
|
static String signin = '/signin';
|
|
static String signup = '/signup';
|
|
static String settings = '/settings';
|
|
}
|
|
|
|
bool needAuthChangeInitialized = true;
|
|
final _authService = getIt<AuthService>();
|
|
final allowedLoggedOut = [
|
|
ScreenPaths.splash,
|
|
ScreenPaths.signin,
|
|
ScreenPaths.signup
|
|
];
|
|
|
|
final appRouter = GoRouter(
|
|
initialLocation: ScreenPaths.home,
|
|
debugLogDiagnostics: true,
|
|
refreshListenable: _authService,
|
|
redirect: (context, state) async {
|
|
print('redirect handler');
|
|
final loggedIn = _authService.loggedIn;
|
|
print('$loggedIn ${state.location}');
|
|
if (!loggedIn && !allowedLoggedOut.contains(state.location)) {
|
|
print('Redirecting to sign in');
|
|
return ScreenPaths.signin;
|
|
}
|
|
|
|
if (loggedIn && allowedLoggedOut.contains(state.location)) {
|
|
print('Redirecting to home');
|
|
return ScreenPaths.home;
|
|
}
|
|
|
|
return null;
|
|
},
|
|
routes: [
|
|
GoRoute(
|
|
path: ScreenPaths.signin,
|
|
name: ScreenPaths.signin,
|
|
builder: (context, state) => SignInScreen(),
|
|
),
|
|
GoRoute(
|
|
path: ScreenPaths.home,
|
|
name: ScreenPaths.home,
|
|
pageBuilder: (context, state) => NoTransitionPage(
|
|
name: ScreenPaths.home,
|
|
child: HomeScreen(),
|
|
),
|
|
),
|
|
GoRoute(
|
|
path: ScreenPaths.profile,
|
|
name: ScreenPaths.profile,
|
|
pageBuilder: (context, state) => NoTransitionPage(
|
|
child: ProfileScreen(),
|
|
),
|
|
),
|
|
GoRoute(
|
|
path: ScreenPaths.notifications,
|
|
name: ScreenPaths.notifications,
|
|
pageBuilder: (context, state) => NoTransitionPage(
|
|
child: NotificationsScreen(),
|
|
),
|
|
),
|
|
GoRoute(
|
|
path: ScreenPaths.splash,
|
|
name: ScreenPaths.splash,
|
|
builder: (context, state) => SplashScreen(),
|
|
),
|
|
GoRoute(
|
|
path: '/post',
|
|
redirect: (context, state) {
|
|
print('post state redirect');
|
|
if (state.location == '/post') {
|
|
return '/post/new';
|
|
}
|
|
|
|
return null;
|
|
},
|
|
routes: [
|
|
GoRoute(
|
|
path: 'new',
|
|
builder: (context, state) => EditorScreen(),
|
|
),
|
|
GoRoute(
|
|
path: 'edit/:id',
|
|
builder: (context, state) =>
|
|
EditorScreen(id: state.params['id'] ?? 'Not Found'),
|
|
),
|
|
])
|
|
]);
|