Solian/lib/router.dart

304 lines
9.1 KiB
Dart
Raw Permalink Normal View History

import 'package:animations/animations.dart';
import 'package:flutter/material.dart';
2024-05-18 10:17:16 +00:00
import 'package:go_router/go_router.dart';
2024-09-17 12:40:44 +00:00
import 'package:solian/bootstrapper.dart';
2024-05-29 14:42:11 +00:00
import 'package:solian/models/realm.dart';
2024-06-08 05:28:49 +00:00
import 'package:solian/screens/about.dart';
2024-05-18 10:17:16 +00:00
import 'package:solian/screens/account.dart';
2024-05-23 13:12:47 +00:00
import 'package:solian/screens/account/friend.dart';
2024-09-17 07:59:17 +00:00
import 'package:solian/screens/account/preferences/notifications.dart';
2024-10-13 06:13:16 +00:00
import 'package:solian/screens/account/preferences/security.dart';
2024-09-17 06:21:37 +00:00
import 'package:solian/screens/account/profile_edit.dart';
2024-07-26 08:53:05 +00:00
import 'package:solian/screens/account/profile_page.dart';
import 'package:solian/screens/auth/signin.dart';
import 'package:solian/screens/auth/signup.dart';
2024-05-25 17:21:08 +00:00
import 'package:solian/screens/channel/channel_chat.dart';
2024-05-26 15:13:43 +00:00
import 'package:solian/screens/channel/channel_detail.dart';
2024-05-25 16:11:00 +00:00
import 'package:solian/screens/channel/channel_organize.dart';
import 'package:solian/screens/chat.dart';
2024-09-01 09:20:26 +00:00
import 'package:solian/screens/dashboard.dart';
2024-07-09 13:23:38 +00:00
import 'package:solian/screens/feed/search.dart';
2024-05-25 05:19:16 +00:00
import 'package:solian/screens/posts/post_detail.dart';
2024-07-09 13:23:38 +00:00
import 'package:solian/screens/feed/draft_box.dart';
2024-05-28 14:13:23 +00:00
import 'package:solian/screens/realms.dart';
2024-05-29 14:42:11 +00:00
import 'package:solian/screens/realms/realm_detail.dart';
2024-05-28 14:13:23 +00:00
import 'package:solian/screens/realms/realm_organize.dart';
2024-05-29 14:42:11 +00:00
import 'package:solian/screens/realms/realm_view.dart';
import 'package:solian/screens/explore.dart';
2024-07-10 02:50:10 +00:00
import 'package:solian/screens/posts/post_editor.dart';
2024-07-30 18:44:49 +00:00
import 'package:solian/screens/settings.dart';
2024-07-12 05:15:46 +00:00
import 'package:solian/shells/root_shell.dart';
2024-06-27 06:31:15 +00:00
import 'package:solian/shells/title_shell.dart';
import 'package:solian/theme.dart';
import 'package:solian/widgets/sidebar/empty_placeholder.dart';
2024-05-18 10:17:16 +00:00
2024-05-18 16:56:32 +00:00
abstract class AppRouter {
2024-05-18 10:17:16 +00:00
static GoRouter instance = GoRouter(
routes: [
2024-07-12 05:15:46 +00:00
ShellRoute(
2024-09-17 12:40:44 +00:00
builder: (context, state, child) => BootstrapperShell(
key: const Key('global-bootstrapper'),
child: RootShell(
state: state,
child: child,
),
2024-07-12 05:15:46 +00:00
),
routes: [
2024-09-01 09:20:26 +00:00
GoRoute(
path: '/',
name: 'dashboard',
builder: (context, state) => TitleShell(
state: state,
child: const DashboardScreen(),
),
),
2024-07-12 05:15:46 +00:00
_feedRoute,
_chatRoute,
_realmRoute,
_accountRoute,
2024-07-30 18:44:49 +00:00
GoRoute(
path: '/about',
name: 'about',
builder: (context, state) => TitleShell(
state: state,
child: const AboutScreen(),
),
),
GoRoute(
path: '/settings',
name: 'settings',
builder: (context, state) => TitleShell(
state: state,
child: const SettingScreen(),
),
),
2024-07-12 05:15:46 +00:00
],
),
2024-07-06 12:55:53 +00:00
],
);
static final ShellRoute _feedRoute = ShellRoute(
2024-07-06 13:14:19 +00:00
builder: (context, state, child) => child,
2024-07-06 12:55:53 +00:00
routes: [
GoRoute(
path: '/explore',
name: 'explore',
builder: (context, state) => const ExploreScreen(),
2024-07-06 12:55:53 +00:00
),
2024-07-07 06:22:53 +00:00
GoRoute(
path: '/drafts',
name: 'draftBox',
builder: (context, state) => const DraftBoxScreen(),
),
GoRoute(
path: '/posts/search',
name: 'postSearch',
2024-07-07 06:22:53 +00:00
builder: (context, state) => TitleShell(
state: state,
child: FeedSearchScreen(
tag: state.uri.queryParameters['tag'],
category: state.uri.queryParameters['category'],
),
),
),
2024-07-06 12:55:53 +00:00
GoRoute(
path: '/posts/view/:id',
2024-07-06 12:55:53 +00:00
name: 'postDetail',
builder: (context, state) => TitleShell(
state: state,
child: PostDetailScreen(
id: state.pathParameters['id']!,
2024-07-10 02:50:10 +00:00
),
),
),
GoRoute(
path: '/posts/editor',
name: 'postEditor',
pageBuilder: (context, state) {
2024-07-09 13:23:38 +00:00
final arguments = state.extra as PostPublishArguments?;
return CustomTransitionPage(
child: PostPublishScreen(
edit: arguments?.edit,
reply: arguments?.reply,
repost: arguments?.repost,
realm: arguments?.realm,
mode: int.tryParse(state.uri.queryParameters['mode'] ?? '0') ?? 0,
),
transitionsBuilder:
(context, animation, secondaryAnimation, child) {
return FadeThroughTransition(
fillColor: Theme.of(context).scaffoldBackgroundColor,
animation: animation,
secondaryAnimation: secondaryAnimation,
child: child,
);
},
2024-07-06 12:55:53 +00:00
);
},
),
],
);
static final ShellRoute _chatRoute = ShellRoute(
2024-10-06 03:12:54 +00:00
builder: (context, state, child) =>
AppTheme.isLargeScreen(context) ? ChatListShell(child: child) : child,
2024-07-06 12:55:53 +00:00
routes: [
GoRoute(
path: '/chat',
name: 'chat',
builder: (context, state) => AppTheme.isLargeScreen(context)
? const EmptyPagePlaceholder()
: const ChatScreen(),
2024-07-06 12:55:53 +00:00
),
GoRoute(
path: '/chat/organize',
name: 'channelOrganizing',
builder: (context, state) {
final arguments = state.extra as ChannelOrganizeArguments?;
return ChannelOrganizeScreen(
edit: arguments?.edit,
realm: arguments?.realm,
);
},
),
GoRoute(
path: '/chat/:alias',
name: 'channelChat',
builder: (context, state) {
return ChannelChatScreen(
key: UniqueKey(),
2024-07-06 12:55:53 +00:00
alias: state.pathParameters['alias']!,
realm: state.uri.queryParameters['realm'] ?? 'global',
);
},
),
GoRoute(
path: '/chat/:alias/detail',
name: 'channelDetail',
builder: (context, state) {
final arguments = state.extra as ChannelDetailArguments;
return TitleShell(
state: state,
2024-10-06 17:47:34 +00:00
isResponsive: true,
2024-07-06 12:55:53 +00:00
child: ChannelDetailScreen(
channel: arguments.channel,
profile: arguments.profile,
realm: state.uri.queryParameters['realm'] ?? 'global',
2024-05-29 14:42:11 +00:00
),
2024-07-06 12:55:53 +00:00
);
},
),
],
);
static final ShellRoute _realmRoute = ShellRoute(
2024-07-12 13:59:16 +00:00
builder: (context, state, child) => child,
2024-07-06 12:55:53 +00:00
routes: [
GoRoute(
path: '/realms',
name: 'realms',
2024-07-12 13:59:16 +00:00
builder: (context, state) => const RealmListScreen(),
2024-07-06 12:55:53 +00:00
),
GoRoute(
path: '/realms/:alias/detail',
name: 'realmDetail',
builder: (context, state) => TitleShell(
state: state,
child: RealmDetailScreen(
realm: state.extra as Realm,
alias: state.pathParameters['alias']!,
2024-05-29 14:42:11 +00:00
),
2024-07-06 12:55:53 +00:00
),
),
GoRoute(
path: '/realm/organize',
name: 'realmOrganizing',
builder: (context, state) {
final arguments = state.extra as RealmOrganizeArguments?;
return RealmOrganizeScreen(
edit: arguments?.edit,
);
},
),
GoRoute(
path: '/realm/:alias',
name: 'realmView',
builder: (context, state) {
return RealmViewScreen(
alias: state.pathParameters['alias']!,
);
},
),
],
);
static final ShellRoute _accountRoute = ShellRoute(
builder: (context, state, child) => child,
2024-07-06 12:55:53 +00:00
routes: [
GoRoute(
path: '/account',
name: 'account',
builder: (context, state) => TitleShell(
state: state,
isCenteredTitle: true,
child: const AccountScreen(),
),
2024-07-06 12:55:53 +00:00
),
GoRoute(
path: '/account/friend',
name: 'accountFriend',
2024-07-23 17:17:41 +00:00
builder: (context, state) => const FriendScreen(),
2024-07-06 12:55:53 +00:00
),
GoRoute(
path: '/account/personalize',
2024-09-13 15:19:33 +00:00
name: 'accountProfile',
2024-07-06 12:55:53 +00:00
builder: (context, state) => TitleShell(
state: state,
child: const PersonalizeScreen(),
),
),
2024-09-17 07:59:17 +00:00
GoRoute(
path: '/account/preferences/notifications',
name: 'notificationPreferences',
builder: (context, state) => TitleShell(
state: state,
child: const NotificationPreferencesScreen(),
),
),
2024-10-13 06:13:16 +00:00
GoRoute(
path: '/account/preferences/auth',
name: 'authPreferences',
builder: (context, state) => TitleShell(
state: state,
child: const AuthPreferencesScreen(),
),
),
2024-07-26 08:53:05 +00:00
GoRoute(
path: '/account/view/:name',
name: 'accountProfilePage',
builder: (context, state) => AccountProfilePage(
name: state.pathParameters['name']!,
),
),
GoRoute(
path: '/auth/sign-in',
name: 'signin',
builder: (context, state) => TitleShell(
state: state,
isCenteredTitle: true,
child: const SignInScreen(),
),
),
GoRoute(
path: '/auth/sign-up',
name: 'signup',
builder: (context, state) => TitleShell(
state: state,
isCenteredTitle: true,
child: const SignUpScreen(),
),
),
2024-05-18 10:17:16 +00:00
],
);
}