Compare commits

...

2 Commits

Author SHA1 Message Date
cb4a2598c8 ♻️ Refactored router 2025-01-25 14:35:04 +08:00
950612dc07 🐛 Fix error when went to publisher page from account page 2025-01-25 14:27:09 +08:00
6 changed files with 216 additions and 246 deletions

View File

@ -260,7 +260,7 @@ class _AppSplashScreenState extends State<_AppSplashScreen> {
try { try {
final cfg = context.read<ConfigProvider>(); final cfg = context.read<ConfigProvider>();
WidgetsBinding.instance.addPostFrameCallback((_) { WidgetsBinding.instance.addPostFrameCallback((_) {
cfg.calcDrawerSize(context); cfg.calcDrawerSize(context, withMediaQuery: true);
}); });
final home = context.read<HomeWidgetProvider>(); final home = context.read<HomeWidgetProvider>();
await home.initialize(); await home.initialize();

View File

@ -41,14 +41,22 @@ class ConfigProvider extends ChangeNotifier {
bool drawerIsCollapsed = false; bool drawerIsCollapsed = false;
bool drawerIsExpanded = false; bool drawerIsExpanded = false;
void calcDrawerSize(BuildContext context) { void calcDrawerSize(BuildContext context, {bool withMediaQuery = false}) {
bool newDrawerIsCollapsed = false;
bool newDrawerIsExpanded = false;
if (withMediaQuery) {
newDrawerIsCollapsed = MediaQuery.of(context).size.width < 450;
newDrawerIsExpanded = MediaQuery.of(context).size.width >= 451;
} else {
final rpb = ResponsiveBreakpoints.of(context); final rpb = ResponsiveBreakpoints.of(context);
final newDrawerIsCollapsed = rpb.smallerOrEqualTo(MOBILE); newDrawerIsCollapsed = rpb.smallerOrEqualTo(MOBILE);
final newDrawerIsExpanded = rpb.largerThan(TABLET) newDrawerIsCollapsed = rpb.largerThan(TABLET)
? (prefs.getBool(kAppDrawerPreferCollapse) ?? false) ? (prefs.getBool(kAppDrawerPreferCollapse) ?? false)
? false ? false
: true : true
: false; : false;
}
if (newDrawerIsExpanded != drawerIsExpanded || newDrawerIsCollapsed != drawerIsCollapsed) { if (newDrawerIsExpanded != drawerIsExpanded || newDrawerIsCollapsed != drawerIsCollapsed) {
drawerIsExpanded = newDrawerIsExpanded; drawerIsExpanded = newDrawerIsExpanded;
drawerIsCollapsed = newDrawerIsCollapsed; drawerIsCollapsed = newDrawerIsCollapsed;

View File

@ -34,21 +34,30 @@ 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(
builder: (context, state, child) => child,
routes: [
GoRoute( GoRoute(
path: '/', path: '/',
name: 'home', name: 'home',
pageBuilder: (context, state) => NoTransitionPage( pageBuilder: (context, state) => CustomTransitionPage(
transitionsBuilder: _fadeThroughTransition,
child: const HomeScreen(), child: const HomeScreen(),
), ),
), ),
GoRoute( GoRoute(
path: '/posts', path: '/posts',
name: 'explore', name: 'explore',
pageBuilder: (context, state) => NoTransitionPage( pageBuilder: (context, state) => CustomTransitionPage(
transitionsBuilder: _fadeThroughTransition,
child: const ExploreScreen(), child: const ExploreScreen(),
), ),
routes: [ routes: [
@ -96,30 +105,15 @@ final _appRoutes = [
path: '/account', path: '/account',
name: 'account', name: 'account',
pageBuilder: (context, state) => CustomTransitionPage( pageBuilder: (context, state) => CustomTransitionPage(
transitionsBuilder: (context, animation, secondaryAnimation, child) { transitionsBuilder: _fadeThroughTransition,
return FadeThroughTransition(
animation: animation,
secondaryAnimation: secondaryAnimation,
fillColor: Colors.transparent,
child: child,
);
},
child: const AccountScreen(), child: const AccountScreen(),
), ),
routes: [],
), ),
GoRoute( GoRoute(
path: '/chat', path: '/chat',
name: 'chat', name: 'chat',
pageBuilder: (context, state) => CustomTransitionPage( pageBuilder: (context, state) => CustomTransitionPage(
transitionsBuilder: (context, animation, secondaryAnimation, child) { transitionsBuilder: _fadeThroughTransition,
return FadeThroughTransition(
animation: animation,
secondaryAnimation: secondaryAnimation,
fillColor: Colors.transparent,
child: child,
);
},
child: const ChatScreen(), child: const ChatScreen(),
), ),
routes: [ routes: [
@ -165,46 +159,34 @@ final _appRoutes = [
animation: animation, animation: animation,
secondaryAnimation: secondaryAnimation, secondaryAnimation: secondaryAnimation,
fillColor: Colors.transparent, fillColor: Colors.transparent,
child: AppBackground(
child: child, child: child,
),
); );
}, },
), ),
), ),
GoRoute(
path: '/:alias',
name: 'realmDetail',
builder: (context, state) => AppBackground(
child: RealmDetailScreen(alias: state.pathParameters['alias']!),
),
),
], ],
), ),
GoRoute( GoRoute(
path: '/realm', path: '/realm',
name: 'realm', name: 'realm',
pageBuilder: (context, state) => NoTransitionPage( pageBuilder: (context, state) => CustomTransitionPage(
transitionsBuilder: _fadeThroughTransition,
child: const RealmScreen(), child: const RealmScreen(),
), ),
routes: [ routes: [
GoRoute(
path: '/:alias',
name: 'realmDetail',
builder: (context, state) => RealmDetailScreen(alias: state.pathParameters['alias']!),
),
GoRoute( GoRoute(
path: '/manage', path: '/manage',
name: 'realmManage', name: 'realmManage',
pageBuilder: (context, state) => CustomTransitionPage( pageBuilder: (context, state) => CustomTransitionPage(
transitionsBuilder: _fadeThroughTransition,
child: RealmManageScreen( child: RealmManageScreen(
editingRealmAlias: state.uri.queryParameters['editing'], editingRealmAlias: state.uri.queryParameters['editing'],
), ),
transitionsBuilder: (context, animation, secondaryAnimation, child) {
return FadeThroughTransition(
animation: animation,
secondaryAnimation: secondaryAnimation,
fillColor: Colors.transparent,
child: AppBackground(
child: child,
),
);
},
), ),
), ),
], ],
@ -212,7 +194,8 @@ final _appRoutes = [
GoRoute( GoRoute(
path: '/album', path: '/album',
name: 'album', name: 'album',
pageBuilder: (context, state) => NoTransitionPage( pageBuilder: (context, state) => CustomTransitionPage(
transitionsBuilder: _fadeThroughTransition,
child: const AlbumScreen(), child: const AlbumScreen(),
), ),
), ),
@ -230,11 +213,6 @@ final _appRoutes = [
child: const NotificationScreen(), child: const NotificationScreen(),
), ),
), ),
],
),
ShellRoute(
builder: (context, state, child) => child,
routes: [
GoRoute( GoRoute(
path: '/auth/login', path: '/auth/login',
name: 'authLogin', name: 'authLogin',
@ -272,8 +250,6 @@ final _appRoutes = [
name: state.pathParameters['name']!, name: state.pathParameters['name']!,
), ),
), ),
],
),
GoRoute( GoRoute(
path: '/account/:name', path: '/account/:name',
name: 'accountProfilePage', name: 'accountProfilePage',
@ -281,26 +257,16 @@ final _appRoutes = [
child: UserScreen(name: state.pathParameters['name']!), child: UserScreen(name: state.pathParameters['name']!),
), ),
), ),
ShellRoute(
builder: (context, state, child) => child,
routes: [
GoRoute( GoRoute(
path: '/settings', path: '/settings',
name: 'settings', name: 'settings',
builder: (context, state) => SettingsScreen(), builder: (context, state) => SettingsScreen(),
), ),
],
),
ShellRoute(
builder: (context, state, child) => child,
routes: [
GoRoute( GoRoute(
path: '/about', path: '/about',
name: 'about', name: 'about',
builder: (context, state) => AboutScreen(), builder: (context, state) => AboutScreen(),
), ),
],
),
]; ];
final appRouter = GoRouter( final appRouter = GoRouter(

View File

@ -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 = {
@ -596,7 +595,7 @@ class _UserScreenState extends State<UserScreen> with SingleTickerProviderStateM
subtitle: Text('@${ele.name}'), subtitle: Text('@${ele.name}'),
trailing: const Icon(Symbols.chevron_right), trailing: const Icon(Symbols.chevron_right),
onTap: () { onTap: () {
GoRouter.of(context).pushNamed( GoRouter.of(context).goNamed(
'postPublisher', 'postPublisher',
pathParameters: {'name': ele.name}, pathParameters: {'name': ele.name},
); );

View File

@ -7,12 +7,11 @@ import 'package:marquee/marquee.dart';
import 'package:provider/provider.dart'; import 'package:provider/provider.dart';
import 'package:responsive_framework/responsive_framework.dart'; import 'package:responsive_framework/responsive_framework.dart';
import 'package:styled_widget/styled_widget.dart'; import 'package:styled_widget/styled_widget.dart';
import 'package:surface/providers/link_preview.dart';
import 'package:surface/types/link.dart'; import 'package:surface/types/link.dart';
import 'package:surface/widgets/universal_image.dart'; import 'package:surface/widgets/universal_image.dart';
import 'package:url_launcher/url_launcher_string.dart'; import 'package:url_launcher/url_launcher_string.dart';
import '../providers/link_preview.dart';
class LinkPreviewWidget extends StatefulWidget { class LinkPreviewWidget extends StatefulWidget {
final String text; final String text;

View File

@ -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';