Skip to content
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
277 changes: 68 additions & 209 deletions lib/core/router/app_router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,73 +4,81 @@ import 'package:go_router/go_router.dart';

// bindings
import 'package:ondo/core/router/bindings/login_binding.dart';
import 'package:ondo/core/router/bindings/navigation_binding.dart';
import 'package:ondo/core/router/bindings/password_reset_binding.dart';
import 'package:ondo/core/router/bindings/post_binding.dart';
import 'package:ondo/core/router/bindings/profile_binding.dart';
import 'package:ondo/core/router/bindings/signup_binding.dart';
import 'package:ondo/core/router/bindings/splash_binding.dart';
import 'package:ondo/domain/usecases/search/user_search_use_case.dart';
import 'package:ondo/presentation/notification/screens/notification_screen.dart';
import 'package:ondo/presentation/post/controllers/post_view_controller.dart';
import 'bindings/navigation_binding.dart';

// controllers
import 'package:ondo/presentation/auth/password_reset/controllers/password_reset_flow_controller.dart';

// password reset screens
import 'package:ondo/presentation/auth/password_reset/screens/password_reset_email_code_screen.dart';
import 'package:ondo/presentation/auth/password_reset/screens/password_reset_email_screen.dart';
import 'package:ondo/presentation/auth/password_reset/screens/password_reset_password_completed_screen.dart';
import 'package:ondo/presentation/auth/password_reset/screens/password_reset_password_screen.dart';
// password reset
import 'package:ondo/core/router/routers/password_reset_routes.dart';

// signup screens
import 'package:ondo/presentation/auth/signup/screens/signup_complete_screen.dart';
import 'package:ondo/presentation/auth/signup/screens/signup_email_code_input_screen.dart';
import 'package:ondo/presentation/auth/signup/screens/signup_email_input_screen.dart';
import 'package:ondo/presentation/auth/signup/screens/signup_introduction_input_screen.dart';
import 'package:ondo/presentation/auth/signup/screens/signup_major_interest_setup_screen.dart';
import 'package:ondo/presentation/auth/signup/screens/signup_nickname_setup_screen.dart';
import 'package:ondo/presentation/auth/signup/screens/signup_password_setup_screen.dart';
import 'package:ondo/presentation/auth/signup/screens/signup_profile_image_setup_screen.dart';
import 'package:ondo/presentation/auth/signup/screens/signup_terms_agreement_screen.dart';
//sign up
import 'package:ondo/core/router/routers/sign_up_routes.dart';

// auth / home
import 'package:ondo/presentation/auth/login/screens/login.dart';
import 'package:ondo/presentation/auth/login/screens/splash.dart';
import 'package:ondo/presentation/home/screens/home_screen.dart';
import 'package:ondo/core/router/routers/home_routes.dart';

// navigation
import 'package:ondo/presentation/navigation/screens/navigation_screen.dart';
import 'package:ondo/presentation/post/controllers/post_view_controller.dart';

// post
import 'package:ondo/presentation/post/screens/post_detail_screen.dart';

// profile
import 'package:ondo/presentation/profile/screens/edit_profile_screen.dart';
import 'package:ondo/presentation/profile/screens/my_profile_screen.dart';
import 'package:ondo/presentation/profile/screens/other_profile_screen.dart';
import 'package:ondo/presentation/profile/screens/setting_screen.dart';
import 'package:ondo/presentation/profile/screens/terms_screen.dart';
import 'package:ondo/core/router/routers/profile_route.dart';

//chat
import 'package:ondo/core/router/routers/chat_routes.dart';

//community
import 'package:ondo/core/router/routers/community_routes.dart';

class RoutePaths {
static const String navigation = '/';
//splash
static const String splash = '/splash';

//home
static const String home = '/home';
static const String homeSearch = '/home/search';

//login
static const String login = '/login';

//notification
static const String notification = '/notification';

//post
static const String postDetail = '/post/:postId';

//community
static const String community = '/community';
static const String communitySearch = '/community/search';

//chat
static const String chat = '/chat';
static const String chatSearch = '/chat/search';
static const String chatDetail = '/chat/:chatRoomId';

//password
static const String passwordReset = '/password_reset';
static const String passwordResetInputEmail = '/password_reset/email';
static const String passwordResetInputEmailCode = '/password_reset/email-code';
static const String passwordResetInputEmailCode =
'/password_reset/email-code';
static const String passwordResetInputPassword = '/password_reset/password';
static const String passwordResetComplete = '/password_reset/complete';

//profile
static const String profile = '/profile';
static const String editProfile = '/profile/edit';
static const String profileSetting = '/profile/setting';
static const String profileTerms = '/profile/setting/terms';
static const String userProfile = '/profile/user/:publicId';

//sign up
static const String signup = '/signup';
static const String signupTerms = '/signup/terms';
static const String signupEmail = '/signup/email';
Expand All @@ -95,22 +103,6 @@ final GoRouter appRouter = GoRouter(
return const SplashScreen();
},
),

GoRoute(
path: RoutePaths.navigation,
name: 'navigation',
builder: (context, state) {
NavigationBinding().dependencies();
return const NavigationScreen();
},
),

GoRoute(
path: RoutePaths.home,
name: 'home',
builder: (context, state) => const HomeScreen(),
),

GoRoute(
path: RoutePaths.login,
name: 'login',
Expand All @@ -120,184 +112,51 @@ final GoRouter appRouter = GoRouter(
},
),

GoRoute(
path: RoutePaths.postDetail,
name: 'postDetail',
builder: (context, state) {
final postId = int.parse(state.pathParameters['postId']!);

if (Get.isRegistered<PostViewController>()) {
Get.delete<PostViewController>(force: true);
}

PostBinding(postId, state.extra as bool? ?? false).dependencies();

return PostDetailScreen();
},
),

ShellRoute(
builder: (context, state, child) {
PasswordResetBinding().dependencies();
return child;
},
redirect: (context, state) {
if (!Get.isRegistered<PasswordResetFlowController>()) {
PasswordResetBinding().dependencies();
}

final flowController = Get.find<PasswordResetFlowController>();
final location = state.uri.path;

final allowedPaths = {
RoutePaths.passwordResetInputEmail,
RoutePaths.passwordResetInputEmailCode,
};

if (!flowController.isEmailVerified && !allowedPaths.contains(location)) {
return RoutePaths.passwordResetInputEmail;
if (!Get.isRegistered<UserSearchUseCase>()) {
NavigationBinding().dependencies();
}

return null;
return NavigationScreen(
child: child,
);
},
routes: [
GoRoute(
path: RoutePaths.passwordResetInputEmail,
name: 'passwordResetInputEmail',
builder: (context, state) =>
const PasswordResetEmailInputScreen(),
),
GoRoute(
path: RoutePaths.passwordResetInputEmailCode,
name: 'passwordResetInputEmailCode',
builder: (context, state) =>
const PasswordResetEmailCodeInputScreen(),
),
GoRoute(
path: RoutePaths.passwordResetInputPassword,
name: 'passwordResetInputPassword',
builder: (context, state) =>
const PasswordResetPasswordScreen(),
),
GoRoute(
path: RoutePaths.passwordResetComplete,
name: 'passwordResetComplete',
builder: (context, state) =>
const PasswordResetCompletedScreen(),
),
],
), // password_reset
...HomeRoutes.routes,
...CommunityRoutes.routes,
...ChatRoutes.routes,
...ProfileRoute.routes,

ShellRoute(
builder: (context, state, child) {
ProfileBinding().dependencies();
return child;
},
routes: [
GoRoute(
path: RoutePaths.profile,
name: 'profile',
builder: (context, state) => const MyProfileScreen(),
routes: [
GoRoute(
path: 'edit',
name: 'editProfile',
builder: (context, state) => const EditProfileScreen(),
),
GoRoute(
path: 'setting',
name: 'profileSetting',
builder: (context, state) => const SettingScreen(),
routes: [
GoRoute(
path: 'terms',
name: 'profileTerms',
builder: (context, state) => const TermsScreen(),
),
],
),
GoRoute(
path: 'user/:publicId',
name: 'userProfile',
builder: (context, state) => OtherProfileScreen(publicId: state.pathParameters['publicId'] ?? ''),
),
],
path: RoutePaths.notification,
builder: (context, state) {
return NotificationScreen();
},
),
],
), //profile

ShellRoute(
builder: (context, state, child) {
SignupBinding().dependencies();
return child;
},
redirect: (context, state) {
if (state.uri.toString() == RoutePaths.signup) {
return RoutePaths.signupTerms;
}
return null;
},
routes: [
GoRoute(
path: RoutePaths.signupTerms,
name: 'signupTerms',
builder: (context, state) =>
const SignupTermsAgreementScreen(),
),
GoRoute(
path: RoutePaths.signupEmail,
name: 'signupEmail',
builder: (context, state) =>
const SignupEmailInputScreen(),
),
GoRoute(
path: RoutePaths.signupEmailCode,
name: 'signupEmailCode',
builder: (context, state) =>
const SignupEmailCodeInputScreen(),
),
GoRoute(
path: RoutePaths.signupPassword,
name: 'signupPassword',
builder: (context, state) =>
const SignupPasswordSetupScreen(),
),
GoRoute(
path: RoutePaths.signupNickname,
name: 'signupNickname',
builder: (context, state) =>
const SignupNicknameSetupScreen(),
),
GoRoute(
path: RoutePaths.signupProfileImage,
name: 'signupProfileImage',
builder: (context, state) =>
const SignupProfileImageSetupScreen(),
),
GoRoute(
path: RoutePaths.signupIntroduction,
name: 'signupIntroduction',
builder: (context, state) =>
const SignupIntroductionInputScreen(),
),
GoRoute(
path: RoutePaths.signupMajorInterest,
name: 'signupMajorInterest',
builder: (context, state) =>
const SignupMajorInterestSetupScreen(),
),
GoRoute(
path: RoutePaths.signupComplete,
name: 'signupComplete',
builder: (context, state) =>
const SignupCompleteScreen(),
path: RoutePaths.postDetail,
builder: (context, state) {
final postId = int.parse(state.pathParameters['postId']!);
PostBinding(postId, state.extra as bool? ?? false).dependencies();
Comment thread
eum018 marked this conversation as resolved.
Outdated
return PostDetailScreen(postId: postId,);
},
onExit: (context, state) {
final postId = int.parse(state.pathParameters['postId']!);
Get.delete<PostViewController>(tag: postId.toString(), force: true);
return true;
},
),
],
),

...PasswordResetRoutes.routes,

...SignupRoutes.routes,
],
errorBuilder: (context, state) => const Scaffold(
body: Center(
child: Text('페이지를 찾을 수 없습니다.'),
),
),
);
);
35 changes: 35 additions & 0 deletions lib/core/router/bindings/auth_binding.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import 'package:get/get.dart';

import '../../../data/datasource/auth/auth_local_datasource_impl.dart';
import '../../../data/datasource/auth/auth_remote_datasource.dart';
import '../../../data/datasource/base/auth_local_datasource.dart';
import '../../../data/network/clients/auth_client.dart';
import '../../env.dart';

class AuthBinding extends Bindings {
@override
void dependencies() {
if (Get.isRegistered<AuthRemoteDatasource>()) {
Get.lazyPut<AuthRemoteDatasource>(
() => AuthRemoteDatasource(Env.apiBaseUrl),
fenix: true,
);
}
if (Get.isRegistered<AuthLocalDatasource>()) {
Get.lazyPut<AuthLocalDatasource>(
() => AuthLocalDatasourceImpl(),
fenix: true,
);
}

if (Get.isRegistered<AuthClient>()) {
Get.lazyPut(
() => AuthClient(
localDatasource: Get.find<AuthLocalDatasource>(),
remoteDatasource: Get.find<AuthRemoteDatasource>(),
),
fenix: true,
);
}
Comment thread
eum018 marked this conversation as resolved.
Outdated
}
}
Loading
Loading