Solian/lib/router.dart

247 lines
7.3 KiB
Dart
Raw Normal View History

import 'package:animations/animations.dart';
import 'package:flutter/material.dart';
2024-05-18 18:17:16 +08:00
import 'package:go_router/go_router.dart';
2024-05-29 22:42:11 +08:00
import 'package:solian/models/realm.dart';
2024-06-08 13:28:49 +08:00
import 'package:solian/screens/about.dart';
2024-05-18 18:17:16 +08:00
import 'package:solian/screens/account.dart';
2024-05-23 21:12:47 +08:00
import 'package:solian/screens/account/friend.dart';
2024-05-22 23:18:01 +08:00
import 'package:solian/screens/account/personalize.dart';
2024-07-26 16:53:05 +08:00
import 'package:solian/screens/account/profile_page.dart';
2024-05-26 01:21:08 +08:00
import 'package:solian/screens/channel/channel_chat.dart';
2024-05-26 23:13:43 +08:00
import 'package:solian/screens/channel/channel_detail.dart';
2024-05-26 00:11:00 +08:00
import 'package:solian/screens/channel/channel_organize.dart';
import 'package:solian/screens/chat.dart';
2024-07-09 21:23:38 +08:00
import 'package:solian/screens/feed/search.dart';
2024-05-25 13:19:16 +08:00
import 'package:solian/screens/posts/post_detail.dart';
2024-07-09 21:23:38 +08:00
import 'package:solian/screens/feed/draft_box.dart';
2024-05-28 22:13:23 +08:00
import 'package:solian/screens/realms.dart';
2024-05-29 22:42:11 +08:00
import 'package:solian/screens/realms/realm_detail.dart';
2024-05-28 22:13:23 +08:00
import 'package:solian/screens/realms/realm_organize.dart';
2024-05-29 22:42:11 +08:00
import 'package:solian/screens/realms/realm_view.dart';
2024-07-12 16:19:54 +08:00
import 'package:solian/screens/home.dart';
2024-07-10 10:50:10 +08:00
import 'package:solian/screens/posts/post_editor.dart';
2024-07-31 02:44:49 +08:00
import 'package:solian/screens/settings.dart';
2024-07-12 13:15:46 +08:00
import 'package:solian/shells/root_shell.dart';
2024-06-27 14:31:15 +08:00
import 'package:solian/shells/title_shell.dart';
2024-05-18 18:17:16 +08:00
2024-05-19 00:56:32 +08:00
abstract class AppRouter {
2024-05-18 18:17:16 +08:00
static GoRouter instance = GoRouter(
routes: [
2024-07-12 13:15:46 +08:00
ShellRoute(
builder: (context, state, child) => RootShell(
state: state,
child: child,
),
routes: [
_feedRoute,
_chatRoute,
_realmRoute,
_accountRoute,
2024-07-31 02:44:49 +08: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 13:15:46 +08:00
],
),
2024-07-06 20:55:53 +08:00
],
);
static final ShellRoute _feedRoute = ShellRoute(
2024-07-06 21:14:19 +08:00
builder: (context, state, child) => child,
2024-07-06 20:55:53 +08:00
routes: [
GoRoute(
path: '/',
2024-07-12 16:19:54 +08:00
name: 'home',
builder: (context, state) => const HomeScreen(),
2024-07-06 20:55:53 +08:00
),
2024-07-07 14:22:53 +08:00
GoRoute(
path: '/feed/search',
name: 'feedSearch',
builder: (context, state) => TitleShell(
state: state,
child: FeedSearchScreen(
tag: state.uri.queryParameters['tag'],
category: state.uri.queryParameters['category'],
),
),
),
2024-07-09 21:23:38 +08:00
GoRoute(
path: '/drafts',
name: 'draftBox',
builder: (context, state) => const DraftBoxScreen(),
),
2024-07-06 20:55:53 +08:00
GoRoute(
path: '/posts/view/:id',
2024-07-06 20:55:53 +08:00
name: 'postDetail',
builder: (context, state) => TitleShell(
state: state,
child: PostDetailScreen(
id: state.pathParameters['id']!,
2024-07-10 10:50:10 +08:00
),
),
),
GoRoute(
path: '/posts/editor',
name: 'postEditor',
pageBuilder: (context, state) {
2024-07-09 21:23:38 +08:00
final arguments = state.extra as PostPublishArguments?;
return CustomTransitionPage(
child: PostPublishScreen(
edit: arguments?.edit,
reply: arguments?.reply,
repost: arguments?.repost,
realm: arguments?.realm,
postListController: arguments?.postListController,
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 20:55:53 +08:00
);
},
),
],
);
static final ShellRoute _chatRoute = ShellRoute(
2024-07-12 21:59:16 +08:00
builder: (context, state, child) => child,
2024-07-06 20:55:53 +08:00
routes: [
GoRoute(
path: '/chat',
name: 'chat',
2024-07-12 21:59:16 +08:00
builder: (context, state) => const ChatScreen(),
2024-07-06 20:55:53 +08: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(
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,
child: ChannelDetailScreen(
channel: arguments.channel,
profile: arguments.profile,
realm: state.uri.queryParameters['realm'] ?? 'global',
2024-05-29 22:42:11 +08:00
),
2024-07-06 20:55:53 +08:00
);
},
),
],
);
static final ShellRoute _realmRoute = ShellRoute(
2024-07-12 21:59:16 +08:00
builder: (context, state, child) => child,
2024-07-06 20:55:53 +08:00
routes: [
GoRoute(
path: '/realms',
name: 'realms',
2024-07-12 21:59:16 +08:00
builder: (context, state) => const RealmListScreen(),
2024-07-06 20:55:53 +08: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 22:42:11 +08:00
),
2024-07-06 20:55:53 +08: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 20:55:53 +08:00
routes: [
GoRoute(
path: '/account',
name: 'account',
builder: (context, state) => TitleShell(
state: state,
isCenteredTitle: true,
child: const AccountScreen(),
),
2024-07-06 20:55:53 +08:00
),
GoRoute(
path: '/account/friend',
name: 'accountFriend',
2024-07-24 01:17:41 +08:00
builder: (context, state) => const FriendScreen(),
2024-07-06 20:55:53 +08:00
),
GoRoute(
path: '/account/personalize',
name: 'accountPersonalize',
builder: (context, state) => TitleShell(
state: state,
child: const PersonalizeScreen(),
),
),
2024-07-26 16:53:05 +08:00
GoRoute(
path: '/account/view/:name',
name: 'accountProfilePage',
builder: (context, state) => AccountProfilePage(
name: state.pathParameters['name']!,
),
),
2024-05-18 18:17:16 +08:00
],
);
}