414 lines
16 KiB
Dart
414 lines
16 KiB
Dart
import 'dart:convert';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
import 'package:aslan/app_localizations.dart';
|
|
import 'package:aslan/chatvibe_ui/components/at_debounce_widget.dart';
|
|
import 'package:aslan/chatvibe_ui/components/text/at_text.dart';
|
|
import 'package:aslan/chatvibe_managers/rtm_manager.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:tencent_cloud_chat_sdk/enum/conversation_type.dart';
|
|
import 'package:tencent_cloud_chat_sdk/models/v2_tim_conversation.dart';
|
|
import 'package:tencent_cloud_chat_sdk/models/v2_tim_value_callback.dart';
|
|
import 'package:tencent_cloud_chat_sdk/tencent_im_sdk_plugin.dart';
|
|
import 'package:aslan/chatvibe_core/constants/at_global_config.dart';
|
|
import 'package:aslan/chatvibe_core/config/business_logic_strategy.dart';
|
|
import 'package:aslan/chatvibe_core/routes/at_fluro_navigator.dart';
|
|
import 'package:aslan/chatvibe_data/sources/local/data_persistence.dart';
|
|
import 'package:aslan/chatvibe_data/sources/local/user_manager.dart';
|
|
import 'package:aslan/chatvibe_ui/widgets/msg/message_conversation_list_page.dart';
|
|
import 'package:aslan/chatvibe_features/chat/at_chat_route.dart';
|
|
import 'package:aslan/chatvibe_features/chat/message/at_message_friends_page.dart';
|
|
|
|
import '../../index/main_route.dart';
|
|
|
|
///消息
|
|
class ATMessagePage extends StatefulWidget {
|
|
bool isFromRoom = false;
|
|
|
|
ATMessagePage({this.isFromRoom = false});
|
|
|
|
@override
|
|
_MessagePageState createState() => _MessagePageState(isFromRoom);
|
|
}
|
|
|
|
class _MessagePageState extends State<ATMessagePage> {
|
|
BusinessLogicStrategy get _strategy => ATGlobalConfig.businessLogicStrategy;
|
|
bool isFromRoom = false;
|
|
bool showSystemAnnouncementTips = true;
|
|
|
|
_MessagePageState(this.isFromRoom);
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
showSystemAnnouncementTips = DataPersistence.getBool(
|
|
"${AccountStorage().getCurrentUser()?.userProfile?.account}-ShowSystemAnnouncementTips",
|
|
defaultValue: true,
|
|
);
|
|
_checkLogin();
|
|
}
|
|
|
|
void _checkLogin() async {
|
|
V2TimValueCallback<int> getLoginStatusRes =
|
|
await TencentImSDKPlugin.v2TIMManager.getLoginStatus();
|
|
if (getLoginStatusRes.code == 0) {
|
|
var status = getLoginStatusRes.data; // getLoginStatusRes.data为用户登录状态值
|
|
if (status == 1) {
|
|
// 已登录
|
|
///处理有时候拉不到最后一条消息
|
|
Provider.of<RtmProvider>(
|
|
context,
|
|
listen: false,
|
|
).initConversation().then((value) {
|
|
Future.delayed(Duration(milliseconds: 550), () {
|
|
Provider.of<RtmProvider>(
|
|
context,
|
|
listen: false,
|
|
).initConversation().then((value) {
|
|
setState(() {});
|
|
});
|
|
});
|
|
});
|
|
} else if (status == 2) {
|
|
// 登录中
|
|
} else if (status == 3) {
|
|
// 未登录
|
|
Provider.of<RtmProvider>(
|
|
context,
|
|
listen: false,
|
|
).loginTencetRtm(context).then((value) {
|
|
_checkLogin();
|
|
});
|
|
}
|
|
setState(() {});
|
|
}
|
|
}
|
|
|
|
@override
|
|
void dispose() {
|
|
super.dispose();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return Stack(
|
|
children: [
|
|
widget.isFromRoom
|
|
? Image.asset(
|
|
_strategy.getMessagePageIndexMaskIcon(),
|
|
width: ScreenUtil().screenWidth,
|
|
fit: BoxFit.cover,
|
|
)
|
|
: Container(),
|
|
DefaultTabController(
|
|
length: 2,
|
|
child: Scaffold(
|
|
backgroundColor: Colors.transparent,
|
|
appBar: AppBar(
|
|
backgroundColor: Colors.transparent,
|
|
title: TabBar(
|
|
tabs:
|
|
[
|
|
ATAppLocalizations.of(context)!.message,
|
|
]
|
|
.map(
|
|
(e) => Padding(
|
|
padding: EdgeInsets.only(bottom: 3.w, top: 4.w),
|
|
child: Text(e),
|
|
),
|
|
)
|
|
.toList(),
|
|
dividerColor: Colors.transparent,
|
|
labelStyle: TextStyle(
|
|
fontSize: 16.sp,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
unselectedLabelStyle: TextStyle(
|
|
fontSize: 15.sp,
|
|
color: Color.fromRGBO(66, 12, 40, 0.40),
|
|
fontWeight: FontWeight.normal,
|
|
),
|
|
indicator: BoxDecoration(),
|
|
//TabBarIndicator(),
|
|
isScrollable: false,
|
|
labelColor: Colors.black,
|
|
unselectedLabelColor: Color.fromRGBO(66, 12, 40, 0.40),
|
|
tabAlignment: TabAlignment.center,
|
|
),
|
|
actions: [
|
|
ATDebounceWidget(
|
|
child: Container(
|
|
padding: EdgeInsetsDirectional.only(end: 10.w),
|
|
child: Image.asset(
|
|
"atu_images/index/at_icon_serach.png",
|
|
width: 20.w,
|
|
height: 20.w,
|
|
),
|
|
),
|
|
onTap: () {
|
|
ATNavigatorUtils.push(context, MainRoute.mainSearch);
|
|
},
|
|
),
|
|
],
|
|
leading: Container(),
|
|
),
|
|
body: TabBarView(
|
|
children: [
|
|
Consumer<RtmProvider>(
|
|
builder: (_, provider, __) {
|
|
return Column(
|
|
children: [
|
|
_headMenu(provider),
|
|
Expanded(
|
|
child: Container(
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
borderRadius: BorderRadius.only(
|
|
topLeft: Radius.circular(8.w),
|
|
topRight: Radius.circular(8.w),
|
|
),
|
|
),
|
|
margin: EdgeInsets.only(
|
|
top: 10.w,
|
|
left: 8.w,
|
|
right: 8.w,
|
|
),
|
|
child: MessageConversationListPage(false),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
},
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
}
|
|
|
|
Widget _headMenu(RtmProvider provider) {
|
|
return Container(
|
|
height: 92.w,
|
|
margin: EdgeInsets.only(top: 15.w, bottom: 0.w, left: 8.w, right: 8.w),
|
|
padding: EdgeInsets.symmetric(horizontal: 6.w, vertical: 6.w),
|
|
decoration: BoxDecoration(
|
|
color: Colors.white,
|
|
borderRadius: BorderRadius.circular(8),
|
|
),
|
|
child: Row(
|
|
mainAxisSize: MainAxisSize.max,
|
|
children: [
|
|
Expanded(
|
|
child: ATDebounceWidget(
|
|
child:
|
|
provider.activityUnReadCount > 0
|
|
? Badge(
|
|
backgroundColor: Colors.red,
|
|
label: text(
|
|
"${provider.activityUnReadCount > 99 ? "99+" : provider.activityUnReadCount}",
|
|
fontSize: 9.sp,
|
|
textColor: Colors.white,
|
|
fontWeight: FontWeight.w600,
|
|
),
|
|
alignment: AlignmentDirectional.topEnd,
|
|
offset: Offset(
|
|
ATGlobalConfig.lang == "ar" ? 5 : -15,
|
|
0,
|
|
),
|
|
child: Container(
|
|
alignment: Alignment.center,
|
|
child: Column(
|
|
children: [
|
|
SizedBox(height: 3.w),
|
|
Image.asset(
|
|
_strategy.getMessagePageActivityMessageIcon(),
|
|
width: 56.w,
|
|
height: 56.w,
|
|
),
|
|
text(
|
|
ATAppLocalizations.of(context)!.activity,
|
|
textColor: Colors.black,
|
|
fontSize: 12.sp,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
)
|
|
: Container(
|
|
alignment: Alignment.center,
|
|
child: Column(
|
|
children: [
|
|
SizedBox(height: 3.w),
|
|
Image.asset(
|
|
_strategy.getMessagePageActivityMessageIcon(),
|
|
width: 56.w,
|
|
height: 56.w,
|
|
),
|
|
text(
|
|
ATAppLocalizations.of(context)!.activity,
|
|
textColor: Colors.black,
|
|
fontSize: 12.sp,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
onTap: () {
|
|
provider.updateActivityCount(0);
|
|
ATNavigatorUtils.push(
|
|
context,
|
|
ATChatRouter.activity,
|
|
replace: false,
|
|
);
|
|
},
|
|
),
|
|
),
|
|
Expanded(
|
|
child: ATDebounceWidget(
|
|
child:
|
|
provider.systemUnReadCount > 0
|
|
? Badge(
|
|
backgroundColor: Colors.red,
|
|
label: text(
|
|
"${provider.systemUnReadCount > 99 ? "99+" : provider.systemUnReadCount}",
|
|
fontSize: 9.sp,
|
|
textColor: Colors.white,
|
|
fontWeight: FontWeight.w600,
|
|
),
|
|
alignment: AlignmentDirectional.topEnd,
|
|
offset: Offset(
|
|
ATGlobalConfig.lang == "ar" ? 5 : -15,
|
|
0,
|
|
),
|
|
child: Container(
|
|
alignment: Alignment.center,
|
|
child: Column(
|
|
children: [
|
|
SizedBox(height: 3.w),
|
|
Image.asset(
|
|
_strategy.getMessagePageSystemMessageIcon(),
|
|
width: 56.w,
|
|
height: 56.w,
|
|
),
|
|
text(
|
|
ATAppLocalizations.of(context)!.system,
|
|
textColor: Colors.black,
|
|
fontSize: 12.sp,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
)
|
|
: Container(
|
|
alignment: Alignment.center,
|
|
child: Column(
|
|
children: [
|
|
SizedBox(height: 3.w),
|
|
Image.asset(
|
|
_strategy.getMessagePageSystemMessageIcon(),
|
|
width: 56.w,
|
|
height: 56.w,
|
|
),
|
|
text(
|
|
ATAppLocalizations.of(context)!.system,
|
|
textColor: Colors.black,
|
|
fontSize: 12.sp,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
onTap: () async {
|
|
var conversation = V2TimConversation(
|
|
type: ConversationType.V2TIM_C2C,
|
|
userID: "atyou-admin",
|
|
conversationID: ATGlobalConfig.imAdmin,
|
|
);
|
|
provider.updateSystemCount(0);
|
|
var bool = await provider.startConversation(conversation);
|
|
if (!bool) return;
|
|
var json = jsonEncode(conversation.toJson());
|
|
ATNavigatorUtils.push(
|
|
context,
|
|
"${ATChatRouter.systemChat}?conversation=${Uri.encodeComponent(json)}",
|
|
);
|
|
},
|
|
),
|
|
),
|
|
Expanded(
|
|
child: ATDebounceWidget(
|
|
child:
|
|
provider.notifcationUnReadCount > 0
|
|
? Badge(
|
|
backgroundColor: Colors.red,
|
|
label: text(
|
|
"${provider.notifcationUnReadCount > 99 ? "99+" : provider.notifcationUnReadCount}",
|
|
fontSize: 9.sp,
|
|
textColor: Colors.white,
|
|
fontWeight: FontWeight.w600,
|
|
),
|
|
offset: Offset(
|
|
ATGlobalConfig.lang == "ar" ? -2 : -8,
|
|
0,
|
|
),
|
|
alignment: AlignmentDirectional.topEnd,
|
|
child: Container(
|
|
alignment: Alignment.center,
|
|
child: Column(
|
|
children: [
|
|
SizedBox(height: 3.w),
|
|
Image.asset(
|
|
_strategy
|
|
.getMessagePageNotificationMessageIcon(),
|
|
width: 56.w,
|
|
height: 56.w,
|
|
),
|
|
text(
|
|
ATAppLocalizations.of(context)!.notifcation,
|
|
textColor: Colors.black,
|
|
fontSize: 12.sp,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
)
|
|
: Container(
|
|
alignment: Alignment.center,
|
|
child: Column(
|
|
children: [
|
|
SizedBox(height: 3.w),
|
|
Image.asset(
|
|
_strategy.getMessagePageNotificationMessageIcon(),
|
|
width: 56.w,
|
|
height: 56.w,
|
|
),
|
|
text(
|
|
ATAppLocalizations.of(context)!.notifcation,
|
|
textColor: Colors.black,
|
|
fontSize: 12.sp,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
onTap: () {
|
|
provider.updateNotificationCount(0);
|
|
ATNavigatorUtils.push(
|
|
context,
|
|
ATChatRouter.notifcation,
|
|
replace: false,
|
|
);
|
|
},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|