feat(app): 初始化 Flutter 前端项目 (Phase F0)
- Flutter 3.44.0 + Dart 3.12.0 - 设计系统: 7色Token×浅/深模式, NotoSansSC/Caveat字体, 圆角10/16/22/28/pill, 三级阴影 - ResponsiveScaffold: 手机底部TabBar / 平板侧边Rail / 桌面三栏 - go_router 路由表: 13个页面 (5个Tab + 8个全屏页面) - 13个功能模块占位页面 (home/calendar/mood/search/profile/editor/auth/class/teacher/parent/achievement/stickers/templates) - 依赖: flutter_bloc, go_router, freezed, isar, dio, perfect_freehand, fl_chart - 中国镜像: PUB_HOSTED_URL + FLUTTER_STORAGE_BASE_URL - flutter analyze: No issues found
This commit is contained in:
181
app/lib/core/routing/app_router.dart
Normal file
181
app/lib/core/routing/app_router.dart
Normal file
@@ -0,0 +1,181 @@
|
||||
// 暖记路由表 — go_router 20 页面
|
||||
|
||||
export '../../widgets/responsive_scaffold.dart';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
import '../../widgets/responsive_scaffold.dart';
|
||||
|
||||
import '../../features/home/views/home_page.dart';
|
||||
import '../../features/calendar/views/calendar_page.dart';
|
||||
import '../../features/mood/views/mood_page.dart';
|
||||
import '../../features/search/views/search_page.dart';
|
||||
import '../../features/profile/views/profile_page.dart';
|
||||
import '../../features/editor/views/editor_page.dart';
|
||||
import '../../features/auth/views/login_page.dart';
|
||||
import '../../features/class_/views/class_page.dart';
|
||||
import '../../features/teacher/views/teacher_page.dart';
|
||||
import '../../features/parent/views/parent_page.dart';
|
||||
import '../../features/achievement/views/achievement_page.dart';
|
||||
import '../../features/stickers/views/sticker_library_page.dart';
|
||||
import '../../features/templates/views/template_gallery_page.dart';
|
||||
|
||||
// Shell 分支键
|
||||
final _rootNavigatorKey = GlobalKey<NavigatorState>();
|
||||
final _shellNavigatorKey = GlobalKey<NavigatorState>();
|
||||
|
||||
/// 暖记路由配置
|
||||
final appRouter = GoRouter(
|
||||
navigatorKey: _rootNavigatorKey,
|
||||
initialLocation: '/home',
|
||||
debugLogDiagnostics: true,
|
||||
routes: [
|
||||
// 认证路由(无 Shell)
|
||||
GoRoute(
|
||||
path: '/login',
|
||||
name: 'login',
|
||||
builder: (context, state) => const LoginPage(),
|
||||
),
|
||||
|
||||
// 主 Shell 路由(底部导航 + 侧边导航)
|
||||
ShellRoute(
|
||||
navigatorKey: _shellNavigatorKey,
|
||||
builder: (context, state, child) {
|
||||
// 根据当前路径计算选中的 tab index
|
||||
final index = _selectedIndexFromLocation(state.uri.path);
|
||||
return _AppShell(
|
||||
selectedIndex: index,
|
||||
child: child,
|
||||
);
|
||||
},
|
||||
routes: [
|
||||
// Tab 0: 首页日记流
|
||||
GoRoute(
|
||||
path: '/home',
|
||||
name: 'home',
|
||||
builder: (context, state) => const HomePage(),
|
||||
),
|
||||
// Tab 1: 日历
|
||||
GoRoute(
|
||||
path: '/calendar',
|
||||
name: 'calendar',
|
||||
builder: (context, state) => const CalendarPage(),
|
||||
),
|
||||
// Tab 2: 心情
|
||||
GoRoute(
|
||||
path: '/mood',
|
||||
name: 'mood',
|
||||
builder: (context, state) => const MoodPage(),
|
||||
),
|
||||
// Tab 3: 搜索
|
||||
GoRoute(
|
||||
path: '/search',
|
||||
name: 'search',
|
||||
builder: (context, state) => const SearchPage(),
|
||||
),
|
||||
// Tab 4: 个人中心
|
||||
GoRoute(
|
||||
path: '/profile',
|
||||
name: 'profile',
|
||||
builder: (context, state) => const ProfilePage(),
|
||||
),
|
||||
],
|
||||
),
|
||||
|
||||
// 全屏页面(无底部导航)
|
||||
GoRoute(
|
||||
path: '/editor',
|
||||
name: 'editor',
|
||||
parentNavigatorKey: _rootNavigatorKey,
|
||||
builder: (context, state) {
|
||||
final journalId = state.uri.queryParameters['id'];
|
||||
return EditorPage(journalId: journalId);
|
||||
},
|
||||
),
|
||||
GoRoute(
|
||||
path: '/class',
|
||||
name: 'class',
|
||||
parentNavigatorKey: _rootNavigatorKey,
|
||||
builder: (context, state) => const ClassPage(),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/teacher',
|
||||
name: 'teacher',
|
||||
parentNavigatorKey: _rootNavigatorKey,
|
||||
builder: (context, state) => const TeacherPage(),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/parent',
|
||||
name: 'parent',
|
||||
parentNavigatorKey: _rootNavigatorKey,
|
||||
builder: (context, state) => const ParentPage(),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/achievements',
|
||||
name: 'achievements',
|
||||
parentNavigatorKey: _rootNavigatorKey,
|
||||
builder: (context, state) => const AchievementPage(),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/stickers',
|
||||
name: 'stickers',
|
||||
parentNavigatorKey: _rootNavigatorKey,
|
||||
builder: (context, state) => const StickerLibraryPage(),
|
||||
),
|
||||
GoRoute(
|
||||
path: '/templates',
|
||||
name: 'templates',
|
||||
parentNavigatorKey: _rootNavigatorKey,
|
||||
builder: (context, state) => const TemplateGalleryPage(),
|
||||
),
|
||||
],
|
||||
);
|
||||
|
||||
/// 路径 → Tab index 映射
|
||||
int _selectedIndexFromLocation(String location) {
|
||||
if (location.startsWith('/calendar')) return 1;
|
||||
if (location.startsWith('/mood')) return 2;
|
||||
if (location.startsWith('/search')) return 3;
|
||||
if (location.startsWith('/profile')) return 4;
|
||||
return 0; // 默认首页
|
||||
}
|
||||
|
||||
/// App Shell — 包裹 ResponsiveScaffold
|
||||
class _AppShell extends StatelessWidget {
|
||||
const _AppShell({
|
||||
required this.selectedIndex,
|
||||
required this.child,
|
||||
});
|
||||
|
||||
final int selectedIndex;
|
||||
final Widget child;
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ResponsiveScaffold(
|
||||
selectedIndex: selectedIndex,
|
||||
onDestinationSelected: (index) {
|
||||
switch (index) {
|
||||
case 0:
|
||||
context.go('/home');
|
||||
case 1:
|
||||
context.go('/calendar');
|
||||
case 2:
|
||||
context.go('/mood');
|
||||
case 3:
|
||||
context.go('/search');
|
||||
case 4:
|
||||
context.go('/profile');
|
||||
}
|
||||
},
|
||||
body: child,
|
||||
floatingActionButton: selectedIndex == 0
|
||||
? FloatingActionButton(
|
||||
onPressed: () => context.go('/editor'),
|
||||
child: const Icon(Icons.edit_rounded),
|
||||
)
|
||||
: null,
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user