8d890c0424
- 新增 lib/core/network/:ApiClient(dio 封装,错误信封→类型化异常,base URL 经 --dart-define=PATBOND_API_BASE_URL 注入)、AuthInterceptor(Bearer + 设备标识)、TokenRefresher(单飞刷新,401/40101 重放一次,仅 40102/再 401 清会话) - 新增 lib/features/auth/:SessionManager(token 只进 flutter_secure_storage)、AuthRepository(login/register/refresh/logout/me,注册带 Idempotency-Key)、Splash(500ms 最短停留/5s 超时/错误态重试+改用账号登录)、登录页与注册页(照 12 号组装稿,错误三层映射,预留区不渲染) - App 根组件改为认证状态机驱动(Splash↔登录↔主壳 300ms fade);个人中心退出登录接入真实 logout - 顺带修复:FIX-1 促销卡渐变改 [primaryStrong, primary]、FIX-2 补 helperStyle: muted、README dart format 命令补 --output=none - 新增依赖:dio ^5.11.1、flutter_secure_storage ^11.0.0、uuid ^4.6.0 - 门禁:dart format(0 changed)/ flutter analyze(No issues)/ flutter test(30 passed,其中新增 23:TokenRefresher 5 + AuthRepository 10 + 登录页 4 + 注册页 4) Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
180 lines
5.9 KiB
Dart
180 lines
5.9 KiB
Dart
import 'package:flutter/material.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.onLogout});
|
|
|
|
final AppState appState;
|
|
|
|
/// 退出登录:调 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 = ['首页', '创作中心', '健康档案', '本地服务', '我的资料'];
|
|
|
|
void selectTab(int index) {
|
|
setState(() => currentIndex = index);
|
|
}
|
|
|
|
void openServices(bool personal) {
|
|
setState(() {
|
|
showPersonalServices = personal;
|
|
currentIndex = 3;
|
|
});
|
|
}
|
|
|
|
void openPost(PostModel post) {
|
|
Navigator.of(context).push(
|
|
MaterialPageRoute<void>(
|
|
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: '我的',
|
|
),
|
|
],
|
|
),
|
|
);
|
|
},
|
|
);
|
|
}
|
|
}
|