6fef0db009
CI / flutter-gates (push) Successful in 1m3s
- AnalyticsRouteObserver:didPush/didReplace/didPop 集中捕获,页面零侵入 - AnalyticsPageName 枚举:pageName 编译期锁死(字典 v2 九个初始值 + 客户端现存 create/pet_archive/services/post_detail),字典外路由不上报 - PageViewTracker:page_viewed 单一上报出口,维护 referrer 链(栈底/冷启动首页为 null)与去重(Tab 重复点选) - 三类非路由曝光手动补点:主壳 Tab 切换(IndexedStack)、认证状态机切页(AnimatedSwitcher)、回栈到无名根路由(resolveRootPage) - 既有 Navigator.push 挂 RouteSettings.name:login_page(register)、main_shell_page(post_detail);fade_route 签名扩展可选 settings - M2 健康档案页面(pet_list/pet_detail/pet_form/record_form/record_detail)先留枚举定义,待功能落地接线 测试新增 8 例(analytics_route_observer_test):push 上报/push 两页 referrer 链正确 + pop 补报/根路由 resolveRootPage 补报/枚举外不报/dialog 不报/Tab 去重/referrer 连贯/reportTab。 验收对照(06 号报告 §5.2 六条):1✓ observer 注册、2✓ pageName 枚举含 pet_form、3✓ referrer 链、4✓ 字典外不报、5✓ 单测 push/pop/referrer、6✓ M1 存量四页接全。 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
209 lines
6.8 KiB
Dart
209 lines
6.8 KiB
Dart
import 'package:flutter/material.dart';
|
|
import 'package:patbond_flutter/analytics/analytics_page_name.dart';
|
|
import 'package:patbond_flutter/analytics/page_view_tracker.dart';
|
|
import 'package:patbond_flutter/core/theme/app_theme.dart';
|
|
import 'package:patbond_flutter/features/create/create_page.dart';
|
|
import 'package:patbond_flutter/features/home/home_page.dart';
|
|
import 'package:patbond_flutter/features/pets/pets_page.dart';
|
|
import 'package:patbond_flutter/features/post/post_detail_page.dart';
|
|
import 'package:patbond_flutter/features/profile/profile_page.dart';
|
|
import 'package:patbond_flutter/features/services/services_page.dart';
|
|
import 'package:patbond_flutter/models/models.dart';
|
|
import 'package:patbond_flutter/state/app_state.dart';
|
|
import 'package:patbond_flutter/widgets/common.dart';
|
|
|
|
class MainShellPage extends StatefulWidget {
|
|
const MainShellPage({
|
|
required this.appState,
|
|
super.key,
|
|
this.pageViewTracker,
|
|
this.onLogout,
|
|
});
|
|
|
|
final AppState appState;
|
|
|
|
/// Tab 曝光补点(IndexedStack 切换不产生路由事件,03 号评估 §3.2)。
|
|
final PageViewTracker? pageViewTracker;
|
|
|
|
/// 退出登录:调 logout 接口并清会话,认证状态机自动回登录页。
|
|
final Future<void> Function()? onLogout;
|
|
|
|
@override
|
|
State<MainShellPage> createState() => _MainShellPageState();
|
|
}
|
|
|
|
class _MainShellPageState extends State<MainShellPage> {
|
|
int currentIndex = 0;
|
|
bool showPersonalServices = false;
|
|
|
|
static const titles = ['首页', '创作中心', '健康档案', '本地服务', '我的资料'];
|
|
|
|
/// Tab 索引 → pageName 枚举(03 号评估 §3.2 映射表)。
|
|
static const _tabPages = [
|
|
AnalyticsPageName.home,
|
|
AnalyticsPageName.create,
|
|
AnalyticsPageName.petArchive,
|
|
AnalyticsPageName.services,
|
|
AnalyticsPageName.profile,
|
|
];
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
// 初始 Tab 曝光补一次(03 号评估 §3.2 手动补点 1)。
|
|
widget.pageViewTracker?.reportTab(_tabPages[currentIndex]);
|
|
}
|
|
|
|
void selectTab(int index) {
|
|
setState(() => currentIndex = index);
|
|
widget.pageViewTracker?.reportTab(_tabPages[index]);
|
|
}
|
|
|
|
void openServices(bool personal) {
|
|
setState(() {
|
|
showPersonalServices = personal;
|
|
currentIndex = 3;
|
|
});
|
|
widget.pageViewTracker?.reportTab(_tabPages[3]);
|
|
}
|
|
|
|
void openPost(PostModel post) {
|
|
Navigator.of(context).push(
|
|
MaterialPageRoute<void>(
|
|
settings: RouteSettings(name: AnalyticsPageName.postDetail.pageName),
|
|
builder: (context) =>
|
|
PostDetailPage(appState: widget.appState, postId: post.id),
|
|
),
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return AnimatedBuilder(
|
|
animation: widget.appState,
|
|
builder: (context, _) {
|
|
if (!widget.appState.isReady) {
|
|
return const Scaffold(
|
|
body: Center(child: CircularProgressIndicator()),
|
|
);
|
|
}
|
|
|
|
final pages = [
|
|
HomePage(
|
|
appState: widget.appState,
|
|
onOpenPost: openPost,
|
|
onOpenServices: openServices,
|
|
onOpenCreate: () => selectTab(1),
|
|
),
|
|
CreatePage(
|
|
appState: widget.appState,
|
|
onPublished: (post) {
|
|
selectTab(0);
|
|
WidgetsBinding.instance.addPostFrameCallback(
|
|
(_) => openPost(post),
|
|
);
|
|
},
|
|
),
|
|
PetsPage(appState: widget.appState),
|
|
ServicesPage(
|
|
showPersonal: showPersonalServices,
|
|
locationWeather: widget.appState.locationWeather,
|
|
),
|
|
ProfilePage(appState: widget.appState, onLogout: widget.onLogout),
|
|
];
|
|
|
|
return Scaffold(
|
|
appBar: AppBar(
|
|
backgroundColor: Colors.white.withAlpha(245),
|
|
surfaceTintColor: Colors.transparent,
|
|
scrolledUnderElevation: 1,
|
|
centerTitle: true,
|
|
title: Text(
|
|
titles[currentIndex],
|
|
style: const TextStyle(fontSize: 16, fontWeight: FontWeight.w800),
|
|
),
|
|
leadingWidth: 118,
|
|
leading: InkWell(
|
|
onTap: () => selectTab(2),
|
|
borderRadius: BorderRadius.circular(24),
|
|
child: Padding(
|
|
padding: const EdgeInsets.only(left: 14),
|
|
child: Row(
|
|
children: [
|
|
RemoteImage(
|
|
url: widget.appState.pet.avatarUrl,
|
|
width: 36,
|
|
height: 36,
|
|
borderRadius: BorderRadius.circular(18),
|
|
),
|
|
const SizedBox(width: 7),
|
|
const Expanded(
|
|
child: Text(
|
|
'Patbond',
|
|
maxLines: 1,
|
|
overflow: TextOverflow.ellipsis,
|
|
style: TextStyle(
|
|
color: AppColors.primary,
|
|
fontSize: 13,
|
|
fontWeight: FontWeight.w800,
|
|
),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
actions: [
|
|
IconButton.filledTonal(
|
|
tooltip: '通知',
|
|
onPressed: () {
|
|
ScaffoldMessenger.of(
|
|
context,
|
|
).showSnackBar(const SnackBar(content: Text('暂无新通知 🐾')));
|
|
},
|
|
icon: const Icon(Icons.notifications_outlined, size: 21),
|
|
),
|
|
const SizedBox(width: 10),
|
|
],
|
|
),
|
|
body: SafeArea(
|
|
top: false,
|
|
child: IndexedStack(index: currentIndex, children: pages),
|
|
),
|
|
bottomNavigationBar: NavigationBar(
|
|
selectedIndex: currentIndex,
|
|
onDestinationSelected: selectTab,
|
|
destinations: const [
|
|
NavigationDestination(
|
|
icon: Icon(Icons.home_outlined),
|
|
selectedIcon: Icon(Icons.home_rounded),
|
|
label: '首页',
|
|
),
|
|
NavigationDestination(
|
|
icon: Icon(Icons.auto_awesome_outlined),
|
|
selectedIcon: Icon(Icons.auto_awesome),
|
|
label: '创作',
|
|
),
|
|
NavigationDestination(
|
|
icon: Icon(Icons.pets_outlined),
|
|
selectedIcon: Icon(Icons.pets),
|
|
label: '档案',
|
|
),
|
|
NavigationDestination(
|
|
icon: Icon(Icons.storefront_outlined),
|
|
selectedIcon: Icon(Icons.storefront),
|
|
label: '服务',
|
|
),
|
|
NavigationDestination(
|
|
icon: Icon(Icons.person_outline),
|
|
selectedIcon: Icon(Icons.person),
|
|
label: '我的',
|
|
),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|