mirror of
https://github.com/R0m1k3/xtremflow.git
synced 2026-10-20 21:48:06 +02:00
feat: Initialize XtremFlow project with core structure, IPTV features, authentication, and video player.
This commit is contained in:
commit
2a28eb44d8
28 files changed
+3279
No files matched your search
@@ -0,0 +1,69 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import '../../features/auth/providers/auth_provider.dart';
|
||||
import '../../features/auth/screens/login_screen.dart';
|
||||
import '../../features/iptv/screens/playlist_selection_screen.dart';
|
||||
import '../../features/iptv/screens/dashboard_screen.dart';
|
||||
import '../../features/admin/screens/admin_panel.dart';
|
||||
import '../models/playlist_config.dart';
|
||||
|
||||
final routerProvider = Provider<GoRouter>((ref) {
|
||||
final authNotifier = ref.watch(authProvider.notifier);
|
||||
final authState = ref.watch(authProvider);
|
||||
|
||||
return GoRouter(
|
||||
initialLocation: '/login',
|
||||
redirect: (context, state) {
|
||||
final isLoggedIn = authState.isAuthenticated;
|
||||
final isLoginRoute = state.matchedLocation == '/login';
|
||||
|
||||
// Redirect to login if not authenticated
|
||||
if (!isLoggedIn && !isLoginRoute) {
|
||||
return '/login';
|
||||
}
|
||||
|
||||
// Redirect to playlists if already logged in and trying to access login
|
||||
if (isLoggedIn && isLoginRoute) {
|
||||
return '/playlists';
|
||||
}
|
||||
|
||||
// Admin guard for /admin route
|
||||
if (state.matchedLocation == '/admin' && !authState.isAdmin) {
|
||||
return '/playlists';
|
||||
}
|
||||
|
||||
return null;
|
||||
},
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: '/login',
|
||||
builder: (context, state) => const LoginScreen(),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/playlists',
|
||||
builder: (context, state) => const PlaylistSelectionScreen(),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/dashboard',
|
||||
builder: (context, state) {
|
||||
final playlist = state.extra as PlaylistConfig?;
|
||||
if (playlist == null) {
|
||||
// Redirect back if no playlist provided
|
||||
WidgetsBinding.instance.addPostFrameCallback((_) {
|
||||
context.go('/playlists');
|
||||
});
|
||||
return const Scaffold(
|
||||
body: Center(child: CircularProgressIndicator()),
|
||||
);
|
||||
}
|
||||
return DashboardScreen(playlist: playlist);
|
||||
},
|
||||
),
|
||||
GoRoute(
|
||||
path: '/admin',
|
||||
builder: (context, state) => const AdminPanel(),
|
||||
),
|
||||
],
|
||||
);
|
||||
});
|
||||
Reference in new issue
Block a user