f501a959f3
CI / flutter-gates (push) Successful in 1m9s
- 生产接线修复:app.dart 组装时传 analytics 实例给 ApiAuthRepository(_buildRepository),修复 M1 遗留的「生产环境 _analytics 恒为 null、挂接点空转」问题 - sessionId 生命周期:新建 SessionTracker (WidgetsBindingObserver),冷启动生成 UUIDv7、后台超 30 分钟换新、未超阈值沿用原值,不再每事件随机生成 - eventId 改 UUIDv7:对齐 13 号规范(uuid 包已在依赖,直接用 v7()),保留插入时间局部性 - appVersion 动态注入:package_info_plus(新增依赖)异步读取后 setAppVersion,不再硬编码 '1.0.0+1' - osVersion 动态读取:Platform.operatingSystemVersion 正则提取主版本(如 android-14),不再硬编码 - 队列顺手加固:上传失败批次重回队首而非整批丢弃(一行级缓解,分段持久化属 M2 第二波) 测试新增 9 例:session_tracker_test(5 例:冷启动/短后台/长后台/级联状态/连续幂等),analytics_service_test 补强 4 例(UUIDv7/sessionId 不再逐事件生成/appVersion 可注入/失败重回队列)。 验收对照(06 号报告 §5.1 六条):1✓ SessionTracker 新建、2✓ 三条语义、3✓ 同会话 sessionId 一致、4✓ sessionId 为 UUID 不持久化、5✓ 单测 3 例(实际 5 例)、6✓ 真机脚本(开发者手测)。 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: '我的',
|
|
),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|