feat:增加博客分类模块
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
import 'package:blog_app/layout/drawer.dart';
|
||||
import 'package:blog_app/layout/menu.dart';
|
||||
import 'package:blog_app/pages/about_page.dart';
|
||||
import 'package:blog_app/pages/blog_page.dart';
|
||||
import 'package:blog_app/pages/message_page.dart';
|
||||
import 'package:blog_app/pages/profile_page.dart';
|
||||
import 'package:blog_app/pages/category_page.dart';
|
||||
import 'package:blog_app/pages/settings_page.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
@@ -14,18 +15,6 @@ class _HomePageState extends State<HomePage> {
|
||||
int _currentPageIndex = 0;
|
||||
late PageController _pageController;
|
||||
|
||||
// 页面标题列表
|
||||
final List<String> _pageTitles = ['博客', '消息中心', '设置', '关于我们'];
|
||||
|
||||
// 页面图标列表
|
||||
final List<IconData> _pageIcons = [
|
||||
Icons.article,
|
||||
Icons.person,
|
||||
Icons.message,
|
||||
Icons.settings,
|
||||
Icons.info,
|
||||
];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
@@ -46,7 +35,7 @@ class _HomePageState extends State<HomePage> {
|
||||
_currentPageIndex = index;
|
||||
});
|
||||
},
|
||||
children: [BlogPage(), MessagePage(), SettingsPage(), AboutPage()],
|
||||
children: [BlogPage(), CategoryPage(), SettingsPage(), AboutPage()],
|
||||
);
|
||||
}
|
||||
|
||||
@@ -55,7 +44,7 @@ class _HomePageState extends State<HomePage> {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(
|
||||
_pageTitles[_currentPageIndex],
|
||||
pages[_currentPageIndex].title,
|
||||
style: TextStyle(color: Colors.white),
|
||||
),
|
||||
backgroundColor: Theme.of(context).colorScheme.primary,
|
||||
@@ -79,6 +68,35 @@ class _HomePageState extends State<HomePage> {
|
||||
);
|
||||
}
|
||||
|
||||
void onTapDrawerItem(int index) {
|
||||
setState(() {
|
||||
_currentPageIndex = index;
|
||||
});
|
||||
_pageController.animateToPage(
|
||||
index,
|
||||
duration: Duration(milliseconds: 300),
|
||||
curve: Curves.easeInOut,
|
||||
);
|
||||
Navigator.pop(context);
|
||||
}
|
||||
|
||||
Widget _buildDrawerBody() {
|
||||
return ListView(
|
||||
padding: EdgeInsets.zero,
|
||||
children: [
|
||||
...List.generate(
|
||||
pages.length,
|
||||
(index) => buildDrawerItem(
|
||||
context: context,
|
||||
page: pages[index],
|
||||
isSelected: index == _currentPageIndex,
|
||||
onTap: () => onTapDrawerItem(index),
|
||||
),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDrawer() {
|
||||
return Drawer(
|
||||
child: Container(
|
||||
@@ -86,145 +104,12 @@ class _HomePageState extends State<HomePage> {
|
||||
child: Column(
|
||||
children: [
|
||||
// 抽屉头部
|
||||
_buildDrawerHeader(),
|
||||
|
||||
buildDrawerHeader(context),
|
||||
// 菜单项列表
|
||||
Expanded(
|
||||
child: ListView(
|
||||
padding: EdgeInsets.zero,
|
||||
children: [
|
||||
...List.generate(
|
||||
_pageTitles.length,
|
||||
(index) => _buildDrawerItem(
|
||||
icon: _pageIcons[index],
|
||||
title: _pageTitles[index],
|
||||
index: index,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
Expanded(child: _buildDrawerBody()),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDrawerHeader() {
|
||||
return Container(
|
||||
width: double.infinity,
|
||||
height: 200,
|
||||
decoration: BoxDecoration(
|
||||
gradient: LinearGradient(
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [Colors.blue, Colors.lightBlue],
|
||||
),
|
||||
),
|
||||
child: SafeArea(
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
CircleAvatar(
|
||||
radius: 40,
|
||||
backgroundColor: Colors.white.withOpacity(0.3),
|
||||
child: Icon(Icons.person, size: 50, color: Colors.white),
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
Text(
|
||||
'用户名',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
SizedBox(height: 4),
|
||||
Text(
|
||||
'user@example.com',
|
||||
style: TextStyle(color: Colors.white70, fontSize: 14),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDrawerItem({
|
||||
required IconData icon,
|
||||
required String title,
|
||||
required int index,
|
||||
}) {
|
||||
final bool isSelected = index == _currentPageIndex;
|
||||
final bool isSpecialItem = index == -1; // 特殊菜单项标识
|
||||
|
||||
return Container(
|
||||
margin: EdgeInsets.symmetric(horizontal: 12, vertical: 4),
|
||||
decoration: BoxDecoration(
|
||||
color: isSelected ? Colors.blue.withOpacity(0.1) : Colors.transparent,
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: ListTile(
|
||||
leading: Icon(
|
||||
icon,
|
||||
color:
|
||||
isSelected
|
||||
? Colors.blue
|
||||
: isSpecialItem
|
||||
? Colors.grey[600]
|
||||
: Colors.grey[700],
|
||||
size: 24,
|
||||
),
|
||||
title: Text(
|
||||
title,
|
||||
style: TextStyle(
|
||||
color:
|
||||
isSelected
|
||||
? Colors.blue
|
||||
: isSpecialItem
|
||||
? Colors.grey[600]
|
||||
: Colors.grey[800],
|
||||
fontWeight: isSelected ? FontWeight.bold : FontWeight.normal,
|
||||
fontSize: 16,
|
||||
),
|
||||
),
|
||||
trailing:
|
||||
isSelected
|
||||
? Icon(Icons.arrow_forward_ios, size: 16, color: Colors.blue)
|
||||
: null,
|
||||
onTap: () {
|
||||
if (!isSpecialItem) {
|
||||
// 正常页面切换
|
||||
setState(() {
|
||||
_currentPageIndex = index;
|
||||
});
|
||||
_pageController.animateToPage(
|
||||
index,
|
||||
duration: Duration(milliseconds: 300),
|
||||
curve: Curves.easeInOut,
|
||||
);
|
||||
} else {
|
||||
// 特殊菜单项处理
|
||||
_handleSpecialItemTap(title);
|
||||
}
|
||||
Navigator.pop(context); // 关闭抽屉
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _handleSpecialItemTap(String title) {
|
||||
// 处理特殊菜单项的点击事件
|
||||
switch (title) {
|
||||
case '帮助中心':
|
||||
print('打开帮助中心');
|
||||
break;
|
||||
case '意见反馈':
|
||||
print('打开意见反馈');
|
||||
break;
|
||||
case '退出登录':
|
||||
print('执行退出登录');
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user