router property
latefinal
Implementation
late final GoRouter router = GoRouter(
initialLocation: AppRoutePath.homeRoute,
routes: [
// Home Route
GoRoute(
path: AppRoutePath.homeRoute,
builder: (context, state) => const ProjectsPage(),
),
// Task List Route
GoRoute(
path: '${AppRoutePath.taskListRoute}/:taskId',
builder: (context, state) {
final taskId = state.pathParameters['taskId'];
if (taskId == null || taskId.isEmpty) {
return const Scaffold(
body: Center(child: Text('Project ID is missing')),
);
}
return BlocProvider(
create: (context) =>
getIt<TasksBloc>()..add(FetchTasksEvent(taskId)),
child: TasksPage(projectId: taskId));
},
),
GoRoute(
path: AppRoutePath.taskHistory,
builder: (context, state) => const TaskHistory(),
),
// Add Task Route
GoRoute(
path: AppRoutePath.createTaskRoute,
builder: (context, state) => const CreateTaskScreen(),
),
GoRoute(
path: '${AppRoutePath.updateTaskRoute}/:taskId',
builder: (context, state) {
final taskId = state.pathParameters['taskId'];
if (taskId == null || taskId.isEmpty) {
return const Scaffold(
body: Center(child: Text('Task ID is missing')),
);
}
return BlocProvider(
create: (context) => getIt<CommentBloc>()
..add(FetchCommentsEvent(taskId: taskId, projectId: '')),
child: BlocProvider(
create: (context) =>
getIt<UpdateTaskBloc>()..add(FetchTask(taskId: taskId)),
child: UpdateTaskScreen(taskId: taskId),
),
);
},
),
],
// Error Page for unknown routes
errorBuilder: (context, state) => Scaffold(
appBar: AppBar(title: const Text('404 - Page not found')),
body: const Center(
child: Text('404 - The page you are looking for does not exist.')),
),
);