You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

89 lines
2.7 KiB

import 'package:dating_touchme_app/controller/home/home_controller.dart';
import 'package:dating_touchme_app/pages/home/all_timeline.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:tdesign_flutter/tdesign_flutter.dart';
class TimelineWindow extends StatefulWidget {
const TimelineWindow({super.key});
@override
State<TimelineWindow> createState() => _TimelineWindowState();
}
class _TimelineWindowState extends State<TimelineWindow> with AutomaticKeepAliveClientMixin, SingleTickerProviderStateMixin {
late TabController tabController;
final HomeController controller = Get.find<HomeController>();
@override
void initState() {
super.initState();
tabController = TabController(length: 2, vsync: this);
}
@override
Widget build(BuildContext context) {
super.build(context);
return Column(
children: [
TDTabBar(
tabs: [
TDTab(
child: Padding(
padding: EdgeInsets.only(right: 16, left: 16),
child: Text('全部'),
),
),
TDTab(
child: Padding(
padding: EdgeInsets.only(right: 16, left: 16),
child: Text('好友动态'),
),
),
],
backgroundColor: Colors.transparent,
labelPadding: const EdgeInsets.only(right: 4, top: 10, bottom: 10, left: 4),
selectedBgColor: const Color.fromRGBO(108, 105, 244, 1),
unSelectedBgColor: Colors.transparent,
labelColor: Colors.white,
dividerHeight: 0,
tabAlignment: TabAlignment.start,
outlineType: TDTabBarOutlineType.capsule,
controller: tabController,
showIndicator: false,
isScrollable: true,
onTap: (index) async {
print('相亲页面 Tab: $index');
if (controller.timelineTab.value != index) {
controller.setTimelineTab(index);
// 确保状态更新后刷新UI
controller.update();
}
},
),
Expanded(
child: Obx(() {
// 使用 IndexedStack 保持两个列表的状态,根据当前选中的标签显示对应的列表
return IndexedStack(
index: controller.timelineTab.value,
children: const [
// 推荐列表
AllTimeline(),
// 同城列表
SizedBox(),
],
);
}),
),
],
);
}
@override
bool get wantKeepAlive => true;
}