import 'package:flutter/material.dart'; import 'package:food_hub_app/api/recipe.dart'; import 'package:food_hub_app/models/recipe.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_timeline.dart'; import 'package:tdesign_flutter/tdesign_flutter.dart'; class RecordPage extends StatefulWidget { const RecordPage({super.key}); @override State createState() => _RecordPageState(); } class _RecordPageState extends State with SingleTickerProviderStateMixin { List _recipeList = []; final List _recordList = []; late final TabController _tabController = TabController( length: 3, vsync: this, ); final List tabs = [ const TDTab(text: '菜谱', icon: Icon(Icons.book)), const TDTab(text: '日历', icon: Icon(Icons.calendar_month)), const TDTab(text: '时间轴', icon: Icon(Icons.timeline)), ]; @override void initState() { super.initState(); _getRecipeList(); _tabController.addListener(_handleTabChange); } @override void dispose() { _tabController.removeListener(_handleTabChange); _tabController.dispose(); super.dispose(); } void _handleTabChange() { if (_tabController.indexIsChanging) { return; } // 根据当前选中的索引执行对应接口请求 switch (_tabController.index) { case 0: _getRecipeList(); break; case 1: print("2"); break; case 2: print("3"); break; } } Future _getRecipeList() async { final result = await queryRecipeApi(RecipeQuery(category: "")); setState(() { _recipeList = result; }); } @override Widget build(BuildContext context) { return Padding( padding: EdgeInsets.all(0), child: Column( children: [ 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(recordList: _recordList), ], ), ), ), ], ), ); } }