Solian/lib/router.dart

173 lines
6.0 KiB
Dart
Raw Normal View History

import 'package:flutter/material.dart';
2024-04-12 16:38:20 +00:00
import 'package:go_router/go_router.dart';
2024-04-26 17:36:54 +00:00
import 'package:solian/models/call.dart';
import 'package:solian/models/channel.dart';
2024-04-14 10:38:44 +00:00
import 'package:solian/models/post.dart';
import 'package:solian/screens/account.dart';
2024-04-25 15:03:16 +00:00
import 'package:solian/screens/account/friend.dart';
2024-05-02 10:56:40 +00:00
import 'package:solian/screens/account/personalize.dart';
2024-05-01 09:37:34 +00:00
import 'package:solian/screens/auth/signup.dart';
2024-04-26 17:36:54 +00:00
import 'package:solian/screens/chat/call.dart';
2024-04-17 15:00:53 +00:00
import 'package:solian/screens/chat/chat.dart';
import 'package:solian/screens/chat/chat_list.dart';
import 'package:solian/screens/chat/chat_detail.dart';
import 'package:solian/screens/chat/channel/channel_editor.dart';
import 'package:solian/screens/chat/channel/channel_member.dart';
2024-04-12 16:38:20 +00:00
import 'package:solian/screens/explore.dart';
2024-04-24 15:19:26 +00:00
import 'package:solian/screens/notification.dart';
import 'package:solian/screens/posts/comment_editor.dart';
2024-04-14 10:38:44 +00:00
import 'package:solian/screens/posts/moment_editor.dart';
2024-04-13 17:07:57 +00:00
import 'package:solian/screens/posts/screen.dart';
2024-05-01 09:37:34 +00:00
import 'package:solian/screens/auth/signin.dart';
import 'package:solian/utils/theme.dart';
import 'package:solian/widgets/empty.dart';
import 'package:solian/widgets/layouts/two_column.dart';
2024-04-12 16:38:20 +00:00
abstract class SolianRouter {
static final router = GoRouter(
routes: [
GoRoute(
path: '/notification',
name: 'notification',
builder: (context, state) => const NotificationScreen(),
),
ShellRoute(
pageBuilder: (context, state, child) => defaultPageBuilder(
context,
state,
SolianTheme.isLargeScreen(context)
? TwoColumnLayout(
sideChild: const ExplorePostScreen(),
mainChild: child,
)
: child,
),
routes: [
GoRoute(
path: '/',
name: 'explore',
builder: (context, state) =>
!SolianTheme.isLargeScreen(context) ? const ExplorePostScreen() : const PageEmptyWidget(),
),
GoRoute(
path: '/posts/publish/moments',
name: 'posts.moments.editor',
builder: (context, state) => MomentEditorScreen(editing: state.extra as Post?),
),
GoRoute(
path: '/posts/publish/comments',
name: 'posts.comments.editor',
builder: (context, state) {
final args = state.extra as CommentPostArguments;
return CommentEditorScreen(editing: args.editing, related: args.related);
},
),
GoRoute(
path: '/posts/:dataset/:alias',
name: 'posts.screen',
builder: (context, state) => PostScreen(
alias: state.pathParameters['alias'] as String,
dataset: state.pathParameters['dataset'] as String,
),
),
],
),
ShellRoute(
pageBuilder: (context, state, child) => defaultPageBuilder(
context,
state,
SolianTheme.isLargeScreen(context)
? TwoColumnLayout(
sideChild: const ChatListScreen(),
mainChild: child,
)
: child,
),
routes: [
GoRoute(
path: '/chat',
name: 'chat',
builder: (context, state) =>
!SolianTheme.isLargeScreen(context) ? const ChatListScreen() : const PageEmptyWidget(),
),
GoRoute(
path: '/chat/create',
name: 'chat.channel.editor',
builder: (context, state) => ChannelEditorScreen(editing: state.extra as Channel?),
),
GoRoute(
path: '/chat/c/:channel',
name: 'chat.channel',
builder: (context, state) => ChatScreen(alias: state.pathParameters['channel'] as String),
),
GoRoute(
path: '/chat/c/:channel/call',
name: 'chat.channel.call',
builder: (context, state) => ChatCall(call: state.extra as Call),
),
GoRoute(
path: '/chat/c/:channel/manage',
name: 'chat.channel.manage',
builder: (context, state) => ChatDetailScreen(channel: state.extra as Channel),
),
GoRoute(
path: '/chat/c/:channel/member',
name: 'chat.channel.member',
builder: (context, state) => ChatMemberScreen(channel: state.extra as Channel),
),
],
),
ShellRoute(
pageBuilder: (context, state, child) => defaultPageBuilder(
context,
state,
SolianTheme.isLargeScreen(context)
? TwoColumnLayout(
sideChild: const AccountScreen(),
mainChild: child,
)
: child,
),
routes: [
GoRoute(
path: '/account',
name: 'account',
builder: (context, state) =>
!SolianTheme.isLargeScreen(context) ? const AccountScreen() : const PageEmptyWidget(),
),
GoRoute(
path: '/auth/sign-in',
name: 'auth.sign-in',
builder: (context, state) => SignInScreen(),
),
GoRoute(
path: '/auth/sign-up',
name: 'auth.sign-up',
builder: (context, state) => SignUpScreen(),
),
GoRoute(
path: '/account/friend',
name: 'account.friend',
builder: (context, state) => const FriendScreen(),
),
GoRoute(
path: '/account/personalize',
name: 'account.personalize',
builder: (context, state) => const PersonalizeScreen(),
),
]),
],
);
static Page defaultPageBuilder(
BuildContext context,
GoRouterState state,
Widget child,
) =>
MaterialPage(
key: state.pageKey,
restorationId: state.pageKey.value,
child: child,
);
}