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.
163 lines
5.0 KiB
163 lines
5.0 KiB
import 'package:dating_touchme_app/controller/home/timeline_controller.dart';
|
|
import 'package:dating_touchme_app/extension/ex_widget.dart';
|
|
import 'package:dating_touchme_app/generated/assets.dart';
|
|
import 'package:dating_touchme_app/pages/home/recommend_window.dart';
|
|
import 'package:dating_touchme_app/pages/home/send_timeline.dart';
|
|
import 'package:dating_touchme_app/pages/home/timeline_trend.dart';
|
|
import 'package:dating_touchme_app/pages/home/timeline_window.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:dating_touchme_app/controller/home/home_controller.dart';
|
|
import 'package:dating_touchme_app/pages/home/recommend_tab.dart';
|
|
import 'package:dating_touchme_app/pages/home/nearby_tab.dart';
|
|
|
|
class TimelinePage extends StatefulWidget {
|
|
const TimelinePage({super.key});
|
|
|
|
@override
|
|
State<TimelinePage> createState() => _TimelinePageState();
|
|
}
|
|
|
|
class _TimelinePageState extends State<TimelinePage>
|
|
with AutomaticKeepAliveClientMixin {
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
// 确保 HomeController 已注册
|
|
if (!Get.isRegistered<TimelineController>()) {
|
|
Get.put(TimelineController());
|
|
}
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
super.build(context);
|
|
return GetBuilder<TimelineController>(
|
|
builder: (controller) {
|
|
return Stack(
|
|
children: [
|
|
Positioned.fill(
|
|
child: Container(
|
|
color: Colors.white,
|
|
),
|
|
),
|
|
// 背景图 - 覆盖整个屏幕包括状态栏和导航栏
|
|
Image.asset(
|
|
Assets.imagesBgInformation,
|
|
fit: BoxFit.cover,
|
|
width: double.infinity,
|
|
height: double.infinity,
|
|
),
|
|
Scaffold(
|
|
backgroundColor: Colors.transparent,
|
|
appBar: _buildAppBar(controller),
|
|
body: Stack(
|
|
children: [
|
|
Obx(() {
|
|
// 使用 IndexedStack 保持两个列表的状态,根据当前选中的标签显示对应的列表
|
|
return IndexedStack(
|
|
index: controller.topTab.value,
|
|
children: [
|
|
// // 推荐列表
|
|
// RecommendWindow(),
|
|
// 同城列表
|
|
const TimelineWindow(),
|
|
Container()
|
|
],
|
|
);
|
|
}),
|
|
Positioned(
|
|
bottom: 44.w,
|
|
right: 3.w,
|
|
child: Image.asset(
|
|
Assets.imagesPublish,
|
|
width: 60.w,
|
|
).onTap((){
|
|
Get.to(() => SendTimeline());
|
|
}),
|
|
)
|
|
],
|
|
),
|
|
),
|
|
],
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
PreferredSizeWidget _buildAppBar(TimelineController controller) {
|
|
return AppBar(
|
|
backgroundColor: Colors.transparent,
|
|
elevation: 0,
|
|
centerTitle: true,
|
|
toolbarHeight: 56,
|
|
titleSpacing: 0,
|
|
title: Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
// _buildTabButton(title: '推荐', index: 0, controller: controller),
|
|
// const SizedBox(width: 28),
|
|
_buildTabButton(title: '广场', index: 0, controller: controller),
|
|
],
|
|
),
|
|
bottom: const PreferredSize(
|
|
preferredSize: Size.fromHeight(4),
|
|
child: SizedBox(height: 4),
|
|
),
|
|
actions: [
|
|
Container(
|
|
margin: EdgeInsets.only(right: 15),
|
|
child: Icon(
|
|
Icons.email_outlined,
|
|
size: 19,
|
|
),
|
|
).onTap((){
|
|
Get.to(() => TimelineTrend());
|
|
})
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget _buildTabButton({
|
|
required String title,
|
|
required int index,
|
|
required TimelineController controller,
|
|
}) {
|
|
final bool selected = controller.topTab.value == index;
|
|
return GestureDetector(
|
|
onTap: () {
|
|
print('Tab $index clicked');
|
|
if (controller.topTab.value != index) {
|
|
controller.setTopTab(index);
|
|
// 确保状态更新后刷新UI
|
|
controller.update();
|
|
}
|
|
},
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: [
|
|
Text(
|
|
title,
|
|
style: TextStyle(
|
|
fontSize: selected ? 19 : 17,
|
|
fontWeight: selected ? FontWeight.w700 : FontWeight.w400,
|
|
color: selected
|
|
? const Color(0xFF333333)
|
|
: const Color(0xFF999999),
|
|
),
|
|
),
|
|
const SizedBox(height: 6),
|
|
selected
|
|
? Image.asset(Assets.imagesTabChangeIcon, width: 32, height: 8)
|
|
: const SizedBox(height: 8),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
@override
|
|
bool get wantKeepAlive => true;
|
|
}
|