修复重复登录,头像无法更换问题
This commit is contained in:
parent
906cfbf4d8
commit
88d9428970
@ -13,6 +13,14 @@
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
"oauth_client": [
|
"oauth_client": [
|
||||||
|
{
|
||||||
|
"client_id": "980005024266-o9pjdmdbqqt1julbh1q1ovafcvmr1mv1.apps.googleusercontent.com",
|
||||||
|
"client_type": 1,
|
||||||
|
"android_info": {
|
||||||
|
"package_name": "com.org.yumi",
|
||||||
|
"certificate_hash": "3fe178dcc3294f7420df2754cfaf4646d6a19478"
|
||||||
|
}
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"client_id": "980005024266-sl5h466pe90jsjmoi4jcd7bqhmckieec.apps.googleusercontent.com",
|
"client_id": "980005024266-sl5h466pe90jsjmoi4jcd7bqhmckieec.apps.googleusercontent.com",
|
||||||
"client_type": 1,
|
"client_type": 1,
|
||||||
|
|||||||
@ -2,7 +2,6 @@ import 'dart:io';
|
|||||||
|
|
||||||
import 'package:fluro/fluro.dart';
|
import 'package:fluro/fluro.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:yumi/shared/data_sources/sources/remote/net/network_client.dart';
|
|
||||||
import 'package:yumi/modules/chat/chat_route.dart';
|
import 'package:yumi/modules/chat/chat_route.dart';
|
||||||
import 'package:yumi/modules/auth/login_route.dart';
|
import 'package:yumi/modules/auth/login_route.dart';
|
||||||
import 'package:yumi/app/routes/sc_lk_application.dart';
|
import 'package:yumi/app/routes/sc_lk_application.dart';
|
||||||
|
|||||||
@ -1,8 +1,6 @@
|
|||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/services.dart';
|
|
||||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
|
||||||
import 'package:yumi/app_localizations.dart';
|
import 'package:yumi/app_localizations.dart';
|
||||||
import 'package:yumi/ui_kit/components/sc_compontent.dart';
|
import 'package:yumi/ui_kit/components/sc_compontent.dart';
|
||||||
import 'package:yumi/ui_kit/components/text/sc_text.dart';
|
import 'package:yumi/ui_kit/components/text/sc_text.dart';
|
||||||
@ -12,7 +10,6 @@ import 'package:yumi/shared/tools/sc_pick_utils.dart';
|
|||||||
import 'package:yumi/shared/data_sources/sources/repositories/sc_user_repository_impl.dart';
|
import 'package:yumi/shared/data_sources/sources/repositories/sc_user_repository_impl.dart';
|
||||||
import 'package:yumi/services/auth/authentication_manager.dart';
|
import 'package:yumi/services/auth/authentication_manager.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:yumi/ui_kit/components/custom_cached_image.dart';
|
|
||||||
import 'package:yumi/app/constants/sc_screen.dart';
|
import 'package:yumi/app/constants/sc_screen.dart';
|
||||||
import 'package:yumi/app/routes/sc_routes.dart';
|
import 'package:yumi/app/routes/sc_routes.dart';
|
||||||
import 'package:yumi/app/routes/sc_fluro_navigator.dart';
|
import 'package:yumi/app/routes/sc_fluro_navigator.dart';
|
||||||
@ -26,7 +23,6 @@ import 'package:yumi/services/audio/rtm_manager.dart';
|
|||||||
import 'package:yumi/app/constants/sc_global_config.dart';
|
import 'package:yumi/app/constants/sc_global_config.dart';
|
||||||
|
|
||||||
import '../../../shared/business_logic/usecases/sc_custom_filtering_textinput_formatter.dart';
|
import '../../../shared/business_logic/usecases/sc_custom_filtering_textinput_formatter.dart';
|
||||||
import '../../country/country_page.dart';
|
|
||||||
import '../../country/country_route.dart';
|
import '../../country/country_route.dart';
|
||||||
|
|
||||||
///编辑个人信息
|
///编辑个人信息
|
||||||
@ -503,6 +499,26 @@ class _SCEditProfilePageState extends State<SCEditProfilePage> {
|
|||||||
return eighteenYearsAgo;
|
return eighteenYearsAgo;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String? _preferNonEmpty(String? primary, String? fallback) {
|
||||||
|
if (primary != null && primary.isNotEmpty) {
|
||||||
|
return primary;
|
||||||
|
}
|
||||||
|
if (fallback != null && fallback.isNotEmpty) {
|
||||||
|
return fallback;
|
||||||
|
}
|
||||||
|
return primary ?? fallback;
|
||||||
|
}
|
||||||
|
|
||||||
|
num? _preferNonZero(num? primary, num? fallback) {
|
||||||
|
if (primary != null && primary != 0) {
|
||||||
|
return primary;
|
||||||
|
}
|
||||||
|
if (fallback != null && fallback != 0) {
|
||||||
|
return fallback;
|
||||||
|
}
|
||||||
|
return primary ?? fallback;
|
||||||
|
}
|
||||||
|
|
||||||
///提交数据
|
///提交数据
|
||||||
void _submitUserProfile() async {
|
void _submitUserProfile() async {
|
||||||
if (nicknameController.text.isEmpty) {
|
if (nicknameController.text.isEmpty) {
|
||||||
@ -544,6 +560,50 @@ class _SCEditProfilePageState extends State<SCEditProfilePage> {
|
|||||||
idToken,
|
idToken,
|
||||||
userProvider!.editUser!,
|
userProvider!.editUser!,
|
||||||
);
|
);
|
||||||
|
final submittedProfile = userProvider?.editUser;
|
||||||
|
if (submittedProfile != null) {
|
||||||
|
final mergedProfile =
|
||||||
|
(user.userProfile ?? SocialChatUserProfile()).copyWith(
|
||||||
|
userAvatar: _preferNonEmpty(
|
||||||
|
user.userProfile?.userAvatar,
|
||||||
|
submittedProfile.userAvatar,
|
||||||
|
),
|
||||||
|
userNickname: _preferNonEmpty(
|
||||||
|
user.userProfile?.userNickname,
|
||||||
|
submittedProfile.userNickname,
|
||||||
|
),
|
||||||
|
userSex: _preferNonZero(
|
||||||
|
user.userProfile?.userSex,
|
||||||
|
submittedProfile.userSex,
|
||||||
|
),
|
||||||
|
bornYear: _preferNonZero(
|
||||||
|
user.userProfile?.bornYear,
|
||||||
|
submittedProfile.bornYear,
|
||||||
|
),
|
||||||
|
bornMonth: _preferNonZero(
|
||||||
|
user.userProfile?.bornMonth,
|
||||||
|
submittedProfile.bornMonth,
|
||||||
|
),
|
||||||
|
bornDay: _preferNonZero(
|
||||||
|
user.userProfile?.bornDay,
|
||||||
|
submittedProfile.bornDay,
|
||||||
|
),
|
||||||
|
age: _preferNonZero(user.userProfile?.age, submittedProfile.age),
|
||||||
|
countryCode: _preferNonEmpty(
|
||||||
|
user.userProfile?.countryCode,
|
||||||
|
submittedProfile.countryCode,
|
||||||
|
),
|
||||||
|
countryId: _preferNonEmpty(
|
||||||
|
user.userProfile?.countryId,
|
||||||
|
submittedProfile.countryId,
|
||||||
|
),
|
||||||
|
countryName: _preferNonEmpty(
|
||||||
|
user.userProfile?.countryName,
|
||||||
|
submittedProfile.countryName,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
user.setUserProfile(mergedProfile);
|
||||||
|
}
|
||||||
if (!mounted) {
|
if (!mounted) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -554,6 +614,7 @@ class _SCEditProfilePageState extends State<SCEditProfilePage> {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
AccountStorage().setCurrentUser(user);
|
AccountStorage().setCurrentUser(user);
|
||||||
|
userProvider?.syncCurrentUserProfile(user.userProfile);
|
||||||
SCLoadingManager.hide();
|
SCLoadingManager.hide();
|
||||||
SCNavigatorUtils.push(context, SCRoutes.home, clearStack: true);
|
SCNavigatorUtils.push(context, SCRoutes.home, clearStack: true);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -325,7 +325,7 @@ class _EditUserInfoPage2State extends State<EditUserInfoPage2>
|
|||||||
sTime = bTime;
|
sTime = bTime;
|
||||||
SCLoadingManager.show();
|
SCLoadingManager.show();
|
||||||
try {
|
try {
|
||||||
await SCAccountRepository().updateUserInfo(
|
final updatedProfile = await SCAccountRepository().updateUserInfo(
|
||||||
userAvatar: userCover,
|
userAvatar: userCover,
|
||||||
userSex: sex,
|
userSex: sex,
|
||||||
userNickname: nickName,
|
userNickname: nickName,
|
||||||
@ -337,6 +337,14 @@ class _EditUserInfoPage2State extends State<EditUserInfoPage2>
|
|||||||
autograph: autograph,
|
autograph: autograph,
|
||||||
countryId: country?.id,
|
countryId: country?.id,
|
||||||
);
|
);
|
||||||
|
if (!mounted) {
|
||||||
|
SCLoadingManager.hide();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
Provider.of<SocialChatUserProfileManager>(
|
||||||
|
context,
|
||||||
|
listen: false,
|
||||||
|
).syncCurrentUserProfile(updatedProfile);
|
||||||
Provider.of<RtcProvider>(context, listen: false).needUpDataUserInfo =
|
Provider.of<RtcProvider>(context, listen: false).needUpDataUserInfo =
|
||||||
true;
|
true;
|
||||||
SCTts.show(SCAppLocalizations.of(context)!.operationSuccessful);
|
SCTts.show(SCAppLocalizations.of(context)!.operationSuccessful);
|
||||||
|
|||||||
@ -72,7 +72,7 @@ class _MePage2State extends State<MePage2> {
|
|||||||
padding: EdgeInsets.fromLTRB(10.w, 12.w, 10.w, 24.w),
|
padding: EdgeInsets.fromLTRB(10.w, 12.w, 10.w, 24.w),
|
||||||
child: Column(
|
child: Column(
|
||||||
children: [
|
children: [
|
||||||
_buildProfileSection(),
|
_buildProfileSection(profileManager),
|
||||||
SizedBox(height: 12.w),
|
SizedBox(height: 12.w),
|
||||||
_buildStatsCard(),
|
_buildStatsCard(),
|
||||||
SizedBox(height: 12.w),
|
SizedBox(height: 12.w),
|
||||||
@ -110,8 +110,9 @@ class _MePage2State extends State<MePage2> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget _buildProfileSection() {
|
Widget _buildProfileSection(SocialChatUserProfileManager profileManager) {
|
||||||
final profile = AccountStorage().getCurrentUser()?.userProfile;
|
final profile =
|
||||||
|
profileManager.userProfile ?? AccountStorage().getCurrentUser()?.userProfile;
|
||||||
|
|
||||||
return SCDebounceWidget(
|
return SCDebounceWidget(
|
||||||
onTap: () {
|
onTap: () {
|
||||||
@ -515,7 +516,7 @@ class _MePage2State extends State<MePage2> {
|
|||||||
return Container(
|
return Container(
|
||||||
width: 0.5.w,
|
width: 0.5.w,
|
||||||
height: 16.w,
|
height: 16.w,
|
||||||
color: const Color(0xFFE6E6E6).withOpacity(0.8),
|
color: const Color(0xFFE6E6E6).withValues(alpha: 0.8),
|
||||||
margin: EdgeInsets.symmetric(horizontal: 6.w),
|
margin: EdgeInsets.symmetric(horizontal: 6.w),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -535,8 +536,8 @@ class _MePage2State extends State<MePage2> {
|
|||||||
begin: Alignment.topLeft,
|
begin: Alignment.topLeft,
|
||||||
end: Alignment.bottomRight,
|
end: Alignment.bottomRight,
|
||||||
colors: [
|
colors: [
|
||||||
const Color(0xFF0A7D49).withOpacity(0.20),
|
const Color(0xFF0A7D49).withValues(alpha: 0.20),
|
||||||
const Color(0xFF031513).withOpacity(0.35),
|
const Color(0xFF031513).withValues(alpha: 0.35),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@ -61,17 +61,30 @@ class SocialChatUserProfileManager extends ChangeNotifier {
|
|||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void syncCurrentUserProfile(SocialChatUserProfile? profile) {
|
||||||
|
if (profile == null) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
userProfile = profile;
|
||||||
|
final currentUser = AccountStorage().getCurrentUser();
|
||||||
|
if (currentUser != null) {
|
||||||
|
currentUser.setUserProfile(profile);
|
||||||
|
AccountStorage().setCurrentUser(currentUser);
|
||||||
|
}
|
||||||
|
notifyListeners();
|
||||||
|
}
|
||||||
|
|
||||||
Future fetchUserProfileData({
|
Future fetchUserProfileData({
|
||||||
bool loadGuardCount = true,
|
bool loadGuardCount = true,
|
||||||
bool refreshFamilyData = false,
|
bool refreshFamilyData = false,
|
||||||
}) async {
|
}) async {
|
||||||
var us = AccountStorage().getCurrentUser();
|
var us = AccountStorage().getCurrentUser();
|
||||||
String userId = us?.userProfile?.id ?? "";
|
String userId = us?.userProfile?.id ?? "";
|
||||||
|
if (userId.isEmpty) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
var userInfo = await SCAccountRepository().loadUserInfo(userId);
|
var userInfo = await SCAccountRepository().loadUserInfo(userId);
|
||||||
userProfile = userInfo;
|
syncCurrentUserProfile(userInfo);
|
||||||
us?.setUserProfile(userInfo);
|
|
||||||
AccountStorage().setCurrentUser(us!);
|
|
||||||
notifyListeners();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
SCUserIdentityRes? userIdentity;
|
SCUserIdentityRes? userIdentity;
|
||||||
|
|||||||
@ -4,7 +4,7 @@ import 'package:dio/dio.dart';
|
|||||||
import 'package:flutter/cupertino.dart';
|
import 'package:flutter/cupertino.dart';
|
||||||
import 'package:flutter/foundation.dart';
|
import 'package:flutter/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
import 'package:yumi/app/constants/sc_global_config.dart';
|
||||||
import 'package:yumi/ui_kit/components/sc_tts.dart';
|
import 'package:yumi/ui_kit/components/sc_tts.dart';
|
||||||
import 'package:yumi/shared/tools/sc_room_utils.dart';
|
import 'package:yumi/shared/tools/sc_room_utils.dart';
|
||||||
import 'package:yumi/shared/data_sources/sources/local/user_manager.dart';
|
import 'package:yumi/shared/data_sources/sources/local/user_manager.dart';
|
||||||
@ -22,6 +22,87 @@ _parseAndDecode(String response) => jsonDecode(response);
|
|||||||
|
|
||||||
parseJson(String text) => compute(_parseAndDecode, text);
|
parseJson(String text) => compute(_parseAndDecode, text);
|
||||||
|
|
||||||
|
String _normalizeAuthorizationHeader(Object? authorization) {
|
||||||
|
if (authorization == null) {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
if (authorization is Iterable) {
|
||||||
|
return authorization.map((value) => value.toString()).join(",");
|
||||||
|
}
|
||||||
|
return authorization.toString().trim();
|
||||||
|
}
|
||||||
|
|
||||||
|
bool _shouldLogoutForUnauthorized(DioException e) {
|
||||||
|
final currentToken = AccountStorage().getToken();
|
||||||
|
if (currentToken.isEmpty) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
final requestAuthorization = _normalizeAuthorizationHeader(
|
||||||
|
e.requestOptions.headers["Authorization"],
|
||||||
|
);
|
||||||
|
if (requestAuthorization.isEmpty) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
return requestAuthorization == "Bearer $currentToken";
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<bool> _isCurrentSessionStillValid(DioException e) async {
|
||||||
|
if (!_shouldLogoutForUnauthorized(e)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
final verificationHeaders = Map<String, dynamic>.from(e.requestOptions.headers)
|
||||||
|
..remove("Content-Length")
|
||||||
|
..remove("content-length");
|
||||||
|
|
||||||
|
final verificationClient = Dio(
|
||||||
|
BaseOptions(
|
||||||
|
baseUrl:
|
||||||
|
e.requestOptions.baseUrl.isNotEmpty
|
||||||
|
? e.requestOptions.baseUrl
|
||||||
|
: SCGlobalConfig.apiHost,
|
||||||
|
connectTimeout: const Duration(seconds: 5),
|
||||||
|
receiveTimeout: const Duration(seconds: 5),
|
||||||
|
sendTimeout: const Duration(seconds: 5),
|
||||||
|
responseType: ResponseType.json,
|
||||||
|
validateStatus: (status) => status != null && status < 500,
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|
||||||
|
try {
|
||||||
|
final verificationResponse = await verificationClient.get(
|
||||||
|
"/app/h5/identity",
|
||||||
|
options: Options(headers: verificationHeaders),
|
||||||
|
);
|
||||||
|
final responseData = verificationResponse.data;
|
||||||
|
|
||||||
|
if (verificationResponse.statusCode == 401) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (responseData is Map<String, dynamic>) {
|
||||||
|
if (responseData["status"] == true) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (responseData["errorCode"] == SCErroCode.authUnauthorized.code) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} on DioException catch (verificationError) {
|
||||||
|
final responseData = verificationError.response?.data;
|
||||||
|
if (verificationError.response?.statusCode == 401) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (responseData is Map<String, dynamic> &&
|
||||||
|
responseData["errorCode"] == SCErroCode.authUnauthorized.code) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} catch (_) {}
|
||||||
|
|
||||||
|
// 校验结果不明确时不要主动登出,避免单条接口抖动把整次登录踢掉。
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
class BaseNetworkClient {
|
class BaseNetworkClient {
|
||||||
final Dio dio;
|
final Dio dio;
|
||||||
|
|
||||||
@ -176,7 +257,7 @@ class BaseNetworkClient {
|
|||||||
}
|
}
|
||||||
} on DioException catch (e) {
|
} on DioException catch (e) {
|
||||||
// 网络错误处理
|
// 网络错误处理
|
||||||
throw _hdlErr(e);
|
throw await _hdlErr(e);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
SCLoadingManager.hide();
|
SCLoadingManager.hide();
|
||||||
throw Exception('未知错误: $e');
|
throw Exception('未知错误: $e');
|
||||||
@ -184,7 +265,7 @@ class BaseNetworkClient {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 错误处理
|
// 错误处理
|
||||||
DioException _hdlErr(DioException e) {
|
Future<DioException> _hdlErr(DioException e) async {
|
||||||
SCLoadingManager.hide();
|
SCLoadingManager.hide();
|
||||||
switch (e.type) {
|
switch (e.type) {
|
||||||
case DioExceptionType.connectionTimeout:
|
case DioExceptionType.connectionTimeout:
|
||||||
@ -209,12 +290,13 @@ class BaseNetworkClient {
|
|||||||
}
|
}
|
||||||
} else if (errorCode == SCErroCode.authUnauthorized.code) {
|
} else if (errorCode == SCErroCode.authUnauthorized.code) {
|
||||||
//token过期
|
//token过期
|
||||||
BuildContext? context = navigatorKey.currentContext;
|
final shouldLogout =
|
||||||
if (context != null) {
|
!SCNavigatorUtils.inLoginPage &&
|
||||||
if (!inLoginPage) {
|
!await _isCurrentSessionStillValid(e);
|
||||||
AccountStorage().logout(context);
|
final BuildContext? context = navigatorKey.currentContext;
|
||||||
inLoginPage = true;
|
if (context != null && shouldLogout) {
|
||||||
}
|
AccountStorage().logout(context);
|
||||||
|
SCNavigatorUtils.inLoginPage = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (errorMsg.toString().endsWith("balance not made")) {
|
if (errorMsg.toString().endsWith("balance not made")) {
|
||||||
|
|||||||
@ -10,7 +10,6 @@ import 'package:yumi/shared/data_sources/sources/remote/net/api.dart';
|
|||||||
import 'package:yumi/shared/data_sources/sources/remote/net/sc_logger.dart';
|
import 'package:yumi/shared/data_sources/sources/remote/net/sc_logger.dart';
|
||||||
|
|
||||||
NetworkClient get http => _httpInstance;
|
NetworkClient get http => _httpInstance;
|
||||||
bool inLoginPage = false;
|
|
||||||
|
|
||||||
late final NetworkClient _httpInstance = NetworkClient();
|
late final NetworkClient _httpInstance = NetworkClient();
|
||||||
|
|
||||||
|
|||||||
@ -431,7 +431,7 @@ class SCAccountRepository implements SocialChatUserRepository {
|
|||||||
parm["personalPhotos"] = personalPhotos;
|
parm["personalPhotos"] = personalPhotos;
|
||||||
}
|
}
|
||||||
|
|
||||||
final result = await http.post<SocialChatUserProfile>(
|
final result = await http.put<SocialChatUserProfile>(
|
||||||
"2fa1d4f56bb726558904ce2a50b83f96365e62b6aa808acde7b56d2d5945fbe4",
|
"2fa1d4f56bb726558904ce2a50b83f96365e62b6aa808acde7b56d2d5945fbe4",
|
||||||
data: parm,
|
data: parm,
|
||||||
fromJson: (json) => SocialChatUserProfile.fromJson(json),
|
fromJson: (json) => SocialChatUserProfile.fromJson(json),
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
|
import 'package:yumi/shared/data_sources/sources/local/user_manager.dart';
|
||||||
import 'package:yumi/shared/data_sources/sources/repositories/sc_user_repository_impl.dart';
|
import 'package:yumi/shared/data_sources/sources/repositories/sc_user_repository_impl.dart';
|
||||||
|
|
||||||
import '../../shared/data_sources/models/enum/sc_heartbeat_status.dart';
|
import '../../shared/data_sources/models/enum/sc_heartbeat_status.dart';
|
||||||
@ -17,17 +18,29 @@ class SCHeartbeatUtils {
|
|||||||
bool upMick, {
|
bool upMick, {
|
||||||
String? roomId,
|
String? roomId,
|
||||||
}) async {
|
}) async {
|
||||||
cancelAnchorTimer();
|
cancelTimer();
|
||||||
_c = status;
|
_c = status;
|
||||||
_u = upMick;
|
_u = upMick;
|
||||||
_r = roomId;
|
_r = roomId;
|
||||||
SCAccountRepository().heartbeat(_c, _u, roomId: _r).whenComplete(() {
|
if (AccountStorage().getToken().isEmpty) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
await SCAccountRepository().heartbeat(_c, _u, roomId: _r);
|
||||||
|
_h ??= Timer.periodic(Duration(seconds: 60), (timer) {
|
||||||
|
if (AccountStorage().getToken().isEmpty) {
|
||||||
|
cancelTimer();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
SCAccountRepository()
|
||||||
|
.heartbeat(_c, _u, roomId: _r)
|
||||||
|
.catchError((_) => {});
|
||||||
|
});
|
||||||
|
} catch (e) {
|
||||||
try {
|
try {
|
||||||
_h ??= Timer.periodic(Duration(seconds: 60), (timer) {
|
cancelTimer();
|
||||||
SCAccountRepository().heartbeat(_c, _u, roomId: _r);
|
} catch (_) {}
|
||||||
});
|
}
|
||||||
} catch (e) {}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cancelTimer() {
|
static void cancelTimer() {
|
||||||
@ -40,12 +53,10 @@ class SCHeartbeatUtils {
|
|||||||
///上麦主播发送心跳
|
///上麦主播发送心跳
|
||||||
static void scheduleAnchorHeartbeat(String roomId) async {
|
static void scheduleAnchorHeartbeat(String roomId) async {
|
||||||
cancelAnchorTimer();
|
cancelAnchorTimer();
|
||||||
scheduleHeartbeat(_c, true, roomId: _r);
|
scheduleHeartbeat(_c, true, roomId: roomId);
|
||||||
SCAccountRepository().anchorHeartbeat(roomId).whenComplete(() {
|
SCAccountRepository().anchorHeartbeat(roomId).whenComplete(() {
|
||||||
_a ??= Timer.periodic(Duration(seconds: 60), (timer) {
|
_a ??= Timer.periodic(Duration(seconds: 60), (timer) {
|
||||||
try {
|
SCAccountRepository().anchorHeartbeat(roomId).catchError((_) => {});
|
||||||
SCAccountRepository().anchorHeartbeat(roomId);
|
|
||||||
} catch (e) {}
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,14 +1,13 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
import 'package:flutter/cupertino.dart';
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||||
|
import 'package:yumi/app/routes/sc_fluro_navigator.dart';
|
||||||
import 'package:yumi/shared/tools/sc_room_utils.dart';
|
import 'package:yumi/shared/tools/sc_room_utils.dart';
|
||||||
import 'package:yumi/shared/data_sources/sources/local/user_manager.dart';
|
import 'package:yumi/shared/data_sources/sources/local/user_manager.dart';
|
||||||
import 'package:yumi/shared/business_logic/models/res/login_res.dart';
|
import 'package:yumi/shared/business_logic/models/res/login_res.dart';
|
||||||
import 'package:yumi/ui_kit/components/sc_debounce_widget.dart';
|
import 'package:yumi/ui_kit/components/sc_debounce_widget.dart';
|
||||||
import 'package:yumi/ui_kit/components/sc_compontent.dart';
|
import 'package:yumi/ui_kit/components/sc_compontent.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'package:yumi/shared/data_sources/sources/remote/net/network_client.dart';
|
|
||||||
import 'package:yumi/shared/business_logic/models/res/join_room_res.dart';
|
import 'package:yumi/shared/business_logic/models/res/join_room_res.dart';
|
||||||
import 'package:yumi/services/audio/rtc_manager.dart';
|
import 'package:yumi/services/audio/rtc_manager.dart';
|
||||||
import 'package:yumi/app/constants/sc_screen.dart';
|
import 'package:yumi/app/constants/sc_screen.dart';
|
||||||
@ -41,7 +40,7 @@ class SCFloatIchart {
|
|||||||
var overlayState = Overlay.of(context!);
|
var overlayState = Overlay.of(context!);
|
||||||
overlayEntry = OverlayEntry(
|
overlayEntry = OverlayEntry(
|
||||||
builder: (context) {
|
builder: (context) {
|
||||||
if (inLoginPage) {
|
if (SCNavigatorUtils.inLoginPage) {
|
||||||
remove();
|
remove();
|
||||||
return Container();
|
return Container();
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user