app_router.dart 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. import 'package:flutter/material.dart';
  2. import 'package:go_router/go_router.dart';
  3. import '../pages/dashboard_page.dart';
  4. import '../pages/upload_page.dart';
  5. import '../pages/parse_compare_page.dart';
  6. import '../pages/ai_process_page.dart';
  7. import '../pages/traction_page.dart';
  8. import '../pages/result_page.dart';
  9. import '../pages/task_center_page.dart';
  10. import '../utils/constants.dart';
  11. /// 应用路由配置
  12. class AppRouter {
  13. static const String _initialLocation = String.fromEnvironment(
  14. 'DEFAULT_ROUTE',
  15. defaultValue: AppRoutes.home,
  16. // defaultValue: '${AppRoutes.result}/1',
  17. );
  18. static final GoRouter router = GoRouter(
  19. initialLocation: _initialLocation,
  20. routes: [
  21. GoRoute(
  22. path: AppRoutes.home,
  23. name: 'home',
  24. builder: (context, state) => const DashboardPage(),
  25. ),
  26. GoRoute(
  27. path: AppRoutes.tasks,
  28. name: 'tasks',
  29. builder: (context, state) => const TaskCenterPage(),
  30. ),
  31. GoRoute(
  32. path: AppRoutes.upload,
  33. name: 'upload',
  34. builder: (context, state) => const UploadPage(),
  35. ),
  36. GoRoute(
  37. path: '${AppRoutes.parse}/:id',
  38. name: 'parse',
  39. builder: (context, state) {
  40. final id = state.pathParameters['id']!;
  41. return ParseComparePage(documentId: id);
  42. },
  43. ),
  44. GoRoute(
  45. path: '${AppRoutes.process}/:id',
  46. name: 'process',
  47. builder: (context, state) {
  48. final id = state.pathParameters['id']!;
  49. return AIProcessPage(documentId: id);
  50. },
  51. ),
  52. GoRoute(
  53. path: '${AppRoutes.traction}/:id',
  54. name: 'traction',
  55. builder: (context, state) {
  56. final id = state.pathParameters['id']!;
  57. return TractionPage(documentId: id);
  58. },
  59. ),
  60. GoRoute(
  61. path: '${AppRoutes.result}/:id',
  62. name: 'result',
  63. builder: (context, state) {
  64. final id = state.pathParameters['id']!;
  65. return ResultPage(documentId: id);
  66. },
  67. ),
  68. ],
  69. errorBuilder: (context, state) => Scaffold(
  70. body: Center(
  71. child: Column(
  72. mainAxisAlignment: MainAxisAlignment.center,
  73. children: [
  74. const Icon(Icons.error_outline, size: 64, color: Colors.red),
  75. const SizedBox(height: 16),
  76. Text('页面未找到: ${state.uri}'),
  77. const SizedBox(height: 16),
  78. ElevatedButton(
  79. onPressed: () => context.go(AppRoutes.home),
  80. child: const Text('返回首页'),
  81. ),
  82. ],
  83. ),
  84. ),
  85. ),
  86. );
  87. }