feat:更新日历组件

This commit is contained in:
2025-07-11 16:48:04 +08:00
parent b56b822e01
commit 55ca36cba2
7 changed files with 103 additions and 106 deletions

View File

@@ -1,8 +1,8 @@
import 'package:flutter/material.dart';
import 'package:food_hub_app/widgets/recipe/recipe_calendar.dart';
import 'package:food_hub_app/widgets/recipe/recipe_list.dart';
import 'package:food_hub_app/widgets/recipe/recipe_segment.dart';
import 'package:food_hub_app/widgets/recipe/recipe_timeline.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';
import 'models/recipe.dart';
@@ -13,48 +13,64 @@ class RecordPage extends StatefulWidget {
State<StatefulWidget> createState() => _RecordPageState();
}
class _RecordPageState extends State<RecordPage> {
ViewType _selectedViewType = ViewType.recipe;
class _RecordPageState extends State<RecordPage>
with SingleTickerProviderStateMixin {
final List<Recipe> recipeList = [
Recipe("韭菜炒鸡蛋", "家常菜", "2025-05-04", "https://picsum.photos/200", 10, 2, 4),
Recipe("红烧肉", "家常菜", "2025-05-05", "https://picsum.photos/200", 12, 4, 7),
];
late final TabController _tabController = TabController(
length: 3,
vsync: this,
);
@override
void initState() {
super.initState();
}
@override
void dispose() {
_tabController.dispose();
super.dispose();
}
// 定义标签列表
final List<TDTab> tabs = [
const TDTab(text: '菜谱', icon: Icon(Icons.book)),
const TDTab(text: '日历', icon: Icon(Icons.calendar_today)),
const TDTab(text: '时间轴', icon: Icon(Icons.timeline)),
];
@override
Widget build(BuildContext context) {
return Padding(
padding: EdgeInsets.all(10),
padding: EdgeInsets.all(0),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
// crossAxisAlignment: CrossAxisAlignment.start,
children: [
RecipeSegment(
selectedViewType: _selectedViewType,
onViewTypeChanged: (value) {
setState(() {
_selectedViewType = value;
});
},
// 标签栏
TDTabBar(
tabs: tabs,
controller: _tabController,
backgroundColor: Colors.white,
showIndicator: true,
),
Expanded(
child: Padding(
padding: EdgeInsets.all(5),
child: TabBarView(
controller: _tabController,
children: [
RecipeList(recipeList: recipeList),
RecipeCalendar(),
RecipeTimeline(recipeList: recipeList),
],
),
),
),
const SizedBox(height: 10),
const Divider(height: 1),
const SizedBox(height: 10),
// 内容区域
Expanded(child: _buildContent()),
],
),
);
}
Widget _buildContent() {
switch (_selectedViewType) {
case ViewType.recipe:
return RecipeList(recipeList: recipeList);
case ViewType.calendar:
return RecipeCalendar();
case ViewType.timeline:
return RecipeTimeline(recipeList: recipeList);
}
}
}