mirror of
https://github.com/lucavenir/go_router_riverpod.git
synced 2025-08-06 14:59:53 +08:00
27 lines
706 B
Dart
27 lines
706 B
Dart
import 'package:flutter/material.dart';
|
|
import 'package:go_router/go_router.dart';
|
|
import 'package:riverpod_annotation/riverpod_annotation.dart';
|
|
|
|
import 'router_notifier.dart';
|
|
import 'routes.dart';
|
|
|
|
part 'router.g.dart';
|
|
|
|
final _key = GlobalKey<NavigatorState>(debugLabel: 'routerKey');
|
|
|
|
/// This simple provider caches our GoRouter.
|
|
/// This provider will never rebuild by design.
|
|
@riverpod
|
|
GoRouter router(RouterRef ref) {
|
|
final notifier = ref.watch(routerNotifierProvider.notifier);
|
|
|
|
return GoRouter(
|
|
navigatorKey: _key,
|
|
refreshListenable: notifier,
|
|
debugLogDiagnostics: true,
|
|
initialLocation: SplashRoute.path,
|
|
routes: notifier.routes,
|
|
redirect: notifier.redirect,
|
|
);
|
|
}
|