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.
144 lines
3.6 KiB
144 lines
3.6 KiB
import 'package:flutter/material.dart';
|
|
import 'package:dating_touchme_app/generated/assets.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
import 'package:get/get.dart';
|
|
import 'conversation_tab.dart';
|
|
import 'friend_tab.dart';
|
|
import '../../controller/message/conversation_controller.dart';
|
|
|
|
class MessagePage extends StatefulWidget {
|
|
const MessagePage({super.key});
|
|
|
|
@override
|
|
State<MessagePage> createState() => _MessagePageState();
|
|
}
|
|
|
|
class _MessagePageState extends State<MessagePage> with AutomaticKeepAliveClientMixin, TickerProviderStateMixin {
|
|
late TabController _tabController;
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_tabController = TabController(length: 2, vsync: this);
|
|
// 注册ConversationController
|
|
Get.put(ConversationController());
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
_tabController.dispose();
|
|
super.dispose();
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
super.build(context);
|
|
return Container(
|
|
decoration: BoxDecoration(
|
|
image: DecorationImage(
|
|
image: AssetImage(Assets.imagesBgInformation),
|
|
fit: BoxFit.cover,
|
|
),
|
|
),
|
|
child: Scaffold(
|
|
backgroundColor: Colors.transparent,
|
|
appBar: _buildAppBar(),
|
|
body: _buildTabContent(),
|
|
),
|
|
);
|
|
}
|
|
|
|
// 构建AppBar
|
|
AppBar _buildAppBar() {
|
|
return AppBar(
|
|
backgroundColor: Colors.transparent,
|
|
elevation: 0,
|
|
automaticallyImplyLeading: false,
|
|
centerTitle: true,
|
|
title: Row(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
_buildTabButton(title: '聊天', index: 0),
|
|
const SizedBox(width: 28),
|
|
_buildTabButton(title: '好友', index: 1),
|
|
],
|
|
),
|
|
actions: [
|
|
// 搜索按钮
|
|
GestureDetector(
|
|
onTap: () {
|
|
// 搜索功能
|
|
},
|
|
child: Container(
|
|
width: 36,
|
|
height: 36,
|
|
margin: const EdgeInsets.only(right: 16),
|
|
alignment: Alignment.center,
|
|
child: Image.asset(Assets.imagesSearch, width: 16.w,),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
// 构建标签按钮
|
|
Widget _buildTabButton({required String title, required int index}) {
|
|
final bool isSelected = _tabController.index == index;
|
|
return GestureDetector(
|
|
onTap: () {
|
|
if (_tabController.index != index) {
|
|
_tabController.animateTo(index);
|
|
setState(() {});
|
|
}
|
|
},
|
|
child: _buildTabIndicator(title, isSelected),
|
|
);
|
|
}
|
|
|
|
// 构建标签样式
|
|
Widget _buildTabIndicator(String label, bool isSelected) {
|
|
return Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
children: [
|
|
Text(
|
|
label,
|
|
style: TextStyle(
|
|
fontSize: isSelected ? 19 : 17,
|
|
fontWeight: isSelected ? FontWeight.w700 : FontWeight.w400,
|
|
color: Colors.black,
|
|
),
|
|
),
|
|
const SizedBox(height: 6),
|
|
isSelected
|
|
? Image.asset(
|
|
Assets.imagesTabChangeIcon,
|
|
width: 20,
|
|
)
|
|
: const SizedBox(height: 8),
|
|
],
|
|
);
|
|
}
|
|
|
|
|
|
|
|
// 构建Tab内容区域
|
|
Widget _buildTabContent() {
|
|
return TabBarView(
|
|
controller: _tabController,
|
|
physics: const NeverScrollableScrollPhysics(), // 禁用Tab页手势滚动
|
|
children: const [
|
|
// 聊天Tab
|
|
ConversationTab(),
|
|
// 好友Tab
|
|
FriendTab(),
|
|
],
|
|
);
|
|
}
|
|
|
|
@override
|
|
bool get wantKeepAlive => true;
|
|
}
|