Files
blog_app/lib/pages/category_page.dart
2025-11-15 16:56:47 +08:00

54 lines
1.3 KiB
Dart

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 CategoryPage extends StatefulWidget {
const CategoryPage({super.key});
@override
State<CategoryPage> createState() => _CategoryPageState();
}
class _CategoryPageState extends State<CategoryPage> {
late List<BlogCategory> categories = [];
@override
void initState() {
super.initState();
_loadBlogCategory();
}
Future<void> _loadBlogCategory() async {
try {
final result = await queryBlogCategoryApi();
setState(() {
categories = result;
});
} catch (e) {
throw Exception('获取博客分类失败: $e');
}
}
@override
Widget build(BuildContext context) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
buildCategoryTitle(context, categories.length),
SizedBox(height: 10),
// 分类列表
Expanded(
child: ListView.builder(
itemCount: categories.length,
itemBuilder: (context, index) {
final category = categories[index];
return buildCategoryCard(context, category);
},
),
),
],
);
}
}