feat:增加博客卡片内容
This commit is contained in:
38
lib/pages/blog_page.dart
Normal file
38
lib/pages/blog_page.dart
Normal file
@@ -0,0 +1,38 @@
|
||||
import 'package:blog_app/apis/blog.dart';
|
||||
import 'package:blog_app/models/blog.dart';
|
||||
import 'package:blog_app/widget/blog.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class BlogPage extends StatefulWidget {
|
||||
const BlogPage({super.key});
|
||||
|
||||
@override
|
||||
State<BlogPage> createState() => _BlogPageState();
|
||||
}
|
||||
|
||||
class _BlogPageState extends State<BlogPage> {
|
||||
late List<Blog> blogList = [];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
// 初始加载数据
|
||||
_loadData();
|
||||
}
|
||||
|
||||
Future<void> _loadData() async {
|
||||
final result = await queryBlogByPageApi(1, 10);
|
||||
|
||||
setState(() {
|
||||
blogList = result.records;
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return ListView.builder(
|
||||
itemCount: blogList.length,
|
||||
itemBuilder: (context, index) => BlogCard(blog: blogList[index]),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
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/settings_page.dart';
|
||||
@@ -14,16 +15,11 @@ class _HomePageState extends State<HomePage> {
|
||||
late PageController _pageController;
|
||||
|
||||
// 页面标题列表
|
||||
final List<String> _pageTitles = [
|
||||
'个人资料',
|
||||
'消息中心',
|
||||
'设置',
|
||||
'关于我们',
|
||||
];
|
||||
final List<String> _pageTitles = ['博客', '消息中心', '设置', '关于我们'];
|
||||
|
||||
// 页面图标列表
|
||||
final List<IconData> _pageIcons = [
|
||||
Icons.home,
|
||||
Icons.article,
|
||||
Icons.person,
|
||||
Icons.message,
|
||||
Icons.settings,
|
||||
@@ -42,18 +38,34 @@ class _HomePageState extends State<HomePage> {
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
Widget _buildPageView() {
|
||||
return PageView(
|
||||
controller: _pageController,
|
||||
onPageChanged: (index) {
|
||||
setState(() {
|
||||
_currentPageIndex = index;
|
||||
});
|
||||
},
|
||||
children: [BlogPage(), MessagePage(), SettingsPage(), AboutPage()],
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: Text(_pageTitles[_currentPageIndex]),
|
||||
backgroundColor: Colors.blue,
|
||||
title: Text(
|
||||
_pageTitles[_currentPageIndex],
|
||||
style: TextStyle(color: Colors.white),
|
||||
),
|
||||
backgroundColor: Theme.of(context).colorScheme.primary,
|
||||
elevation: 0,
|
||||
leading: Builder(
|
||||
builder: (context) => IconButton(
|
||||
icon: Icon(Icons.menu, color: Colors.white),
|
||||
onPressed: () => Scaffold.of(context).openDrawer(),
|
||||
),
|
||||
builder:
|
||||
(context) => IconButton(
|
||||
icon: Icon(Icons.menu, color: Colors.white),
|
||||
onPressed: () => Scaffold.of(context).openDrawer(),
|
||||
),
|
||||
),
|
||||
actions: [
|
||||
IconButton(
|
||||
@@ -63,20 +75,7 @@ class _HomePageState extends State<HomePage> {
|
||||
],
|
||||
),
|
||||
drawer: _buildDrawer(),
|
||||
body: PageView(
|
||||
controller: _pageController,
|
||||
onPageChanged: (index) {
|
||||
setState(() {
|
||||
_currentPageIndex = index;
|
||||
});
|
||||
},
|
||||
children: [
|
||||
ProfilePage(),
|
||||
MessagePage(),
|
||||
SettingsPage(),
|
||||
AboutPage(),
|
||||
],
|
||||
),
|
||||
body: Padding(padding: EdgeInsets.all(10), child: _buildPageView()),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -94,12 +93,13 @@ class _HomePageState extends State<HomePage> {
|
||||
child: ListView(
|
||||
padding: EdgeInsets.zero,
|
||||
children: [
|
||||
...List.generate(_pageTitles.length, (index) =>
|
||||
_buildDrawerItem(
|
||||
icon: _pageIcons[index],
|
||||
title: _pageTitles[index],
|
||||
index: index,
|
||||
)
|
||||
...List.generate(
|
||||
_pageTitles.length,
|
||||
(index) => _buildDrawerItem(
|
||||
icon: _pageIcons[index],
|
||||
title: _pageTitles[index],
|
||||
index: index,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -128,11 +128,7 @@ class _HomePageState extends State<HomePage> {
|
||||
CircleAvatar(
|
||||
radius: 40,
|
||||
backgroundColor: Colors.white.withOpacity(0.3),
|
||||
child: Icon(
|
||||
Icons.person,
|
||||
size: 50,
|
||||
color: Colors.white,
|
||||
),
|
||||
child: Icon(Icons.person, size: 50, color: Colors.white),
|
||||
),
|
||||
SizedBox(height: 16),
|
||||
Text(
|
||||
@@ -146,10 +142,7 @@ class _HomePageState extends State<HomePage> {
|
||||
SizedBox(height: 4),
|
||||
Text(
|
||||
'user@example.com',
|
||||
style: TextStyle(
|
||||
color: Colors.white70,
|
||||
fontSize: 14,
|
||||
),
|
||||
style: TextStyle(color: Colors.white70, fontSize: 14),
|
||||
),
|
||||
],
|
||||
),
|
||||
@@ -174,24 +167,31 @@ class _HomePageState extends State<HomePage> {
|
||||
child: ListTile(
|
||||
leading: Icon(
|
||||
icon,
|
||||
color: isSelected ? Colors.blue :
|
||||
isSpecialItem ? Colors.grey[600] : Colors.grey[700],
|
||||
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],
|
||||
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,
|
||||
trailing:
|
||||
isSelected
|
||||
? Icon(Icons.arrow_forward_ios, size: 16, color: Colors.blue)
|
||||
: null,
|
||||
onTap: () {
|
||||
if (!isSpecialItem) {
|
||||
// 正常页面切换
|
||||
@@ -228,101 +228,3 @@ class _HomePageState extends State<HomePage> {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 各个页面组件
|
||||
class HomeContentPage extends StatelessWidget {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SingleChildScrollView(
|
||||
padding: EdgeInsets.all(16),
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
// 欢迎卡片
|
||||
Card(
|
||||
elevation: 4,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(16),
|
||||
),
|
||||
child: Padding(
|
||||
padding: EdgeInsets.all(20),
|
||||
child: Row(
|
||||
children: [
|
||||
Icon(Icons.waving_hand, size: 40, color: Colors.amber),
|
||||
SizedBox(width: 16),
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
'欢迎回来!',
|
||||
style: TextStyle(
|
||||
fontSize: 20,
|
||||
fontWeight: FontWeight.bold,
|
||||
),
|
||||
),
|
||||
SizedBox(height: 4),
|
||||
Text(
|
||||
'今天也是美好的一天',
|
||||
style: TextStyle(color: Colors.grey),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
|
||||
SizedBox(height: 20),
|
||||
|
||||
// 功能网格
|
||||
GridView.count(
|
||||
shrinkWrap: true,
|
||||
physics: NeverScrollableScrollPhysics(),
|
||||
crossAxisCount: 2,
|
||||
crossAxisSpacing: 16,
|
||||
mainAxisSpacing: 16,
|
||||
children: [
|
||||
_buildFeatureCard('数据统计', Icons.analytics, Colors.blue),
|
||||
_buildFeatureCard('文件管理', Icons.folder, Colors.green),
|
||||
_buildFeatureCard('消息通知', Icons.notifications, Colors.orange),
|
||||
_buildFeatureCard('系统设置', Icons.settings, Colors.purple),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildFeatureCard(String title, IconData icon, Color color) {
|
||||
return Card(
|
||||
elevation: 2,
|
||||
shape: RoundedRectangleBorder(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
),
|
||||
child: InkWell(
|
||||
borderRadius: BorderRadius.circular(12),
|
||||
onTap: () {},
|
||||
child: Container(
|
||||
padding: EdgeInsets.all(16),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
Icon(icon, size: 40, color: color),
|
||||
SizedBox(height: 8),
|
||||
Text(
|
||||
title,
|
||||
style: TextStyle(
|
||||
fontWeight: FontWeight.bold,
|
||||
fontSize: 14,
|
||||
),
|
||||
textAlign: TextAlign.center,
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
import 'package:blog_app/utils/http_util.dart';
|
||||
import 'package:blog_app/utils/http_utils.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:markdown_widget/config/toc.dart';
|
||||
import 'package:markdown_widget/widget/markdown.dart';
|
||||
|
||||
Reference in New Issue
Block a user