Skip to content

Commit 7c5b43a

Browse files
committed
use riverpod provider for routing
* fix riverpod_lint not working * bump riverpod deps
1 parent c7bc86c commit 7c5b43a

6 files changed

Lines changed: 156 additions & 219 deletions

File tree

src/analysis_options.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,4 +37,4 @@ analyzer:
3737
- riverpod_lint
3838

3939
plugins:
40-
riverpod_lint: 3.0.3
40+
riverpod_lint: ^3.0.3

src/lib/core/routing/app_router.dart

Lines changed: 104 additions & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -15,103 +15,111 @@ import 'package:revitool/features/tweaks/personalization/personalization_page.da
1515
import 'package:revitool/features/tweaks/security/security_page.dart';
1616
import 'package:revitool/features/tweaks/tweaks_page.dart';
1717
import 'package:revitool/main.dart';
18+
import 'package:riverpod_annotation/riverpod_annotation.dart';
19+
20+
part 'app_router.g.dart';
1821

1922
final _rootNavigatorKey = GlobalKey<NavigatorState>(debugLabel: 'root');
2023
final _shellNavigatorKey = GlobalKey<NavigatorState>(debugLabel: 'shell');
2124

22-
final appRouter = GoRouter(
23-
navigatorKey: _rootNavigatorKey,
24-
initialLocation: initialRoute ?? RouteMeta.home.path,
25-
redirect: (context, state) {
26-
if (!WinRegistryService.isSupported) {
27-
return AppRoutes.unsupported;
28-
}
29-
return null; // Allow navigation
30-
},
31-
routes: [
32-
ShellRoute(
33-
navigatorKey: _shellNavigatorKey,
34-
builder: (context, state, child) {
35-
return AppShell(shellContext: context, child: child);
36-
},
37-
routes: [
38-
GoRoute(
39-
path: RouteMeta.home.path,
40-
name: 'home',
41-
builder: (context, state) => const HomePage(),
42-
),
43-
GoRoute(
44-
path: RouteMeta.tweaks.path,
45-
name: 'tweaks',
46-
builder: (context, state) => const TweaksPage(),
47-
routes: [
48-
GoRoute(
49-
path: 'security',
50-
name: 'security',
51-
pageBuilder: (context, state) =>
52-
AppRoutes.buildPageWithHorizontalTransition(
53-
barrierColor: context.theme.scaffoldBackgroundColor,
54-
state: state,
55-
child: const SecurityPage(),
56-
),
57-
),
58-
GoRoute(
59-
path: 'performance',
60-
name: 'performance',
61-
pageBuilder: (context, state) =>
62-
AppRoutes.buildPageWithHorizontalTransition(
63-
barrierColor: context.theme.scaffoldBackgroundColor,
64-
state: state,
65-
child: const PerformancePage(),
66-
),
67-
),
68-
GoRoute(
69-
path: 'personalization',
70-
name: 'personalization',
71-
pageBuilder: (context, state) =>
72-
AppRoutes.buildPageWithHorizontalTransition(
73-
barrierColor: context.theme.scaffoldBackgroundColor,
74-
state: state,
75-
child: const PersonalizationPage(),
76-
),
77-
),
78-
GoRoute(
79-
path: 'utilities',
80-
name: 'utilities',
81-
pageBuilder: (context, state) =>
82-
AppRoutes.buildPageWithHorizontalTransition(
83-
barrierColor: context.theme.scaffoldBackgroundColor,
84-
state: state,
85-
child: const UtilitiesPage(),
86-
),
87-
),
88-
GoRoute(
89-
path: 'updates',
90-
name: 'updates',
91-
pageBuilder: (context, state) =>
92-
AppRoutes.buildPageWithHorizontalTransition(
93-
barrierColor: context.theme.scaffoldBackgroundColor,
94-
state: state,
95-
child: const UpdatesPage(),
96-
),
97-
),
98-
],
99-
),
100-
GoRoute(
101-
path: RouteMeta.msStore.path,
102-
name: 'msstore',
103-
builder: (context, state) => const MSStorePage(),
104-
),
105-
GoRoute(
106-
path: RouteMeta.settings.path,
107-
name: 'settings',
108-
builder: (context, state) => const SettingsPage(),
109-
),
110-
],
111-
),
112-
GoRoute(
113-
path: AppRoutes.unsupported,
114-
builder: (context, state) => const UnsupportedWidget(),
115-
),
116-
],
117-
);
25+
@riverpod
26+
GoRouter appRouter(Ref ref) {
27+
final router = GoRouter(
28+
navigatorKey: _rootNavigatorKey,
29+
initialLocation: initialRoute ?? RouteMeta.home.path,
30+
redirect: (context, state) {
31+
if (!WinRegistryService.isSupported) {
32+
return AppRoutes.unsupported;
33+
}
34+
return null; // Allow navigation
35+
},
36+
routes: [
37+
ShellRoute(
38+
navigatorKey: _shellNavigatorKey,
39+
builder: (context, state, child) {
40+
return AppShell(shellContext: context, child: child);
41+
},
42+
routes: [
43+
GoRoute(
44+
path: RouteMeta.home.path,
45+
name: 'home',
46+
builder: (context, state) => const HomePage(),
47+
),
48+
GoRoute(
49+
path: RouteMeta.tweaks.path,
50+
name: 'tweaks',
51+
builder: (context, state) => const TweaksPage(),
52+
routes: [
53+
GoRoute(
54+
path: 'security',
55+
name: 'security',
56+
pageBuilder: (context, state) =>
57+
AppRoutes.buildPageWithHorizontalTransition(
58+
barrierColor: context.theme.scaffoldBackgroundColor,
59+
state: state,
60+
child: const SecurityPage(),
61+
),
62+
),
63+
GoRoute(
64+
path: 'performance',
65+
name: 'performance',
66+
pageBuilder: (context, state) =>
67+
AppRoutes.buildPageWithHorizontalTransition(
68+
barrierColor: context.theme.scaffoldBackgroundColor,
69+
state: state,
70+
child: const PerformancePage(),
71+
),
72+
),
73+
GoRoute(
74+
path: 'personalization',
75+
name: 'personalization',
76+
pageBuilder: (context, state) =>
77+
AppRoutes.buildPageWithHorizontalTransition(
78+
barrierColor: context.theme.scaffoldBackgroundColor,
79+
state: state,
80+
child: const PersonalizationPage(),
81+
),
82+
),
83+
GoRoute(
84+
path: 'utilities',
85+
name: 'utilities',
86+
pageBuilder: (context, state) =>
87+
AppRoutes.buildPageWithHorizontalTransition(
88+
barrierColor: context.theme.scaffoldBackgroundColor,
89+
state: state,
90+
child: const UtilitiesPage(),
91+
),
92+
),
93+
GoRoute(
94+
path: 'updates',
95+
name: 'updates',
96+
pageBuilder: (context, state) =>
97+
AppRoutes.buildPageWithHorizontalTransition(
98+
barrierColor: context.theme.scaffoldBackgroundColor,
99+
state: state,
100+
child: const UpdatesPage(),
101+
),
102+
),
103+
],
104+
),
105+
GoRoute(
106+
path: RouteMeta.msStore.path,
107+
name: 'msstore',
108+
builder: (context, state) => const MSStorePage(),
109+
),
110+
GoRoute(
111+
path: RouteMeta.settings.path,
112+
name: 'settings',
113+
builder: (context, state) => const SettingsPage(),
114+
),
115+
],
116+
),
117+
GoRoute(
118+
path: AppRoutes.unsupported,
119+
builder: (context, state) => const UnsupportedWidget(),
120+
),
121+
],
122+
);
123+
124+
return router;
125+
}

src/lib/core/routing/app_shell.dart

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,9 @@ class _AppShellState extends ConsumerState<AppShell> {
8383
appBar: NavigationAppBar(
8484
automaticallyImplyLeading: false,
8585
leading: () {
86-
final enabled = widget.shellContext != null && appRouter.canPop();
86+
final enabled =
87+
widget.shellContext != null &&
88+
ref.read(appRouterProvider).canPop();
8789
final onPressed = enabled
8890
? () {
8991
context.pop();

src/lib/main.dart

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,6 @@ Future<void> main(List<String> args) async {
7979
);
8080
}
8181

82-
// Initialize locale from registry
8382
logger.i('$tag Initializing locale');
8483
try {
8584
final savedLocale = LocaleConfig.parse(appLanguage);
@@ -102,7 +101,7 @@ Future<void> main(List<String> args) async {
102101
);
103102
await WindowPlus.instance.setMinimumSize(const Size(515, 330));
104103

105-
runApp(TranslationProvider(child: const ProviderScope(child: MyApp())));
104+
runApp(ProviderScope(child: TranslationProvider(child: const MyApp())));
106105
}
107106

108107
bool _isSupported = false;
@@ -117,7 +116,7 @@ class MyApp extends ConsumerWidget {
117116

118117
return SystemThemeBuilder(
119118
builder: (context, accent) => FluentApp.router(
120-
routerConfig: appRouter,
119+
routerConfig: ref.read(appRouterProvider),
121120
title: 'Revision Tool',
122121
debugShowCheckedModeBanner: false,
123122
locale: TranslationProvider.of(context).flutterLocale,

0 commit comments

Comments
 (0)