From cb4a2598c84590a163bf1a62ed62a48f768d0a6a Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Sat, 25 Jan 2025 14:35:04 +0800 Subject: [PATCH] :recycle: Refactored router --- lib/router.dart | 428 +++++++++++------------ lib/screens/account/profile_page.dart | 1 - lib/widgets/navigation/app_scaffold.dart | 2 - 3 files changed, 197 insertions(+), 234 deletions(-) diff --git a/lib/router.dart b/lib/router.dart index 52f8257..4ed1091 100644 --- a/lib/router.dart +++ b/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_scaffold.dart'; +Widget _fadeThroughTransition( + BuildContext context, Animation animation, Animation secondaryAnimation, Widget child) { + return FadeThroughTransition( + animation: animation, + secondaryAnimation: secondaryAnimation, + fillColor: Colors.transparent, + child: child, + ); +} + final _appRoutes = [ - ShellRoute( - builder: (context, state, child) => child, + GoRoute( + 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: [ GoRoute( - path: '/', - name: 'home', - pageBuilder: (context, state) => NoTransitionPage( - child: const HomeScreen(), + 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: '/posts', - name: 'explore', - pageBuilder: (context, state) => NoTransitionPage( - child: const ExploreScreen(), - ), - 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(), + path: '/search', + name: 'postSearch', + builder: (context, state) => PostSearchScreen( + initialTags: state.uri.queryParameters['tags']?.split(','), + initialCategories: state.uri.queryParameters['categories']?.split(','), ), ), GoRoute( - path: '/friend', - name: 'friend', - pageBuilder: (context, state) => NoTransitionPage( - child: const FriendScreen(), - ), + path: '/publishers/:name', + name: 'postPublisher', + builder: (context, state) => PostPublisherScreen(name: state.pathParameters['name']!), ), GoRoute( - path: '/notification', - name: 'notification', - pageBuilder: (context, state) => NoTransitionPage( - child: const NotificationScreen(), + path: '/:slug', + name: 'postDetail', + builder: (context, state) => PostDetailScreen( + slug: state.pathParameters['slug']!, + preload: state.extra as SnPost?, ), ), ], ), - ShellRoute( - builder: (context, state, child) => child, + GoRoute( + 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: [ GoRoute( - path: '/auth/login', - name: 'authLogin', - builder: (context, state) => LoginScreen(), + path: '/:scope/:alias', + name: 'chatRoom', + builder: (context, state) => AppBackground( + child: ChatRoomScreen( + scope: state.pathParameters['scope']!, + alias: state.pathParameters['alias']!, + ), + ), ), GoRoute( - path: '/auth/register', - name: 'authRegister', - builder: (context, state) => RegisterScreen(), + path: '/:scope/:alias/call', + name: 'chatCallRoom', + builder: (context, state) => AppBackground( + child: CallRoomScreen( + scope: state.pathParameters['scope']!, + alias: state.pathParameters['alias']!, + ), + ), ), GoRoute( - path: '/reports', - name: 'abuseReport', - builder: (context, state) => AbuseReportScreen(), + path: '/:scope/:alias/detail', + name: 'channelDetail', + builder: (context, state) => AppBackground( + child: ChannelDetailScreen( + scope: state.pathParameters['scope']!, + alias: state.pathParameters['alias']!, + ), + ), ), 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']!, + 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: child, + ); + }, ), ), ], ), + 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( path: '/account/:name', name: 'accountProfilePage', @@ -281,25 +257,15 @@ final _appRoutes = [ child: UserScreen(name: state.pathParameters['name']!), ), ), - ShellRoute( - builder: (context, state, child) => child, - routes: [ - GoRoute( - path: '/settings', - name: 'settings', - builder: (context, state) => SettingsScreen(), - ), - ], + GoRoute( + path: '/settings', + name: 'settings', + builder: (context, state) => SettingsScreen(), ), - ShellRoute( - builder: (context, state, child) => child, - routes: [ - GoRoute( - path: '/about', - name: 'about', - builder: (context, state) => AboutScreen(), - ), - ], + GoRoute( + path: '/about', + name: 'about', + builder: (context, state) => AboutScreen(), ), ]; diff --git a/lib/screens/account/profile_page.dart b/lib/screens/account/profile_page.dart index 59842af..e6b3185 100644 --- a/lib/screens/account/profile_page.dart +++ b/lib/screens/account/profile_page.dart @@ -19,7 +19,6 @@ import 'package:surface/types/check_in.dart'; import 'package:surface/types/post.dart'; import 'package:surface/widgets/account/account_image.dart'; import 'package:surface/widgets/dialog.dart'; -import 'package:surface/widgets/navigation/app_scaffold.dart'; import 'package:surface/widgets/universal_image.dart'; const Map kBadgesMeta = { diff --git a/lib/widgets/navigation/app_scaffold.dart b/lib/widgets/navigation/app_scaffold.dart index d52ee0a..350a71a 100644 --- a/lib/widgets/navigation/app_scaffold.dart +++ b/lib/widgets/navigation/app_scaffold.dart @@ -1,7 +1,6 @@ import 'dart:io'; import 'package:bitsdojo_window/bitsdojo_window.dart'; -import 'package:easy_localization/easy_localization.dart'; import 'package:flutter/foundation.dart'; import 'package:flutter/material.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/navigation.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_bottom_navigation.dart'; import 'package:surface/widgets/navigation/app_drawer_navigation.dart';