2025-09-22 14:41:47 +08:00
|
|
|
|
/// 新关注通知
|
2025-09-17 15:32:18 +08:00
|
|
|
|
library;
|
|
|
|
|
|
2025-09-22 14:41:47 +08:00
|
|
|
|
import 'dart:convert';
|
|
|
|
|
|
2025-09-17 15:32:18 +08:00
|
|
|
|
import 'package:easy_refresh/easy_refresh.dart';
|
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:get/get.dart';
|
|
|
|
|
import 'package:loopin/IM/im_service.dart';
|
2025-09-22 14:41:47 +08:00
|
|
|
|
import 'package:loopin/api/video_api.dart';
|
2025-09-17 15:32:18 +08:00
|
|
|
|
import 'package:loopin/behavior/custom_scroll_behavior.dart';
|
2025-09-22 14:41:47 +08:00
|
|
|
|
import 'package:loopin/components/empty_tip.dart';
|
2025-09-17 15:32:18 +08:00
|
|
|
|
import 'package:loopin/components/network_or_asset_image.dart';
|
2025-09-22 14:41:47 +08:00
|
|
|
|
import 'package:loopin/models/conversation_type.dart';
|
|
|
|
|
import 'package:loopin/service/http.dart';
|
2025-09-17 15:32:18 +08:00
|
|
|
|
import 'package:loopin/styles/index.dart';
|
|
|
|
|
import 'package:loopin/utils/index.dart';
|
|
|
|
|
import 'package:tencent_cloud_chat_sdk/models/v2_tim_conversation.dart';
|
2025-09-22 14:41:47 +08:00
|
|
|
|
import 'package:tencent_cloud_chat_sdk/models/v2_tim_custom_elem.dart';
|
|
|
|
|
import 'package:tencent_cloud_chat_sdk/models/v2_tim_message.dart';
|
2025-09-17 15:32:18 +08:00
|
|
|
|
|
2025-09-22 14:41:47 +08:00
|
|
|
|
// newFocus, 新的关注
|
2025-09-17 15:32:18 +08:00
|
|
|
|
|
2025-09-22 14:41:47 +08:00
|
|
|
|
class Newfoucs extends StatefulWidget {
|
|
|
|
|
const Newfoucs({super.key});
|
2025-09-17 15:32:18 +08:00
|
|
|
|
|
|
|
|
|
@override
|
2025-09-22 14:41:47 +08:00
|
|
|
|
State<Newfoucs> createState() => NewfoucsState();
|
2025-09-17 15:32:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-09-22 14:41:47 +08:00
|
|
|
|
class NewfoucsState extends State<Newfoucs> with SingleTickerProviderStateMixin {
|
2025-09-17 15:32:18 +08:00
|
|
|
|
bool isLoading = false; // 是否在加载中
|
2025-09-22 14:41:47 +08:00
|
|
|
|
RxBool hasMore = true.obs; // 是否还有更多数据
|
2025-09-17 15:32:18 +08:00
|
|
|
|
String page = '';
|
|
|
|
|
|
|
|
|
|
///-------------------
|
2025-09-22 14:41:47 +08:00
|
|
|
|
V2TimConversation? conv;
|
|
|
|
|
RxList<V2TimMessage> msgList = <V2TimMessage>[].obs;
|
2025-09-17 15:32:18 +08:00
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
2025-09-22 14:41:47 +08:00
|
|
|
|
if (Get.arguments != null && Get.arguments is V2TimConversation) {
|
|
|
|
|
// 如果有参数
|
|
|
|
|
conv = Get.arguments as V2TimConversation;
|
|
|
|
|
logger.e('lastmsg:$conv');
|
|
|
|
|
|
|
|
|
|
final lastmsg = conv?.lastMessage;
|
|
|
|
|
if (lastmsg != null) {
|
|
|
|
|
msgList.add(lastmsg);
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-09-17 15:32:18 +08:00
|
|
|
|
}
|
|
|
|
|
|
2025-09-22 14:41:47 +08:00
|
|
|
|
// 分页获取全部数据
|
|
|
|
|
Future<void> getMsgData() async {
|
|
|
|
|
// 获取最旧一条消息作为游标
|
|
|
|
|
V2TimMessage? lastRealMsg;
|
|
|
|
|
lastRealMsg = msgList.last;
|
|
|
|
|
final res = await ImService.instance.getHistoryMessageList(
|
|
|
|
|
userID: ConversationType.newFocus.name, // userID为固定的newFocus
|
|
|
|
|
lastMsg: lastRealMsg,
|
2025-09-17 15:32:18 +08:00
|
|
|
|
);
|
|
|
|
|
if (res.success && res.data != null) {
|
2025-09-22 14:41:47 +08:00
|
|
|
|
msgList.addAll(res.data!);
|
|
|
|
|
logger.e(msgList);
|
|
|
|
|
if (res.data!.isEmpty) {
|
|
|
|
|
hasMore.value = false;
|
2025-09-17 15:32:18 +08:00
|
|
|
|
}
|
2025-09-22 14:41:47 +08:00
|
|
|
|
logger.i('聊天数据加载成功');
|
2025-09-17 15:32:18 +08:00
|
|
|
|
} else {
|
2025-09-22 14:41:47 +08:00
|
|
|
|
logger.e('聊天数据加载失败:${res.desc}');
|
2025-09-17 15:32:18 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 下拉刷新
|
|
|
|
|
Future<void> handleRefresh() async {
|
2025-09-22 14:41:47 +08:00
|
|
|
|
await Future.delayed(Duration(seconds: 5));
|
2025-09-17 15:32:18 +08:00
|
|
|
|
setState(() {});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
|
return Scaffold(
|
|
|
|
|
backgroundColor: Colors.grey[50],
|
|
|
|
|
appBar: AppBar(
|
|
|
|
|
centerTitle: true,
|
|
|
|
|
forceMaterialTransparency: true,
|
|
|
|
|
bottom: PreferredSize(
|
2025-09-22 14:41:47 +08:00
|
|
|
|
preferredSize: Size.fromHeight(1.0),
|
2025-09-17 15:32:18 +08:00
|
|
|
|
child: Container(
|
|
|
|
|
color: Colors.grey[300],
|
|
|
|
|
height: 1.0,
|
|
|
|
|
),
|
|
|
|
|
),
|
2025-09-22 14:41:47 +08:00
|
|
|
|
title: Container(
|
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
|
|
|
|
|
child: Row(
|
|
|
|
|
mainAxisSize: MainAxisSize.min,
|
|
|
|
|
children: [
|
|
|
|
|
const SizedBox(width: 4),
|
|
|
|
|
Text(
|
|
|
|
|
'新的关注',
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
color: Colors.black,
|
|
|
|
|
fontSize: 16,
|
|
|
|
|
fontWeight: FontWeight.bold,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
2025-09-17 15:32:18 +08:00
|
|
|
|
),
|
|
|
|
|
actions: [],
|
|
|
|
|
),
|
|
|
|
|
body: ScrollConfiguration(
|
|
|
|
|
behavior: CustomScrollBehavior().copyWith(scrollbars: false),
|
|
|
|
|
child: Column(
|
|
|
|
|
children: [
|
|
|
|
|
Expanded(
|
|
|
|
|
child: EasyRefresh.builder(
|
|
|
|
|
callLoadOverOffset: 20, //触底距离
|
|
|
|
|
callRefreshOverOffset: 20, // 下拉距离
|
|
|
|
|
header: ClassicHeader(
|
|
|
|
|
dragText: '下拉刷新',
|
|
|
|
|
armedText: '释放刷新',
|
|
|
|
|
readyText: '加载中...',
|
|
|
|
|
processingText: '加载中...',
|
|
|
|
|
processedText: '加载完成',
|
|
|
|
|
failedText: '加载失败,请重试',
|
|
|
|
|
messageText: '最后更新于 %T',
|
|
|
|
|
),
|
|
|
|
|
footer: ClassicFooter(
|
|
|
|
|
dragText: '加载更多',
|
|
|
|
|
armedText: '释放加载',
|
|
|
|
|
readyText: '加载中...',
|
|
|
|
|
processingText: '加载中...',
|
2025-09-22 14:41:47 +08:00
|
|
|
|
processedText: '加载完成',
|
|
|
|
|
noMoreText: '没有更多了~',
|
2025-09-17 15:32:18 +08:00
|
|
|
|
failedText: '加载失败,请重试',
|
|
|
|
|
messageText: '最后更新于 %T',
|
|
|
|
|
),
|
|
|
|
|
onRefresh: () async {
|
|
|
|
|
await handleRefresh();
|
|
|
|
|
},
|
|
|
|
|
onLoad: () async {
|
2025-09-22 14:41:47 +08:00
|
|
|
|
if (hasMore.value) {
|
|
|
|
|
await getMsgData();
|
|
|
|
|
return hasMore.value ? IndicatorResult.success : IndicatorResult.noMore;
|
2025-09-17 15:32:18 +08:00
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
childBuilder: (context, physics) {
|
2025-09-22 14:41:47 +08:00
|
|
|
|
return Obx(
|
|
|
|
|
() {
|
|
|
|
|
if (msgList.isEmpty) return EmptyTip();
|
|
|
|
|
|
|
|
|
|
return ListView.builder(
|
|
|
|
|
shrinkWrap: true,
|
|
|
|
|
physics: physics,
|
|
|
|
|
itemCount: msgList.length,
|
|
|
|
|
itemBuilder: (context, index) {
|
|
|
|
|
//检测cloudCustomData
|
|
|
|
|
///发起关注人的[userID],
|
|
|
|
|
///发起关注人的昵称[nickName],
|
|
|
|
|
///发起关注人的头像地址[faceUrl],
|
|
|
|
|
|
|
|
|
|
//----正式数据
|
|
|
|
|
V2TimMessage msg = msgList[index];
|
|
|
|
|
V2TimCustomElem element = msgList[index].customElem!;
|
|
|
|
|
final cloudCustomData = msgList[index].cloudCustomData;
|
|
|
|
|
logger.w(cloudCustomData);
|
|
|
|
|
final desc = msgList[index].customElem!.desc!;
|
|
|
|
|
String? jsonData = msgList[index].customElem!.data;
|
|
|
|
|
jsonData = (jsonData == null || jsonData.isEmpty) ? '{"faceUrl":"","nickName":"data为空","userID":"213213"}' : jsonData;
|
|
|
|
|
|
|
|
|
|
final item = jsonDecode(jsonData ?? '{"faceUrl":"","nickName":"测试昵称","userID":"213213"}');
|
|
|
|
|
|
|
|
|
|
logger.w(element.toJson());
|
|
|
|
|
|
|
|
|
|
// ----测试数据
|
|
|
|
|
// final jsonData = '{"faceUrl":"","nickName":"测试昵称","userID":"213213"}';
|
|
|
|
|
// final item = jsonDecode(jsonData); // 数据
|
|
|
|
|
// final desc = '测试desc';
|
|
|
|
|
// final cloudCustomData = 'newFocus';
|
|
|
|
|
// V2TimCustomElem msg = V2TimMessage(elemType: 2, isRead: index > 2 ? true : false);
|
|
|
|
|
// -----------
|
|
|
|
|
return Container(
|
|
|
|
|
width: double.infinity,
|
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 15.0, vertical: 10.0),
|
|
|
|
|
child: Row(
|
|
|
|
|
spacing: 10.0,
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
// 头像
|
|
|
|
|
InkWell(
|
|
|
|
|
onTap: () async {
|
|
|
|
|
// 点击头像转到对方主页
|
|
|
|
|
// 先获取视频详情
|
|
|
|
|
// 如果cloudCustomData是interactionComment,interactionAt,interactionReply,传参时带上评论id,
|
|
|
|
|
//
|
|
|
|
|
final res = await Http.get('${VideoApi.detail}/${item['vlogID']}');
|
|
|
|
|
Get.toNamed('/vloger', arguments: res['data']);
|
|
|
|
|
// Get.toNamed('/vloger');
|
2025-09-17 15:32:18 +08:00
|
|
|
|
},
|
2025-09-22 14:41:47 +08:00
|
|
|
|
child: ClipOval(
|
|
|
|
|
child: NetworkOrAssetImage(
|
|
|
|
|
imageUrl: item['faceUrl'],
|
|
|
|
|
width: 50,
|
|
|
|
|
height: 50,
|
|
|
|
|
),
|
2025-09-17 15:32:18 +08:00
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
|
2025-09-22 14:41:47 +08:00
|
|
|
|
// 消息
|
|
|
|
|
Expanded(
|
|
|
|
|
child: InkWell(
|
|
|
|
|
onTap: () async {
|
|
|
|
|
// 点击头像转到对方主页,先获取视频详情
|
|
|
|
|
final res = await Http.get('${VideoApi.detail}/${item['vlogID']}');
|
|
|
|
|
Get.toNamed('/vloger', arguments: res['data']);
|
|
|
|
|
// Get.toNamed('/vloger');
|
|
|
|
|
},
|
|
|
|
|
child: Column(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
// 昵称
|
|
|
|
|
Text(
|
|
|
|
|
item['nickName'] ?? '未知',
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
fontSize: 16,
|
|
|
|
|
fontWeight: FontWeight.normal,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(height: 2.0),
|
|
|
|
|
// 描述内容
|
|
|
|
|
Text(
|
|
|
|
|
maxLines: 2,
|
|
|
|
|
overflow: TextOverflow.ellipsis,
|
|
|
|
|
style: const TextStyle(color: Colors.grey, fontSize: 12.0),
|
|
|
|
|
desc,
|
|
|
|
|
// '很长文本内容很长文本内容很长文本内容很长文本内容很长文本内容很长文本内容很长文本内容很长文本内容很长文本内容很长文本内容很长文本内容很长文本内容很长文本内容很长文本内容很长文本内容很长文本内容很长文本内容很长文本内容',
|
|
|
|
|
),
|
|
|
|
|
Text(
|
|
|
|
|
Utils.formatTime(msg.timestamp ?? DateTime.now().millisecondsSinceEpoch ~/ 1000),
|
|
|
|
|
style: TextStyle(
|
|
|
|
|
color: Colors.grey[600],
|
|
|
|
|
fontSize: 12,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
2025-09-17 15:32:18 +08:00
|
|
|
|
),
|
|
|
|
|
),
|
2025-09-22 14:41:47 +08:00
|
|
|
|
|
|
|
|
|
// 右侧
|
|
|
|
|
Row(
|
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
|
children: <Widget>[
|
|
|
|
|
Visibility(
|
|
|
|
|
visible: false, // 新的关注不需要
|
|
|
|
|
// 视频首图
|
|
|
|
|
child: NetworkOrAssetImage(
|
|
|
|
|
imageUrl: item['firstFrameImg'],
|
|
|
|
|
placeholderAsset: 'assets/images/bk.jpg',
|
|
|
|
|
width: 40,
|
|
|
|
|
height: 60,
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
const SizedBox(width: 5.0),
|
|
|
|
|
// 角标
|
|
|
|
|
Visibility(
|
|
|
|
|
visible: !(msg.isRead ?? true),
|
|
|
|
|
child: FStyle.badge(0, isdot: true),
|
|
|
|
|
),
|
|
|
|
|
],
|
2025-09-17 15:32:18 +08:00
|
|
|
|
),
|
2025-09-22 14:41:47 +08:00
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
},
|
2025-09-17 15:32:18 +08:00
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
);
|
|
|
|
|
},
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
],
|
|
|
|
|
),
|
|
|
|
|
),
|
|
|
|
|
);
|
|
|
|
|
}
|
|
|
|
|
}
|