import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:go_router/go_router.dart'; import '../../presentation/screens/home_screen.dart'; import '../../presentation/screens/schematic_editor_screen.dart'; import '../../presentation/screens/project_list_screen.dart'; import '../../presentation/screens/component_library_screen.dart'; /// 路由路径定义 class AppRoutes { static const String home = '/'; static const String projects = '/projects'; static const String editor = '/editor'; static const String components = '/components'; static const String settings = '/settings'; } /// 路由配置 final routerProvider = Provider((ref) { return GoRouter( initialLocation: AppRoutes.home, debugLogDiagnostics: true, routes: [ // 首页 GoRoute( path: AppRoutes.home, name: 'home', builder: (context, state) => const HomeScreen(), ), // 项目列表 GoRoute( path: AppRoutes.projects, name: 'projects', builder: (context, state) => const ProjectListScreen(), ), // 原理图编辑器 GoRoute( path: AppRoutes.editor, name: 'editor', builder: (context, state) { final projectId = state.uri.queryParameters['projectId']; return SchematicEditorScreen(projectId: projectId); }, ), // 元件库 GoRoute( path: AppRoutes.components, name: 'components', builder: (context, state) => const ComponentLibraryScreen(), ), ], // 错误页面 errorBuilder: (context, state) => Scaffold( appBar: AppBar(title: const Text('错误')), body: const Center(child: Text('页面未找到')), ), ); });