会话加好友

This commit is contained in:
2022-10-25 16:50:48 +08:00
parent b8242e66bd
commit 7c5201ea2b
16 changed files with 128 additions and 51 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 12 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 51 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 59 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 39 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 13 KiB

View File

@@ -5,6 +5,8 @@ import 'package:chat/views/contact/firend/recommend/friend_page.dart';
import 'package:chat/views/contact/firend/recommend/group_page.dart'; import 'package:chat/views/contact/firend/recommend/group_page.dart';
import 'package:chat/views/contact/firend/recommend/index_page.dart'; import 'package:chat/views/contact/firend/recommend/index_page.dart';
import 'package:chat/views/contact/firend/remark/index_page.dart'; import 'package:chat/views/contact/firend/remark/index_page.dart';
import 'package:chat/views/contact/firend/request/apply_page.dart';
import 'package:chat/views/contact/firend/request/index_page.dart';
import 'package:chat/views/contact/firend/search/index_page.dart'; import 'package:chat/views/contact/firend/search/index_page.dart';
import 'package:chat/views/contact/group/create/index_page.dart'; import 'package:chat/views/contact/group/create/index_page.dart';
import 'package:chat/views/contact/group/index_page.dart'; import 'package:chat/views/contact/group/index_page.dart';
@@ -22,7 +24,7 @@ abstract class ContactRoutes {
static const String friendProfile = '/contact/friend/profile'; static const String friendProfile = '/contact/friend/profile';
static const String friendProfileMore = '/contact/friend/profile/more'; static const String friendProfileMore = '/contact/friend/profile/more';
static const String friendRemark = '/contact/friend/remark'; static const String friendRemark = '/contact/friend/remark';
static const String friendApply = '/contact/friend/profile'; static const String friendRequestApply = '/contact/friend/request/apply';
static const String friendRecommend = '/contact/friend/recommend'; static const String friendRecommend = '/contact/friend/recommend';
static const String friendRecommendFriend = static const String friendRecommendFriend =
'/contact/friend/recommend/friend'; '/contact/friend/recommend/friend';
@@ -48,6 +50,16 @@ abstract class ContactRoutes {
name: '/friend', name: '/friend',
page: () => const ContactGroupPage(), page: () => const ContactGroupPage(),
children: [ children: [
GetPage(
name: '/request',
page: () => const ContactFriendRequestPage(),
children: [
GetPage(
name: '/apply',
page: () => const ContactFriendRequestApplyPage(),
),
],
),
GetPage( GetPage(
name: '/search', name: '/search',
page: () => const ContactFriendSearchPage(), page: () => const ContactFriendSearchPage(),

View File

@@ -1,5 +1,7 @@
import 'package:chat/middleware/auth_middleware.dart'; import 'package:chat/middleware/auth_middleware.dart';
import 'package:chat/views/conversation/index_page.dart'; import 'package:chat/views/conversation/index_page.dart';
import 'package:chat/views/conversation/info/group_page.dart';
import 'package:chat/views/conversation/info/private_page.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
@@ -23,11 +25,11 @@ abstract class ConversationRoutes {
children: [ children: [
GetPage( GetPage(
name: '/private', name: '/private',
page: () => Container(), page: () => const ConversationInfoPrivatePage(),
), ),
GetPage( GetPage(
name: '/group', name: '/group',
page: () => Container(), page: () => const ConversationInfoGroupPage(),
), ),
], ],
), ),

View File

@@ -1,6 +1,7 @@
import 'package:chat/models/user_info_model.dart'; import 'package:chat/models/user_info_model.dart';
import 'package:chat/providers/auth_provider.dart'; import 'package:chat/providers/auth_provider.dart';
import 'package:chat/routes/auth_routes.dart'; import 'package:chat/routes/auth_routes.dart';
import 'package:chat/services/tim_service.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
import 'package:get_storage/get_storage.dart'; import 'package:get_storage/get_storage.dart';
import 'package:tencent_im_sdk_plugin/tencent_im_sdk_plugin.dart'; import 'package:tencent_im_sdk_plugin/tencent_im_sdk_plugin.dart';
@@ -27,6 +28,7 @@ class AuthService extends GetxService {
String get _userToken => _box.read('userToken') ?? ''; String get _userToken => _box.read('userToken') ?? '';
Map<String, dynamic> get _userInfo => _box.read('userInfo') ?? {}; Map<String, dynamic> get _userInfo => _box.read('userInfo') ?? {};
/// 用户信息,这个数据,在更新用户资料的时候,也应该更新
Rx<UserInfoModel> userInfo = UserInfoModel.empty().obs; Rx<UserInfoModel> userInfo = UserInfoModel.empty().obs;
@override @override
@@ -43,6 +45,7 @@ class AuthService extends GetxService {
} }
Future<bool> login(String address) async { Future<bool> login(String address) async {
address = '12dUut3dG5xWi6JPDMjSSK6s2JPcfeKYL1';
var result = await AuthProvider.login(address); var result = await AuthProvider.login(address);
if (result != null) { if (result != null) {
@@ -58,6 +61,9 @@ class AuthService extends GetxService {
isLogin.value = true; isLogin.value = true;
/// 登录IM
TimService.to.initSdk();
return true; return true;
} else { } else {
return false; return false;
@@ -74,6 +80,8 @@ class AuthService extends GetxService {
userId = ''; userId = '';
userToken = ''; userToken = '';
TimService.to.instance.logout();
userInfo.value = UserInfoModel.empty(); userInfo.value = UserInfoModel.empty();
isLogin.value = false; isLogin.value = false;
Get.offAllNamed(AuthRoutes.index); Get.offAllNamed(AuthRoutes.index);

View File

@@ -28,6 +28,7 @@ import 'package:tencent_im_sdk_plugin/models/v2_tim_message.dart';
import 'package:tencent_im_sdk_plugin/models/v2_tim_message_receipt.dart'; import 'package:tencent_im_sdk_plugin/models/v2_tim_message_receipt.dart';
import 'package:tencent_im_sdk_plugin/models/v2_tim_topic_info.dart'; import 'package:tencent_im_sdk_plugin/models/v2_tim_topic_info.dart';
import 'package:tencent_im_sdk_plugin/models/v2_tim_user_full_info.dart'; import 'package:tencent_im_sdk_plugin/models/v2_tim_user_full_info.dart';
import 'package:tencent_im_sdk_plugin/models/v2_tim_user_status.dart';
import 'package:tencent_im_sdk_plugin/tencent_im_sdk_plugin.dart'; import 'package:tencent_im_sdk_plugin/tencent_im_sdk_plugin.dart';
import 'package:vibration/vibration.dart'; import 'package:vibration/vibration.dart';
@@ -42,7 +43,7 @@ class TimService extends GetxService {
return TencentImSDKPlugin.v2TIMManager; return TencentImSDKPlugin.v2TIMManager;
} }
int sdkAppID = 1400752974; int sdkAppID = 1400754674;
String get _userSig => AuthService.to.userSig; String get _userSig => AuthService.to.userSig;
@@ -79,15 +80,21 @@ class TimService extends GetxService {
V2TimUserFullInfo info, V2TimUserFullInfo info,
) {}, ) {},
onUserSigExpired: () {}, onUserSigExpired: () {},
onUserStatusChanged: (List<V2TimUserStatus> userStatusList) {},
onLog: (int logLevel, String logContent) {},
), ),
); );
/// 登录 /// 登录
await instance.login( var loginResult = await instance.login(
userID: _userId, userID: _userId,
userSig: _userSig, userSig: _userSig,
); );
if (loginResult.code != 0) {
UiTools.toast(loginResult.desc);
}
Get.put(TimConversationService()); Get.put(TimConversationService());
Get.put(TimFriendService()); Get.put(TimFriendService());
Get.put(TimGroupService()); Get.put(TimGroupService());

View File

@@ -2,6 +2,7 @@ import 'package:chat/configs/app_colors.dart';
import 'package:chat/controllers/private_controller.dart'; import 'package:chat/controllers/private_controller.dart';
import 'package:chat/routes/contact_routes.dart'; import 'package:chat/routes/contact_routes.dart';
import 'package:chat/routes/conversation_routes.dart'; import 'package:chat/routes/conversation_routes.dart';
import 'package:chat/routes/moments_routes.dart';
import 'package:chat/services/tim/conversation_service.dart'; import 'package:chat/services/tim/conversation_service.dart';
import 'package:chat/utils/im_tools.dart'; import 'package:chat/utils/im_tools.dart';
import 'package:chat/views/home/widgets/action_button.dart'; import 'package:chat/views/home/widgets/action_button.dart';
@@ -75,18 +76,18 @@ class ContactFriendProfilePage extends StatelessWidget {
); );
}, },
), ),
// const SizedBox(height: 8), const SizedBox(height: 8),
// ActionItem( ActionItem(
// '他的动态', '他的动态',
// onTap: () { onTap: () {
// Get.toNamed( Get.toNamed(
// MomentsRoutes.user, MomentsRoutes.user,
// arguments: { arguments: {
// 'userId': _.currentFriend.value.userID, 'userId': _.currentFriend.value.userID,
// }, },
// ); );
// }, },
// ), ),
const SizedBox(height: 8), const SizedBox(height: 8),
Visibility( Visibility(
visible: !_.currentFriend.value.isFriend, visible: !_.currentFriend.value.isFriend,
@@ -94,7 +95,7 @@ class ContactFriendProfilePage extends StatelessWidget {
'添加到通讯录', '添加到通讯录',
onTap: () { onTap: () {
Get.toNamed( Get.toNamed(
ContactRoutes.friendApply, ContactRoutes.friendRequestApply,
arguments: { arguments: {
'userID': _.currentFriend.value.userID, 'userID': _.currentFriend.value.userID,
}, },

View File

@@ -1,4 +1,5 @@
import 'package:chat/configs/app_colors.dart'; import 'package:chat/configs/app_colors.dart';
import 'package:chat/services/auth_service.dart';
import 'package:chat/services/tim/friend_service.dart'; import 'package:chat/services/tim/friend_service.dart';
import 'package:chat/utils/ui_tools.dart'; import 'package:chat/utils/ui_tools.dart';
import 'package:chat/widgets/custom_primary_button.dart'; import 'package:chat/widgets/custom_primary_button.dart';
@@ -26,7 +27,7 @@ class _ContactFriendRequestApplyPageState
super.initState(); super.initState();
userID = Get.arguments['userID']; userID = Get.arguments['userID'];
_wordingController.text = '我是 '; _wordingController.text = '我是 ${AuthService.to.userInfo.value.nickname}';
} }
@override @override

View File

@@ -76,7 +76,7 @@ class _ImFriendRequestState extends State<ContactFriendRequestPage> {
); );
} }
Get.toNamed( Get.toNamed(
ContactRoutes.friendApply, ContactRoutes.friendRequestApply,
arguments: { arguments: {
'userID': user.userID, 'userID': user.userID,
}, },

View File

@@ -1,6 +1,5 @@
import 'package:chat/routes/user_routes.dart'; import 'package:chat/routes/user_routes.dart';
import 'package:chat/services/auth_service.dart'; import 'package:chat/views/user/index/widgets/user_top_bar.dart';
import 'package:chat/widgets/custom_avatar.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:get/get.dart'; import 'package:get/get.dart';
@@ -18,34 +17,8 @@ class _UserPageState extends State<UserPage> {
child: Scaffold( child: Scaffold(
body: Column( body: Column(
children: [ children: [
GetX<AuthService>(builder: (_) { const UserTopBar(),
return Row( const SizedBox(height: 8),
children: [
CustomAvatar(
_.userInfo.value.avatar,
size: 72,
),
Column(
children: [
Text(_.userInfo.value.nickname ?? ''),
Text('${_.userInfo.value.address}'),
],
),
Expanded(child: Container()),
InkWell(
onTap: () {
Get.toNamed(UserRoutes.qrCode);
},
child: Row(
children: const [
Icon(Icons.qr_code),
Icon(Icons.arrow_forward_ios),
],
),
),
],
);
}),
ListTile( ListTile(
onTap: () { onTap: () {
Get.toNamed(UserRoutes.share); Get.toNamed(UserRoutes.share);

View File

@@ -0,0 +1,72 @@
import 'package:chat/configs/app_colors.dart';
import 'package:chat/routes/user_routes.dart';
import 'package:chat/services/auth_service.dart';
import 'package:chat/utils/convert.dart';
import 'package:chat/widgets/custom_avatar.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
class UserTopBar extends StatelessWidget {
const UserTopBar({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Container(
color: AppColors.white,
padding: const EdgeInsets.only(
left: 24,
top: 48,
right: 24,
bottom: 24,
),
height: 64 + 48 + 24,
child: GetX<AuthService>(builder: (_) {
return Row(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
CustomAvatar(
_.userInfo.value.avatar,
size: 64,
),
const SizedBox(width: 16),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
_.userInfo.value.nickname ?? '',
style: const TextStyle(
fontSize: 22,
fontWeight: FontWeight.w400,
),
),
Text(Convert.hideCenterStr(_.userInfo.value.address ?? '')),
],
),
Expanded(child: Container()),
InkWell(
onTap: () {
Get.toNamed(UserRoutes.qrCode);
},
child: Row(
children: const [
Icon(
Icons.qr_code,
size: 18,
color: AppColors.unactive,
),
SizedBox(width: 8),
Icon(
Icons.arrow_forward_ios,
size: 16,
color: AppColors.unactive,
),
],
),
),
],
);
}),
);
}
}

View File

@@ -39,7 +39,7 @@ class CustomEasyRefresh {
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
children: [ children: [
Image.asset( Image.asset(
'assets/images/empty.png', 'assets/images/empty/im_emptyIcon_2.png',
width: size, width: size,
), ),
Text( Text(

View File

@@ -59,4 +59,5 @@ flutter:
assets: assets:
- assets/icons/ - assets/icons/
- assets/images/ - assets/images/
- assets/images/empty/
- assets/transits/ - assets/transits/