新增静态演示界面
This commit is contained in:
@@ -1,8 +1,19 @@
|
||||
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({super.key});
|
||||
const MainShellPage({required this.appState, super.key});
|
||||
|
||||
final AppState appState;
|
||||
|
||||
@override
|
||||
State<MainShellPage> createState() => _MainShellPageState();
|
||||
@@ -10,72 +21,156 @@ class MainShellPage extends StatefulWidget {
|
||||
|
||||
class _MainShellPageState extends State<MainShellPage> {
|
||||
int currentIndex = 0;
|
||||
bool showPersonalServices = false;
|
||||
|
||||
final pages = const [
|
||||
HomePage(),
|
||||
Center(child: Text('发现')),
|
||||
Center(child: Text('发布')),
|
||||
Center(child: Text('消息')),
|
||||
Center(child: Text('我的')),
|
||||
];
|
||||
static const titles = ['首页', '创作中心', '健康档案', '本地服务', '我的资料'];
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: pages[currentIndex],
|
||||
bottomNavigationBar: NavigationBarTheme(
|
||||
data: NavigationBarThemeData(
|
||||
backgroundColor: Colors.white,
|
||||
indicatorColor: Colors.red.shade50,
|
||||
labelTextStyle: WidgetStateProperty.all(
|
||||
const TextStyle(
|
||||
fontSize: 12,
|
||||
fontWeight: FontWeight.w600,
|
||||
),
|
||||
),
|
||||
iconTheme: WidgetStateProperty.resolveWith((states) {
|
||||
if (states.contains(WidgetState.selected)) {
|
||||
return const IconThemeData(color: Colors.red);
|
||||
}
|
||||
return const IconThemeData(color: Colors.grey);
|
||||
}),
|
||||
),
|
||||
child: NavigationBar(
|
||||
selectedIndex: currentIndex,
|
||||
onDestinationSelected: (index) {
|
||||
setState(() {
|
||||
currentIndex = index;
|
||||
});
|
||||
},
|
||||
destinations: const [
|
||||
NavigationDestination(
|
||||
icon: Icon(Icons.home_outlined),
|
||||
selectedIcon: Icon(Icons.home),
|
||||
label: '首页',
|
||||
),
|
||||
NavigationDestination(
|
||||
icon: Icon(Icons.explore_outlined),
|
||||
selectedIcon: Icon(Icons.explore),
|
||||
label: '发现',
|
||||
),
|
||||
NavigationDestination(
|
||||
icon: Icon(Icons.add_circle_outline),
|
||||
selectedIcon: Icon(Icons.add_circle),
|
||||
label: '发布',
|
||||
),
|
||||
NavigationDestination(
|
||||
icon: Icon(Icons.notifications_outlined),
|
||||
selectedIcon: Icon(Icons.notifications),
|
||||
label: '消息',
|
||||
),
|
||||
NavigationDestination(
|
||||
icon: Icon(Icons.person_outline),
|
||||
selectedIcon: Icon(Icons.person),
|
||||
label: '我的',
|
||||
),
|
||||
],
|
||||
),
|
||||
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),
|
||||
];
|
||||
|
||||
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: '我的',
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user