오대리ㅣㅣㅣㅣ
This commit is contained in:
86
mobile/lib/app/router.dart
Normal file
86
mobile/lib/app/router.dart
Normal file
@@ -0,0 +1,86 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
import '../core/session_controller.dart';
|
||||
import '../features/auth/login_page.dart';
|
||||
import '../features/auth/register_page.dart';
|
||||
import '../features/chat/chat_page.dart';
|
||||
import '../features/home/home_page.dart';
|
||||
import '../features/search/search_page.dart';
|
||||
import '../features/settings/settings_page.dart';
|
||||
import '../core/app_settings.dart';
|
||||
import '../theme/toss_theme.dart';
|
||||
|
||||
final goRouterProvider = Provider<GoRouter>((ref) {
|
||||
ref.watch(sessionProvider);
|
||||
ref.watch(themeModeProvider);
|
||||
|
||||
return GoRouter(
|
||||
initialLocation: '/splash',
|
||||
redirect: (context, state) {
|
||||
final async = ref.read(sessionProvider);
|
||||
final loc = state.matchedLocation;
|
||||
|
||||
if (async.isLoading) {
|
||||
return loc == '/splash' ? null : '/splash';
|
||||
}
|
||||
if (async.hasError) {
|
||||
return loc == '/login' ? null : '/login';
|
||||
}
|
||||
final s = async.value;
|
||||
if (s == null) {
|
||||
if (loc == '/login' || loc == '/register') return null;
|
||||
return '/login';
|
||||
}
|
||||
if (loc == '/splash' || loc == '/login' || loc == '/register') {
|
||||
return '/';
|
||||
}
|
||||
return null;
|
||||
},
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: '/splash',
|
||||
builder: (context, state) => const Scaffold(
|
||||
backgroundColor: TossColors.bg,
|
||||
body: Center(child: CircularProgressIndicator(color: TossColors.blue)),
|
||||
),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/login',
|
||||
builder: (context, state) => const LoginPage(),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/register',
|
||||
builder: (context, state) => const RegisterPage(),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/',
|
||||
builder: (context, state) => const HomePage(),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/chat',
|
||||
builder: (context, state) {
|
||||
final q = state.uri.queryParameters;
|
||||
final roomId = q['roomId'];
|
||||
final contextId = q['contextId'];
|
||||
if (roomId == null || contextId == null) {
|
||||
return const Scaffold(body: Center(child: Text('Invalid link')));
|
||||
}
|
||||
return ChatPage(roomId: roomId, contextId: contextId);
|
||||
},
|
||||
),
|
||||
GoRoute(
|
||||
path: '/search',
|
||||
builder: (context, state) {
|
||||
final cid = state.uri.queryParameters['contextId'] ?? '';
|
||||
return SearchPage(contextId: cid);
|
||||
},
|
||||
),
|
||||
GoRoute(
|
||||
path: '/settings',
|
||||
builder: (context, state) => const SettingsPage(),
|
||||
),
|
||||
],
|
||||
);
|
||||
});
|
||||
Reference in New Issue
Block a user