From 37c61a0406c1c491e372db5074e636e36d37d6be Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Fri, 15 Nov 2024 22:46:12 +0800 Subject: [PATCH] :zap: Optimize nav transition performance --- lib/main.dart | 4 ++++ lib/router.dart | 27 ++++++++++++++++----------- lib/widgets/connection_indicator.dart | 2 +- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/lib/main.dart b/lib/main.dart index 4201c0b..a8952e0 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -13,6 +13,7 @@ import 'package:surface/providers/theme.dart'; import 'package:surface/providers/userinfo.dart'; import 'package:surface/providers/websocket.dart'; import 'package:surface/router.dart'; +import 'package:surface/widgets/navigation/app_scaffold.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); @@ -83,6 +84,9 @@ class AppMainContent extends StatelessWidget { ...context.localizationDelegates, ], routerConfig: appRouter, + builder: (context, child) { + return AppRootScaffold(body: child ?? const SizedBox.shrink()); + }, ); } } diff --git a/lib/router.dart b/lib/router.dart index b54e002..82c6bb0 100644 --- a/lib/router.dart +++ b/lib/router.dart @@ -27,27 +27,37 @@ final _appRoutes = [ GoRoute( path: '/', name: 'home', - builder: (context, state) => const HomeScreen(), + pageBuilder: (context, state) => NoTransitionPage( + child: const HomeScreen(), + ), ), GoRoute( path: '/posts', name: 'explore', - builder: (context, state) => const ExploreScreen(), + pageBuilder: (context, state) => NoTransitionPage( + child: const ExploreScreen(), + ), ), GoRoute( path: '/account', name: 'account', - builder: (context, state) => const AccountScreen(), + pageBuilder: (context, state) => NoTransitionPage( + child: const AccountScreen(), + ), ), GoRoute( path: '/chat', name: 'chat', - builder: (context, state) => const ChatScreen(), + pageBuilder: (context, state) => NoTransitionPage( + child: const ChatScreen(), + ), ), GoRoute( path: '/album', name: 'album', - builder: (context, state) => const AlbumScreen(), + pageBuilder: (context, state) => NoTransitionPage( + child: const AlbumScreen(), + ), ), ], ), @@ -130,10 +140,5 @@ final _appRoutes = [ ]; final appRouter = GoRouter( - routes: [ - ShellRoute( - builder: (context, state, child) => AppRootScaffold(body: child), - routes: _appRoutes, - ), - ], + routes: _appRoutes, ); diff --git a/lib/widgets/connection_indicator.dart b/lib/widgets/connection_indicator.dart index 8fcef67..f0289ee 100644 --- a/lib/widgets/connection_indicator.dart +++ b/lib/widgets/connection_indicator.dart @@ -42,7 +42,7 @@ class ConnectionIndicator extends StatelessWidget { ) .height( (ws.isBusy || !ws.isConnected) && ua.isAuthorized - ? MediaQuery.of(context).padding.top + 30 + ? MediaQuery.of(context).padding.top + 36 : 0, animate: true) .animate(