Surface/lib/router.dart

276 lines
8.5 KiB
Dart
Raw Permalink Normal View History

2024-11-15 23:08:29 +08:00
import 'package:animations/animations.dart';
2024-11-21 22:55:00 +08:00
import 'package:flutter/material.dart';
2024-11-09 00:09:46 +08:00
import 'package:go_router/go_router.dart';
2024-12-08 14:44:55 +08:00
import 'package:surface/screens/abuse_report.dart';
2024-11-09 00:09:46 +08:00
import 'package:surface/screens/account.dart';
import 'package:surface/screens/account/account_settings.dart';
2025-01-28 00:52:44 +08:00
import 'package:surface/screens/account/factor_settings.dart';
2025-01-15 15:52:52 +08:00
import 'package:surface/screens/account/profile_page.dart';
2024-11-10 01:04:39 +08:00
import 'package:surface/screens/account/profile_edit.dart';
import 'package:surface/screens/account/publishers/publisher_edit.dart';
import 'package:surface/screens/account/publishers/publisher_new.dart';
import 'package:surface/screens/account/publishers/publishers.dart';
2024-11-14 00:08:09 +08:00
import 'package:surface/screens/album.dart';
2024-11-09 18:28:45 +08:00
import 'package:surface/screens/auth/login.dart';
import 'package:surface/screens/auth/register.dart';
2024-11-14 00:08:09 +08:00
import 'package:surface/screens/chat.dart';
2024-11-24 00:22:08 +08:00
import 'package:surface/screens/chat/call_room.dart';
2024-11-28 23:35:25 +08:00
import 'package:surface/screens/chat/channel_detail.dart';
2024-11-16 13:54:36 +08:00
import 'package:surface/screens/chat/manage.dart';
import 'package:surface/screens/chat/room.dart';
2024-11-09 00:09:46 +08:00
import 'package:surface/screens/explore.dart';
2024-11-30 22:39:49 +08:00
import 'package:surface/screens/friend.dart';
2024-11-09 00:09:46 +08:00
import 'package:surface/screens/home.dart';
2025-01-26 02:12:03 +08:00
import 'package:surface/screens/news/news_detail.dart';
import 'package:surface/screens/news/news_list.dart';
2024-11-23 16:55:23 +08:00
import 'package:surface/screens/notification.dart';
2024-11-10 22:56:09 +08:00
import 'package:surface/screens/post/post_detail.dart';
2024-11-10 01:34:58 +08:00
import 'package:surface/screens/post/post_editor.dart';
2024-12-03 23:38:43 +08:00
import 'package:surface/screens/post/publisher_page.dart';
2024-11-23 19:06:09 +08:00
import 'package:surface/screens/post/post_search.dart';
2024-11-16 13:54:36 +08:00
import 'package:surface/screens/realm.dart';
import 'package:surface/screens/realm/manage.dart';
import 'package:surface/screens/realm/realm_detail.dart';
2025-02-11 21:31:53 +08:00
import 'package:surface/screens/realm/realm_discovery.dart';
import 'package:surface/screens/settings.dart';
2024-12-15 12:59:18 +08:00
import 'package:surface/screens/sharing.dart';
2025-01-29 15:18:35 +08:00
import 'package:surface/screens/wallet.dart';
2024-11-10 22:56:09 +08:00
import 'package:surface/types/post.dart';
2024-12-08 17:14:31 +08:00
import 'package:surface/widgets/about.dart';
2024-11-09 00:09:46 +08:00
import 'package:surface/widgets/navigation/app_scaffold.dart';
2025-01-25 14:35:04 +08:00
Widget _fadeThroughTransition(
BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation, Widget child) {
return FadeThroughTransition(
animation: animation,
secondaryAnimation: secondaryAnimation,
fillColor: Colors.transparent,
child: child,
);
}
final _appRoutes = [
2025-01-25 14:35:04 +08:00
GoRoute(
path: '/',
name: 'home',
2025-01-26 02:12:03 +08:00
builder: (context, state) => const HomeScreen(),
2025-01-25 14:35:04 +08:00
),
GoRoute(
path: '/posts',
name: 'explore',
2025-01-26 02:12:03 +08:00
builder: (context, state) => const ExploreScreen(),
routes: [
GoRoute(
2025-01-25 14:35:04 +08:00
path: '/write/:mode',
name: 'postEditor',
builder: (context, state) => PostEditorScreen(
mode: state.pathParameters['mode']!,
postEditId: int.tryParse(
state.uri.queryParameters['editing'] ?? '',
2024-11-23 19:06:09 +08:00
),
2025-01-25 14:35:04 +08:00
postReplyId: int.tryParse(
state.uri.queryParameters['replying'] ?? '',
2024-12-01 22:30:32 +08:00
),
2025-01-25 14:35:04 +08:00
postRepostId: int.tryParse(
state.uri.queryParameters['reposting'] ?? '',
2024-11-15 23:08:29 +08:00
),
2025-01-31 22:52:21 +08:00
extraProps: state.extra as PostEditorExtra?,
2025-01-25 14:35:04 +08:00
),
),
GoRoute(
2025-01-25 14:35:04 +08:00
path: '/search',
name: 'postSearch',
builder: (context, state) => PostSearchScreen(
initialTags: state.uri.queryParameters['tags']?.split(','),
initialCategories: state.uri.queryParameters['categories']?.split(','),
),
),
GoRoute(
2025-01-25 14:35:04 +08:00
path: '/publishers/:name',
name: 'postPublisher',
builder: (context, state) => PostPublisherScreen(name: state.pathParameters['name']!),
2024-11-16 13:54:36 +08:00
),
GoRoute(
2025-01-25 14:35:04 +08:00
path: '/:slug',
name: 'postDetail',
builder: (context, state) => PostDetailScreen(
slug: state.pathParameters['slug']!,
preload: state.extra as SnPost?,
2024-11-16 13:54:36 +08:00
),
2025-01-25 14:35:04 +08:00
),
],
),
2025-01-28 00:52:44 +08:00
GoRoute(path: '/account', name: 'account', builder: (context, state) => const AccountScreen(), routes: [
2025-01-29 15:18:35 +08:00
GoRoute(
path: '/wallet',
name: 'accountWallet',
builder: (context, state) => const WalletScreen(),
),
2025-01-28 00:52:44 +08:00
GoRoute(
path: '/settings',
name: 'accountSettings',
builder: (context, state) => AccountSettingsScreen(),
),
GoRoute(
path: '/settings/factors',
name: 'factorSettings',
builder: (context, state) => FactorSettingsScreen(),
),
GoRoute(
path: '/profile/edit',
name: 'accountProfileEdit',
builder: (context, state) => ProfileEditScreen(),
),
GoRoute(
path: '/publishers',
name: 'accountPublishers',
builder: (context, state) => PublisherScreen(),
),
GoRoute(
path: '/publishers/new',
name: 'accountPublisherNew',
builder: (context, state) => AccountPublisherNewScreen(),
),
GoRoute(
path: '/publishers/edit/:name',
name: 'accountPublisherEdit',
builder: (context, state) => AccountPublisherEditScreen(
name: state.pathParameters['name']!,
),
2025-01-28 00:52:44 +08:00
),
GoRoute(
path: '/:name',
name: 'accountProfilePage',
pageBuilder: (context, state) => NoTransitionPage(
child: UserScreen(name: state.pathParameters['name']!),
),
2025-01-28 00:52:44 +08:00
),
]),
2025-01-25 14:35:04 +08:00
GoRoute(
path: '/chat',
name: 'chat',
2025-01-26 02:12:03 +08:00
builder: (context, state) => const ChatScreen(),
2025-01-25 14:35:04 +08:00
routes: [
GoRoute(
path: '/:scope/:alias',
name: 'chatRoom',
2025-01-26 02:12:03 +08:00
builder: (context, state) => ChatRoomScreen(
scope: state.pathParameters['scope']!,
alias: state.pathParameters['alias']!,
2025-01-31 22:52:21 +08:00
extra: state.extra as ChatRoomScreenExtra?,
2025-01-25 14:35:04 +08:00
),
),
GoRoute(
2025-01-25 14:35:04 +08:00
path: '/:scope/:alias/call',
name: 'chatCallRoom',
2025-01-26 02:12:03 +08:00
builder: (context, state) => CallRoomScreen(
scope: state.pathParameters['scope']!,
alias: state.pathParameters['alias']!,
),
),
2024-11-30 22:39:49 +08:00
GoRoute(
2025-01-25 14:35:04 +08:00
path: '/:scope/:alias/detail',
name: 'channelDetail',
2025-01-26 02:12:03 +08:00
builder: (context, state) => ChannelDetailScreen(
scope: state.pathParameters['scope']!,
alias: state.pathParameters['alias']!,
2024-11-30 22:39:49 +08:00
),
),
2024-11-23 16:55:23 +08:00
GoRoute(
2025-01-25 14:35:04 +08:00
path: '/manage',
name: 'chatManage',
2025-01-26 02:12:03 +08:00
builder: (context, state) => ChatManageScreen(
editingChannelAlias: state.uri.queryParameters['editing'],
2024-11-23 16:55:23 +08:00
),
),
],
),
2025-01-25 14:35:04 +08:00
GoRoute(
path: '/realm',
name: 'realm',
pageBuilder: (context, state) => CustomTransitionPage(
transitionsBuilder: _fadeThroughTransition,
child: const RealmScreen(),
),
routes: [
GoRoute(
2025-01-25 14:35:04 +08:00
path: '/manage',
name: 'realmManage',
2025-01-26 02:12:03 +08:00
builder: (context, state) => RealmManageScreen(
editingRealmAlias: state.uri.queryParameters['editing'],
),
),
2025-02-11 21:31:53 +08:00
GoRoute(
path: '/discovery',
name: 'realmDiscovery',
builder: (context, state) => const RealmDiscoveryScreen(),
),
2025-02-10 17:54:31 +08:00
GoRoute(
path: '/:alias',
name: 'realmDetail',
builder: (context, state) => RealmDetailScreen(alias: state.pathParameters['alias']!),
),
],
),
2025-01-28 00:52:44 +08:00
GoRoute(path: '/news', name: 'news', builder: (context, state) => const NewsScreen(), routes: [
GoRoute(
path: '/:hash',
name: 'newsDetail',
builder: (context, state) => NewsDetailScreen(
hash: state.pathParameters['hash']!,
2025-01-26 02:12:03 +08:00
),
2025-01-28 00:52:44 +08:00
),
]),
2025-01-25 14:35:04 +08:00
GoRoute(
path: '/album',
name: 'album',
2025-01-26 02:12:03 +08:00
builder: (context, state) => const AlbumScreen(),
2025-01-25 14:35:04 +08:00
),
GoRoute(
path: '/friend',
name: 'friend',
2025-01-26 02:12:03 +08:00
builder: (context, state) => const FriendScreen(),
2025-01-25 14:35:04 +08:00
),
GoRoute(
path: '/notification',
name: 'notification',
2025-01-26 02:12:03 +08:00
builder: (context, state) => const NotificationScreen(),
2025-01-25 14:35:04 +08:00
),
GoRoute(
path: '/auth/login',
name: 'authLogin',
builder: (context, state) => LoginScreen(),
),
GoRoute(
path: '/auth/register',
name: 'authRegister',
builder: (context, state) => RegisterScreen(),
),
GoRoute(
path: '/reports',
name: 'abuseReport',
builder: (context, state) => AbuseReportScreen(),
),
GoRoute(
path: '/settings',
name: 'settings',
builder: (context, state) => SettingsScreen(),
),
2025-01-25 14:35:04 +08:00
GoRoute(
path: '/about',
name: 'about',
builder: (context, state) => AboutScreen(),
2024-12-08 17:14:31 +08:00
),
];
final appRouter = GoRouter(
2024-11-15 23:08:29 +08:00
routes: [
ShellRoute(
routes: _appRoutes,
2024-12-15 12:59:18 +08:00
builder: (context, state, child) => AppRootScaffold(
body: AppSharingListener(child: child),
),
2024-11-15 23:08:29 +08:00
),
],
2024-11-09 00:09:46 +08:00
);