♻️ Refactored router
This commit is contained in:
parent
950612dc07
commit
cb4a2598c8
428
lib/router.dart
428
lib/router.dart
@ -34,246 +34,222 @@ import 'package:surface/widgets/about.dart';
|
|||||||
import 'package:surface/widgets/navigation/app_background.dart';
|
import 'package:surface/widgets/navigation/app_background.dart';
|
||||||
import 'package:surface/widgets/navigation/app_scaffold.dart';
|
import 'package:surface/widgets/navigation/app_scaffold.dart';
|
||||||
|
|
||||||
|
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 = [
|
final _appRoutes = [
|
||||||
ShellRoute(
|
GoRoute(
|
||||||
builder: (context, state, child) => child,
|
path: '/',
|
||||||
|
name: 'home',
|
||||||
|
pageBuilder: (context, state) => CustomTransitionPage(
|
||||||
|
transitionsBuilder: _fadeThroughTransition,
|
||||||
|
child: const HomeScreen(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
GoRoute(
|
||||||
|
path: '/posts',
|
||||||
|
name: 'explore',
|
||||||
|
pageBuilder: (context, state) => CustomTransitionPage(
|
||||||
|
transitionsBuilder: _fadeThroughTransition,
|
||||||
|
child: const ExploreScreen(),
|
||||||
|
),
|
||||||
routes: [
|
routes: [
|
||||||
GoRoute(
|
GoRoute(
|
||||||
path: '/',
|
path: '/write/:mode',
|
||||||
name: 'home',
|
name: 'postEditor',
|
||||||
pageBuilder: (context, state) => NoTransitionPage(
|
builder: (context, state) => PostEditorScreen(
|
||||||
child: const HomeScreen(),
|
mode: state.pathParameters['mode']!,
|
||||||
|
postEditId: int.tryParse(
|
||||||
|
state.uri.queryParameters['editing'] ?? '',
|
||||||
|
),
|
||||||
|
postReplyId: int.tryParse(
|
||||||
|
state.uri.queryParameters['replying'] ?? '',
|
||||||
|
),
|
||||||
|
postRepostId: int.tryParse(
|
||||||
|
state.uri.queryParameters['reposting'] ?? '',
|
||||||
|
),
|
||||||
|
extraProps: state.extra as PostEditorExtraProps?,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
GoRoute(
|
GoRoute(
|
||||||
path: '/posts',
|
path: '/search',
|
||||||
name: 'explore',
|
name: 'postSearch',
|
||||||
pageBuilder: (context, state) => NoTransitionPage(
|
builder: (context, state) => PostSearchScreen(
|
||||||
child: const ExploreScreen(),
|
initialTags: state.uri.queryParameters['tags']?.split(','),
|
||||||
),
|
initialCategories: state.uri.queryParameters['categories']?.split(','),
|
||||||
routes: [
|
|
||||||
GoRoute(
|
|
||||||
path: '/write/:mode',
|
|
||||||
name: 'postEditor',
|
|
||||||
builder: (context, state) => PostEditorScreen(
|
|
||||||
mode: state.pathParameters['mode']!,
|
|
||||||
postEditId: int.tryParse(
|
|
||||||
state.uri.queryParameters['editing'] ?? '',
|
|
||||||
),
|
|
||||||
postReplyId: int.tryParse(
|
|
||||||
state.uri.queryParameters['replying'] ?? '',
|
|
||||||
),
|
|
||||||
postRepostId: int.tryParse(
|
|
||||||
state.uri.queryParameters['reposting'] ?? '',
|
|
||||||
),
|
|
||||||
extraProps: state.extra as PostEditorExtraProps?,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
GoRoute(
|
|
||||||
path: '/search',
|
|
||||||
name: 'postSearch',
|
|
||||||
builder: (context, state) => PostSearchScreen(
|
|
||||||
initialTags: state.uri.queryParameters['tags']?.split(','),
|
|
||||||
initialCategories: state.uri.queryParameters['categories']?.split(','),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
GoRoute(
|
|
||||||
path: '/publishers/:name',
|
|
||||||
name: 'postPublisher',
|
|
||||||
builder: (context, state) => PostPublisherScreen(name: state.pathParameters['name']!),
|
|
||||||
),
|
|
||||||
GoRoute(
|
|
||||||
path: '/:slug',
|
|
||||||
name: 'postDetail',
|
|
||||||
builder: (context, state) => PostDetailScreen(
|
|
||||||
slug: state.pathParameters['slug']!,
|
|
||||||
preload: state.extra as SnPost?,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
GoRoute(
|
|
||||||
path: '/account',
|
|
||||||
name: 'account',
|
|
||||||
pageBuilder: (context, state) => CustomTransitionPage(
|
|
||||||
transitionsBuilder: (context, animation, secondaryAnimation, child) {
|
|
||||||
return FadeThroughTransition(
|
|
||||||
animation: animation,
|
|
||||||
secondaryAnimation: secondaryAnimation,
|
|
||||||
fillColor: Colors.transparent,
|
|
||||||
child: child,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
child: const AccountScreen(),
|
|
||||||
),
|
|
||||||
routes: [],
|
|
||||||
),
|
|
||||||
GoRoute(
|
|
||||||
path: '/chat',
|
|
||||||
name: 'chat',
|
|
||||||
pageBuilder: (context, state) => CustomTransitionPage(
|
|
||||||
transitionsBuilder: (context, animation, secondaryAnimation, child) {
|
|
||||||
return FadeThroughTransition(
|
|
||||||
animation: animation,
|
|
||||||
secondaryAnimation: secondaryAnimation,
|
|
||||||
fillColor: Colors.transparent,
|
|
||||||
child: child,
|
|
||||||
);
|
|
||||||
},
|
|
||||||
child: const ChatScreen(),
|
|
||||||
),
|
|
||||||
routes: [
|
|
||||||
GoRoute(
|
|
||||||
path: '/:scope/:alias',
|
|
||||||
name: 'chatRoom',
|
|
||||||
builder: (context, state) => AppBackground(
|
|
||||||
child: ChatRoomScreen(
|
|
||||||
scope: state.pathParameters['scope']!,
|
|
||||||
alias: state.pathParameters['alias']!,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
GoRoute(
|
|
||||||
path: '/:scope/:alias/call',
|
|
||||||
name: 'chatCallRoom',
|
|
||||||
builder: (context, state) => AppBackground(
|
|
||||||
child: CallRoomScreen(
|
|
||||||
scope: state.pathParameters['scope']!,
|
|
||||||
alias: state.pathParameters['alias']!,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
GoRoute(
|
|
||||||
path: '/:scope/:alias/detail',
|
|
||||||
name: 'channelDetail',
|
|
||||||
builder: (context, state) => AppBackground(
|
|
||||||
child: ChannelDetailScreen(
|
|
||||||
scope: state.pathParameters['scope']!,
|
|
||||||
alias: state.pathParameters['alias']!,
|
|
||||||
),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
GoRoute(
|
|
||||||
path: '/manage',
|
|
||||||
name: 'chatManage',
|
|
||||||
pageBuilder: (context, state) => CustomTransitionPage(
|
|
||||||
child: ChatManageScreen(
|
|
||||||
editingChannelAlias: state.uri.queryParameters['editing'],
|
|
||||||
),
|
|
||||||
transitionsBuilder: (context, animation, secondaryAnimation, child) {
|
|
||||||
return FadeThroughTransition(
|
|
||||||
animation: animation,
|
|
||||||
secondaryAnimation: secondaryAnimation,
|
|
||||||
fillColor: Colors.transparent,
|
|
||||||
child: AppBackground(
|
|
||||||
child: child,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
GoRoute(
|
|
||||||
path: '/:alias',
|
|
||||||
name: 'realmDetail',
|
|
||||||
builder: (context, state) => AppBackground(
|
|
||||||
child: RealmDetailScreen(alias: state.pathParameters['alias']!),
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
GoRoute(
|
|
||||||
path: '/realm',
|
|
||||||
name: 'realm',
|
|
||||||
pageBuilder: (context, state) => NoTransitionPage(
|
|
||||||
child: const RealmScreen(),
|
|
||||||
),
|
|
||||||
routes: [
|
|
||||||
GoRoute(
|
|
||||||
path: '/manage',
|
|
||||||
name: 'realmManage',
|
|
||||||
pageBuilder: (context, state) => CustomTransitionPage(
|
|
||||||
child: RealmManageScreen(
|
|
||||||
editingRealmAlias: state.uri.queryParameters['editing'],
|
|
||||||
),
|
|
||||||
transitionsBuilder: (context, animation, secondaryAnimation, child) {
|
|
||||||
return FadeThroughTransition(
|
|
||||||
animation: animation,
|
|
||||||
secondaryAnimation: secondaryAnimation,
|
|
||||||
fillColor: Colors.transparent,
|
|
||||||
child: AppBackground(
|
|
||||||
child: child,
|
|
||||||
),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
|
||||||
GoRoute(
|
|
||||||
path: '/album',
|
|
||||||
name: 'album',
|
|
||||||
pageBuilder: (context, state) => NoTransitionPage(
|
|
||||||
child: const AlbumScreen(),
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
GoRoute(
|
GoRoute(
|
||||||
path: '/friend',
|
path: '/publishers/:name',
|
||||||
name: 'friend',
|
name: 'postPublisher',
|
||||||
pageBuilder: (context, state) => NoTransitionPage(
|
builder: (context, state) => PostPublisherScreen(name: state.pathParameters['name']!),
|
||||||
child: const FriendScreen(),
|
|
||||||
),
|
|
||||||
),
|
),
|
||||||
GoRoute(
|
GoRoute(
|
||||||
path: '/notification',
|
path: '/:slug',
|
||||||
name: 'notification',
|
name: 'postDetail',
|
||||||
pageBuilder: (context, state) => NoTransitionPage(
|
builder: (context, state) => PostDetailScreen(
|
||||||
child: const NotificationScreen(),
|
slug: state.pathParameters['slug']!,
|
||||||
|
preload: state.extra as SnPost?,
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
ShellRoute(
|
GoRoute(
|
||||||
builder: (context, state, child) => child,
|
path: '/account',
|
||||||
|
name: 'account',
|
||||||
|
pageBuilder: (context, state) => CustomTransitionPage(
|
||||||
|
transitionsBuilder: _fadeThroughTransition,
|
||||||
|
child: const AccountScreen(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
GoRoute(
|
||||||
|
path: '/chat',
|
||||||
|
name: 'chat',
|
||||||
|
pageBuilder: (context, state) => CustomTransitionPage(
|
||||||
|
transitionsBuilder: _fadeThroughTransition,
|
||||||
|
child: const ChatScreen(),
|
||||||
|
),
|
||||||
routes: [
|
routes: [
|
||||||
GoRoute(
|
GoRoute(
|
||||||
path: '/auth/login',
|
path: '/:scope/:alias',
|
||||||
name: 'authLogin',
|
name: 'chatRoom',
|
||||||
builder: (context, state) => LoginScreen(),
|
builder: (context, state) => AppBackground(
|
||||||
|
child: ChatRoomScreen(
|
||||||
|
scope: state.pathParameters['scope']!,
|
||||||
|
alias: state.pathParameters['alias']!,
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
GoRoute(
|
GoRoute(
|
||||||
path: '/auth/register',
|
path: '/:scope/:alias/call',
|
||||||
name: 'authRegister',
|
name: 'chatCallRoom',
|
||||||
builder: (context, state) => RegisterScreen(),
|
builder: (context, state) => AppBackground(
|
||||||
|
child: CallRoomScreen(
|
||||||
|
scope: state.pathParameters['scope']!,
|
||||||
|
alias: state.pathParameters['alias']!,
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
GoRoute(
|
GoRoute(
|
||||||
path: '/reports',
|
path: '/:scope/:alias/detail',
|
||||||
name: 'abuseReport',
|
name: 'channelDetail',
|
||||||
builder: (context, state) => AbuseReportScreen(),
|
builder: (context, state) => AppBackground(
|
||||||
|
child: ChannelDetailScreen(
|
||||||
|
scope: state.pathParameters['scope']!,
|
||||||
|
alias: state.pathParameters['alias']!,
|
||||||
|
),
|
||||||
|
),
|
||||||
),
|
),
|
||||||
GoRoute(
|
GoRoute(
|
||||||
path: '/account/profile/edit',
|
path: '/manage',
|
||||||
name: 'accountProfileEdit',
|
name: 'chatManage',
|
||||||
builder: (context, state) => ProfileEditScreen(),
|
pageBuilder: (context, state) => CustomTransitionPage(
|
||||||
),
|
child: ChatManageScreen(
|
||||||
GoRoute(
|
editingChannelAlias: state.uri.queryParameters['editing'],
|
||||||
path: '/account/publishers',
|
),
|
||||||
name: 'accountPublishers',
|
transitionsBuilder: (context, animation, secondaryAnimation, child) {
|
||||||
builder: (context, state) => PublisherScreen(),
|
return FadeThroughTransition(
|
||||||
),
|
animation: animation,
|
||||||
GoRoute(
|
secondaryAnimation: secondaryAnimation,
|
||||||
path: '/account/publishers/new',
|
fillColor: Colors.transparent,
|
||||||
name: 'accountPublisherNew',
|
child: child,
|
||||||
builder: (context, state) => AccountPublisherNewScreen(),
|
);
|
||||||
),
|
},
|
||||||
GoRoute(
|
|
||||||
path: '/account/publishers/edit/:name',
|
|
||||||
name: 'accountPublisherEdit',
|
|
||||||
builder: (context, state) => AccountPublisherEditScreen(
|
|
||||||
name: state.pathParameters['name']!,
|
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
|
GoRoute(
|
||||||
|
path: '/realm',
|
||||||
|
name: 'realm',
|
||||||
|
pageBuilder: (context, state) => CustomTransitionPage(
|
||||||
|
transitionsBuilder: _fadeThroughTransition,
|
||||||
|
child: const RealmScreen(),
|
||||||
|
),
|
||||||
|
routes: [
|
||||||
|
GoRoute(
|
||||||
|
path: '/:alias',
|
||||||
|
name: 'realmDetail',
|
||||||
|
builder: (context, state) => RealmDetailScreen(alias: state.pathParameters['alias']!),
|
||||||
|
),
|
||||||
|
GoRoute(
|
||||||
|
path: '/manage',
|
||||||
|
name: 'realmManage',
|
||||||
|
pageBuilder: (context, state) => CustomTransitionPage(
|
||||||
|
transitionsBuilder: _fadeThroughTransition,
|
||||||
|
child: RealmManageScreen(
|
||||||
|
editingRealmAlias: state.uri.queryParameters['editing'],
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
GoRoute(
|
||||||
|
path: '/album',
|
||||||
|
name: 'album',
|
||||||
|
pageBuilder: (context, state) => CustomTransitionPage(
|
||||||
|
transitionsBuilder: _fadeThroughTransition,
|
||||||
|
child: const AlbumScreen(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
GoRoute(
|
||||||
|
path: '/friend',
|
||||||
|
name: 'friend',
|
||||||
|
pageBuilder: (context, state) => NoTransitionPage(
|
||||||
|
child: const FriendScreen(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
GoRoute(
|
||||||
|
path: '/notification',
|
||||||
|
name: 'notification',
|
||||||
|
pageBuilder: (context, state) => NoTransitionPage(
|
||||||
|
child: const NotificationScreen(),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
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: '/account/profile/edit',
|
||||||
|
name: 'accountProfileEdit',
|
||||||
|
builder: (context, state) => ProfileEditScreen(),
|
||||||
|
),
|
||||||
|
GoRoute(
|
||||||
|
path: '/account/publishers',
|
||||||
|
name: 'accountPublishers',
|
||||||
|
builder: (context, state) => PublisherScreen(),
|
||||||
|
),
|
||||||
|
GoRoute(
|
||||||
|
path: '/account/publishers/new',
|
||||||
|
name: 'accountPublisherNew',
|
||||||
|
builder: (context, state) => AccountPublisherNewScreen(),
|
||||||
|
),
|
||||||
|
GoRoute(
|
||||||
|
path: '/account/publishers/edit/:name',
|
||||||
|
name: 'accountPublisherEdit',
|
||||||
|
builder: (context, state) => AccountPublisherEditScreen(
|
||||||
|
name: state.pathParameters['name']!,
|
||||||
|
),
|
||||||
|
),
|
||||||
GoRoute(
|
GoRoute(
|
||||||
path: '/account/:name',
|
path: '/account/:name',
|
||||||
name: 'accountProfilePage',
|
name: 'accountProfilePage',
|
||||||
@ -281,25 +257,15 @@ final _appRoutes = [
|
|||||||
child: UserScreen(name: state.pathParameters['name']!),
|
child: UserScreen(name: state.pathParameters['name']!),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
ShellRoute(
|
GoRoute(
|
||||||
builder: (context, state, child) => child,
|
path: '/settings',
|
||||||
routes: [
|
name: 'settings',
|
||||||
GoRoute(
|
builder: (context, state) => SettingsScreen(),
|
||||||
path: '/settings',
|
|
||||||
name: 'settings',
|
|
||||||
builder: (context, state) => SettingsScreen(),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
ShellRoute(
|
GoRoute(
|
||||||
builder: (context, state, child) => child,
|
path: '/about',
|
||||||
routes: [
|
name: 'about',
|
||||||
GoRoute(
|
builder: (context, state) => AboutScreen(),
|
||||||
path: '/about',
|
|
||||||
name: 'about',
|
|
||||||
builder: (context, state) => AboutScreen(),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
),
|
),
|
||||||
];
|
];
|
||||||
|
|
||||||
|
@ -19,7 +19,6 @@ import 'package:surface/types/check_in.dart';
|
|||||||
import 'package:surface/types/post.dart';
|
import 'package:surface/types/post.dart';
|
||||||
import 'package:surface/widgets/account/account_image.dart';
|
import 'package:surface/widgets/account/account_image.dart';
|
||||||
import 'package:surface/widgets/dialog.dart';
|
import 'package:surface/widgets/dialog.dart';
|
||||||
import 'package:surface/widgets/navigation/app_scaffold.dart';
|
|
||||||
import 'package:surface/widgets/universal_image.dart';
|
import 'package:surface/widgets/universal_image.dart';
|
||||||
|
|
||||||
const Map<String, (String, IconData, Color)> kBadgesMeta = {
|
const Map<String, (String, IconData, Color)> kBadgesMeta = {
|
||||||
|
@ -1,7 +1,6 @@
|
|||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:bitsdojo_window/bitsdojo_window.dart';
|
import 'package:bitsdojo_window/bitsdojo_window.dart';
|
||||||
import 'package:easy_localization/easy_localization.dart';
|
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:go_router/go_router.dart';
|
import 'package:go_router/go_router.dart';
|
||||||
@ -12,7 +11,6 @@ import 'package:styled_widget/styled_widget.dart';
|
|||||||
import 'package:surface/providers/config.dart';
|
import 'package:surface/providers/config.dart';
|
||||||
import 'package:surface/providers/navigation.dart';
|
import 'package:surface/providers/navigation.dart';
|
||||||
import 'package:surface/widgets/connection_indicator.dart';
|
import 'package:surface/widgets/connection_indicator.dart';
|
||||||
import 'package:surface/widgets/dialog.dart';
|
|
||||||
import 'package:surface/widgets/navigation/app_background.dart';
|
import 'package:surface/widgets/navigation/app_background.dart';
|
||||||
import 'package:surface/widgets/navigation/app_bottom_navigation.dart';
|
import 'package:surface/widgets/navigation/app_bottom_navigation.dart';
|
||||||
import 'package:surface/widgets/navigation/app_drawer_navigation.dart';
|
import 'package:surface/widgets/navigation/app_drawer_navigation.dart';
|
||||||
|
Loading…
x
Reference in New Issue
Block a user