|
|
|
@ -1,5 +1,8 @@ |
|
|
|
import 'package:flutter/material.dart'; |
|
|
|
import 'package:dating_touchme_app/generated/assets.dart'; |
|
|
|
import 'package:get/get.dart'; |
|
|
|
import 'package:dating_touchme_app/controller/message/friend_controller.dart'; |
|
|
|
import 'package:im_flutter_sdk/im_flutter_sdk.dart'; |
|
|
|
|
|
|
|
class FriendTab extends StatefulWidget { |
|
|
|
const FriendTab({super.key}); |
|
|
|
@ -45,45 +48,45 @@ class _FriendTabState extends State<FriendTab> with TickerProviderStateMixin { |
|
|
|
}, |
|
|
|
]; |
|
|
|
|
|
|
|
// 模拟数据 - 好友列表 |
|
|
|
final List<Map<String, dynamic>> _friendList = [ |
|
|
|
{ |
|
|
|
"id": 1, |
|
|
|
"name": "林园园", |
|
|
|
"avatar": Assets.imagesAvatarsExample, |
|
|
|
"isOnline": true, |
|
|
|
}, |
|
|
|
{ |
|
|
|
"id": 2, |
|
|
|
"name": "李晖", |
|
|
|
"avatar": Assets.imagesAvatarsExample, |
|
|
|
"isOnline": false, |
|
|
|
}, |
|
|
|
{ |
|
|
|
"id": 3, |
|
|
|
"name": "李哲", |
|
|
|
"avatar": Assets.imagesAvatarsExample, |
|
|
|
"isOnline": false, |
|
|
|
}, |
|
|
|
{ |
|
|
|
"id": 4, |
|
|
|
"name": "李夏", |
|
|
|
"avatar": Assets.imagesAvatarsExample, |
|
|
|
"isOnline": true, |
|
|
|
}, |
|
|
|
{ |
|
|
|
"id": 5, |
|
|
|
"name": "张雪", |
|
|
|
"avatar": Assets.imagesAvatarsExample, |
|
|
|
"isOnline": false, |
|
|
|
}, |
|
|
|
{ |
|
|
|
"id": 6, |
|
|
|
"name": "王强", |
|
|
|
"avatar": Assets.imagesAvatarsExample, |
|
|
|
"isOnline": true, |
|
|
|
}, |
|
|
|
]; |
|
|
|
// 模拟数据 - 好友列表(已废弃,现在使用 FriendController 从 IM 获取) |
|
|
|
// final List<Map<String, dynamic>> _friendList = [ |
|
|
|
// { |
|
|
|
// "id": 1, |
|
|
|
// "name": "林园园", |
|
|
|
// "avatar": Assets.imagesAvatarsExample, |
|
|
|
// "isOnline": true, |
|
|
|
// }, |
|
|
|
// { |
|
|
|
// "id": 2, |
|
|
|
// "name": "李晖", |
|
|
|
// "avatar": Assets.imagesAvatarsExample, |
|
|
|
// "isOnline": false, |
|
|
|
// }, |
|
|
|
// { |
|
|
|
// "id": 3, |
|
|
|
// "name": "李哲", |
|
|
|
// "avatar": Assets.imagesAvatarsExample, |
|
|
|
// "isOnline": false, |
|
|
|
// }, |
|
|
|
// { |
|
|
|
// "id": 4, |
|
|
|
// "name": "李夏", |
|
|
|
// "avatar": Assets.imagesAvatarsExample, |
|
|
|
// "isOnline": true, |
|
|
|
// }, |
|
|
|
// { |
|
|
|
// "id": 5, |
|
|
|
// "name": "张雪", |
|
|
|
// "avatar": Assets.imagesAvatarsExample, |
|
|
|
// "isOnline": false, |
|
|
|
// }, |
|
|
|
// { |
|
|
|
// "id": 6, |
|
|
|
// "name": "王强", |
|
|
|
// "avatar": Assets.imagesAvatarsExample, |
|
|
|
// "isOnline": true, |
|
|
|
// }, |
|
|
|
// ]; |
|
|
|
|
|
|
|
// 模拟数据 - 粉丝列表 |
|
|
|
final List<Map<String, dynamic>> _fansList = [ |
|
|
|
@ -301,17 +304,56 @@ class _FriendTabState extends State<FriendTab> with TickerProviderStateMixin { |
|
|
|
|
|
|
|
// 构建好友列表 |
|
|
|
Widget _buildFriendList() { |
|
|
|
return ListView.builder( |
|
|
|
padding: const EdgeInsets.only(top: 8), |
|
|
|
itemCount: _friendList.length, |
|
|
|
itemBuilder: (context, index) { |
|
|
|
final friend = _friendList[index]; |
|
|
|
return _buildFriendItem(friend); |
|
|
|
return GetX<FriendController>( |
|
|
|
init: FriendController(), |
|
|
|
builder: (controller) { |
|
|
|
if (controller.isLoading.value) { |
|
|
|
return const Center( |
|
|
|
child: CircularProgressIndicator(), |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
if (controller.errorMessage.value.isNotEmpty) { |
|
|
|
return Center( |
|
|
|
child: Column( |
|
|
|
mainAxisAlignment: MainAxisAlignment.center, |
|
|
|
children: [ |
|
|
|
Text( |
|
|
|
controller.errorMessage.value, |
|
|
|
style: const TextStyle(color: Colors.grey), |
|
|
|
), |
|
|
|
const SizedBox(height: 16), |
|
|
|
ElevatedButton( |
|
|
|
onPressed: () => controller.refreshFriends(), |
|
|
|
child: const Text('重试'), |
|
|
|
), |
|
|
|
], |
|
|
|
), |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
if (controller.friendList.isEmpty) { |
|
|
|
return const Center( |
|
|
|
child: Text( |
|
|
|
'暂无好友', |
|
|
|
style: TextStyle(color: Colors.grey), |
|
|
|
), |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
return ListView.builder( |
|
|
|
padding: const EdgeInsets.only(top: 8), |
|
|
|
itemCount: controller.friendList.length, |
|
|
|
itemBuilder: (context, index) { |
|
|
|
final contact = controller.friendList[index]; |
|
|
|
return _buildFriendItemFromContact(contact); |
|
|
|
}, |
|
|
|
); |
|
|
|
}, |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
// 构建好友项 |
|
|
|
// 构建好友项(从 Map 数据,保留用于兼容) |
|
|
|
Widget _buildFriendItem(Map<String, dynamic> friend) { |
|
|
|
return Container( |
|
|
|
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 4), |
|
|
|
@ -387,6 +429,68 @@ class _FriendTabState extends State<FriendTab> with TickerProviderStateMixin { |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
// 构建好友项(从 EMContact 数据) |
|
|
|
Widget _buildFriendItemFromContact(EMContact contact) { |
|
|
|
// EMContact 只有 userId,需要通过其他方式获取详细信息 |
|
|
|
// 这里先显示 userId,后续可以通过 getUserInfo 获取详细信息 |
|
|
|
final userId = contact.userId; |
|
|
|
|
|
|
|
return Container( |
|
|
|
margin: const EdgeInsets.symmetric(horizontal: 16, vertical: 4), |
|
|
|
padding: const EdgeInsets.all(12), |
|
|
|
decoration: BoxDecoration( |
|
|
|
color: Colors.white, |
|
|
|
borderRadius: BorderRadius.circular(8), |
|
|
|
), |
|
|
|
child: Row( |
|
|
|
children: [ |
|
|
|
// 头像 |
|
|
|
Container( |
|
|
|
width: 50, |
|
|
|
height: 50, |
|
|
|
decoration: BoxDecoration( |
|
|
|
borderRadius: BorderRadius.circular(25), |
|
|
|
), |
|
|
|
child: ClipRRect( |
|
|
|
borderRadius: BorderRadius.circular(25), |
|
|
|
child: const Icon(Icons.person, size: 30), |
|
|
|
), |
|
|
|
), |
|
|
|
|
|
|
|
// 信息 |
|
|
|
Expanded( |
|
|
|
child: Container( |
|
|
|
margin: const EdgeInsets.only(left: 12), |
|
|
|
child: Column( |
|
|
|
crossAxisAlignment: CrossAxisAlignment.start, |
|
|
|
mainAxisAlignment: MainAxisAlignment.center, |
|
|
|
children: [ |
|
|
|
Text( |
|
|
|
userId, |
|
|
|
style: const TextStyle( |
|
|
|
fontWeight: FontWeight.bold, |
|
|
|
), |
|
|
|
), |
|
|
|
const SizedBox(height: 4), |
|
|
|
Text( |
|
|
|
"ID: $userId", |
|
|
|
style: const TextStyle( |
|
|
|
color: Colors.grey, |
|
|
|
fontSize: 12, |
|
|
|
), |
|
|
|
), |
|
|
|
], |
|
|
|
), |
|
|
|
), |
|
|
|
), |
|
|
|
|
|
|
|
// 箭头图标 |
|
|
|
const Icon(Icons.arrow_forward_ios, size: 16, color: Colors.grey), |
|
|
|
], |
|
|
|
), |
|
|
|
); |
|
|
|
} |
|
|
|
|
|
|
|
// 构建粉丝列表 |
|
|
|
Widget _buildFansList() { |
|
|
|
return ListView.builder( |
|
|
|
|