mirror of
https://github.com/Dr-Blank/Vaani.git
synced 2025-12-09 12:39:29 +00:00
routes
This commit is contained in:
parent
ebc14a0448
commit
f8597f7430
13 changed files with 509 additions and 33 deletions
52
lib/router/router.dart
Normal file
52
lib/router/router.dart
Normal file
|
|
@ -0,0 +1,52 @@
|
|||
import 'package:go_router/go_router.dart';
|
||||
import 'package:whispering_pages/pages/home_page.dart';
|
||||
import 'package:whispering_pages/pages/library_item_page.dart';
|
||||
import 'package:whispering_pages/pages/library_page.dart';
|
||||
import 'package:whispering_pages/pages/onboarding/onboarding.dart';
|
||||
|
||||
part 'constants.dart';
|
||||
|
||||
// GoRouter configuration
|
||||
class MyAppRouter {
|
||||
const MyAppRouter({required this.needOnboarding});
|
||||
final bool needOnboarding;
|
||||
// some static strings for named routes
|
||||
|
||||
GoRouter get config => GoRouter(
|
||||
routes: [
|
||||
GoRoute(
|
||||
path: '/login',
|
||||
name: Routes.onboarding,
|
||||
builder: (context, state) => const OnboardingPage(),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/',
|
||||
name: Routes.home,
|
||||
builder: (context, state) => const HomePage(),
|
||||
),
|
||||
// /library/:libraryId
|
||||
GoRoute(
|
||||
path: Routes.library.path,
|
||||
name: Routes.library.name,
|
||||
builder: (context, state) => LibraryPage(
|
||||
libraryId: state.pathParameters[Routes.library.pathParamName]!,
|
||||
),
|
||||
),
|
||||
GoRoute(
|
||||
path: Routes.libraryItem.path,
|
||||
name: Routes.libraryItem.name,
|
||||
builder: (context, state) {
|
||||
final itemId =
|
||||
state.pathParameters[Routes.libraryItem.pathParamName]!;
|
||||
return LibraryItemPage(itemId: itemId, extra: state.extra);
|
||||
},
|
||||
),
|
||||
],
|
||||
redirect: (context, state) {
|
||||
if (needOnboarding) {
|
||||
return context.namedLocation(Routes.onboarding);
|
||||
}
|
||||
return null;
|
||||
},
|
||||
);
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue