修复重复登录,头像无法更换问题
This commit is contained in:
parent
906cfbf4d8
commit
88d9428970
@ -13,6 +13,14 @@
|
||||
}
|
||||
},
|
||||
"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_type": 1,
|
||||
@ -44,4 +52,4 @@
|
||||
}
|
||||
],
|
||||
"configuration_version": "1"
|
||||
}
|
||||
}
|
||||
@ -1,11 +1,10 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:fluro/fluro.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/auth/login_route.dart';
|
||||
import 'package:yumi/app/routes/sc_lk_application.dart';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:fluro/fluro.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:yumi/modules/chat/chat_route.dart';
|
||||
import 'package:yumi/modules/auth/login_route.dart';
|
||||
import 'package:yumi/app/routes/sc_lk_application.dart';
|
||||
|
||||
/// 安卓页面切换时长
|
||||
const Duration kAndroidTransitionDuration = Duration(milliseconds: 375);
|
||||
|
||||
@ -1,21 +1,18 @@
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.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/ui_kit/components/sc_compontent.dart';
|
||||
import 'package:yumi/ui_kit/components/text/sc_text.dart';
|
||||
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||||
import 'package:yumi/app_localizations.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/sc_tts.dart';
|
||||
import 'package:yumi/shared/tools/sc_loading_manager.dart';
|
||||
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/services/auth/authentication_manager.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/routes/sc_routes.dart';
|
||||
import 'package:yumi/app/routes/sc_fluro_navigator.dart';
|
||||
import 'package:yumi/shared/data_sources/sources/repositories/sc_user_repository_impl.dart';
|
||||
import 'package:yumi/services/auth/authentication_manager.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:yumi/app/constants/sc_screen.dart';
|
||||
import 'package:yumi/app/routes/sc_routes.dart';
|
||||
import 'package:yumi/app/routes/sc_fluro_navigator.dart';
|
||||
import 'package:yumi/shared/tools/sc_date_utils.dart';
|
||||
import 'package:yumi/shared/data_sources/sources/local/user_manager.dart';
|
||||
import 'package:yumi/shared/business_logic/models/res/login_res.dart';
|
||||
@ -24,10 +21,9 @@ import 'package:yumi/services/auth/user_profile_manager.dart';
|
||||
import 'package:yumi/services/audio/rtc_manager.dart';
|
||||
import 'package:yumi/services/audio/rtm_manager.dart';
|
||||
import 'package:yumi/app/constants/sc_global_config.dart';
|
||||
|
||||
import '../../../shared/business_logic/usecases/sc_custom_filtering_textinput_formatter.dart';
|
||||
import '../../country/country_page.dart';
|
||||
import '../../country/country_route.dart';
|
||||
|
||||
import '../../../shared/business_logic/usecases/sc_custom_filtering_textinput_formatter.dart';
|
||||
import '../../country/country_route.dart';
|
||||
|
||||
///编辑个人信息
|
||||
class SCEditProfilePage extends StatefulWidget {
|
||||
@ -37,7 +33,7 @@ class SCEditProfilePage extends StatefulWidget {
|
||||
_SCEditProfilePageState createState() => _SCEditProfilePageState();
|
||||
}
|
||||
|
||||
class _SCEditProfilePageState extends State<SCEditProfilePage> {
|
||||
class _SCEditProfilePageState extends State<SCEditProfilePage> {
|
||||
///默认女
|
||||
int type = 0;
|
||||
DateTime birthdayDate = DateTime(2006);
|
||||
@ -488,7 +484,7 @@ class _SCEditProfilePageState extends State<SCEditProfilePage> {
|
||||
);
|
||||
}
|
||||
|
||||
DateTime _getBefor18() {
|
||||
DateTime _getBefor18() {
|
||||
DateTime currentDate = DateTime.now();
|
||||
DateTime eighteenYearsAgo = DateTime(
|
||||
currentDate.year - 18,
|
||||
@ -500,11 +496,31 @@ class _SCEditProfilePageState extends State<SCEditProfilePage> {
|
||||
currentDate.millisecond,
|
||||
currentDate.microsecond,
|
||||
);
|
||||
return eighteenYearsAgo;
|
||||
}
|
||||
|
||||
///提交数据
|
||||
void _submitUserProfile() async {
|
||||
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 {
|
||||
if (nicknameController.text.isEmpty) {
|
||||
SCTts.show(SCAppLocalizations.of(context)!.pleaseEnterNickname);
|
||||
return;
|
||||
@ -539,22 +555,67 @@ class _SCEditProfilePageState extends State<SCEditProfilePage> {
|
||||
context,
|
||||
listen: false,
|
||||
).uid;
|
||||
SocialChatLoginRes user = await SCAccountRepository().regist(
|
||||
authType,
|
||||
idToken,
|
||||
userProvider!.editUser!,
|
||||
);
|
||||
if (!mounted) {
|
||||
return;
|
||||
}
|
||||
SocialChatLoginRes user = await SCAccountRepository().regist(
|
||||
authType,
|
||||
idToken,
|
||||
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) {
|
||||
return;
|
||||
}
|
||||
await Provider.of<RtcProvider>(context, listen: false).resetLocalRoomState(
|
||||
fallbackRtmProvider: Provider.of<RtmProvider>(context, listen: false),
|
||||
);
|
||||
if (!mounted) {
|
||||
return;
|
||||
}
|
||||
AccountStorage().setCurrentUser(user);
|
||||
SCLoadingManager.hide();
|
||||
SCNavigatorUtils.push(context, SCRoutes.home, clearStack: true);
|
||||
}
|
||||
}
|
||||
}
|
||||
AccountStorage().setCurrentUser(user);
|
||||
userProvider?.syncCurrentUserProfile(user.userProfile);
|
||||
SCLoadingManager.hide();
|
||||
SCNavigatorUtils.push(context, SCRoutes.home, clearStack: true);
|
||||
}
|
||||
}
|
||||
|
||||
@ -323,24 +323,32 @@ class _EditUserInfoPage2State extends State<EditUserInfoPage2>
|
||||
int bTime = DateTime.now().millisecondsSinceEpoch;
|
||||
if (bTime - sTime > 5000) {
|
||||
sTime = bTime;
|
||||
SCLoadingManager.show();
|
||||
try {
|
||||
await SCAccountRepository().updateUserInfo(
|
||||
userAvatar: userCover,
|
||||
userSex: sex,
|
||||
userNickname: nickName,
|
||||
age: age,
|
||||
SCLoadingManager.show();
|
||||
try {
|
||||
final updatedProfile = await SCAccountRepository().updateUserInfo(
|
||||
userAvatar: userCover,
|
||||
userSex: sex,
|
||||
userNickname: nickName,
|
||||
age: age,
|
||||
bornDay: birthdayDate?.day,
|
||||
bornMonth: birthdayDate?.month,
|
||||
bornYear: birthdayDate?.year,
|
||||
hobby: hobby,
|
||||
autograph: autograph,
|
||||
countryId: country?.id,
|
||||
);
|
||||
Provider.of<RtcProvider>(context, listen: false).needUpDataUserInfo =
|
||||
true;
|
||||
SCTts.show(SCAppLocalizations.of(context)!.operationSuccessful);
|
||||
} catch (e) {
|
||||
hobby: hobby,
|
||||
autograph: autograph,
|
||||
countryId: country?.id,
|
||||
);
|
||||
if (!mounted) {
|
||||
SCLoadingManager.hide();
|
||||
return;
|
||||
}
|
||||
Provider.of<SocialChatUserProfileManager>(
|
||||
context,
|
||||
listen: false,
|
||||
).syncCurrentUserProfile(updatedProfile);
|
||||
Provider.of<RtcProvider>(context, listen: false).needUpDataUserInfo =
|
||||
true;
|
||||
SCTts.show(SCAppLocalizations.of(context)!.operationSuccessful);
|
||||
} catch (e) {
|
||||
debugPrint(e.toString());
|
||||
SCLoadingManager.hide();
|
||||
}
|
||||
|
||||
@ -60,19 +60,19 @@ class _MePage2State extends State<MePage2> {
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SafeArea(
|
||||
top: true,
|
||||
bottom: false,
|
||||
child: Consumer<SocialChatUserProfileManager>(
|
||||
builder: (context, profileManager, child) {
|
||||
return SingleChildScrollView(
|
||||
physics: const BouncingScrollPhysics(),
|
||||
padding: EdgeInsets.fromLTRB(10.w, 12.w, 10.w, 24.w),
|
||||
child: Column(
|
||||
children: [
|
||||
_buildProfileSection(),
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return SafeArea(
|
||||
top: true,
|
||||
bottom: false,
|
||||
child: Consumer<SocialChatUserProfileManager>(
|
||||
builder: (context, profileManager, child) {
|
||||
return SingleChildScrollView(
|
||||
physics: const BouncingScrollPhysics(),
|
||||
padding: EdgeInsets.fromLTRB(10.w, 12.w, 10.w, 24.w),
|
||||
child: Column(
|
||||
children: [
|
||||
_buildProfileSection(profileManager),
|
||||
SizedBox(height: 12.w),
|
||||
_buildStatsCard(),
|
||||
SizedBox(height: 12.w),
|
||||
@ -110,8 +110,9 @@ class _MePage2State extends State<MePage2> {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildProfileSection() {
|
||||
final profile = AccountStorage().getCurrentUser()?.userProfile;
|
||||
Widget _buildProfileSection(SocialChatUserProfileManager profileManager) {
|
||||
final profile =
|
||||
profileManager.userProfile ?? AccountStorage().getCurrentUser()?.userProfile;
|
||||
|
||||
return SCDebounceWidget(
|
||||
onTap: () {
|
||||
@ -515,7 +516,7 @@ class _MePage2State extends State<MePage2> {
|
||||
return Container(
|
||||
width: 0.5.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),
|
||||
);
|
||||
}
|
||||
@ -535,8 +536,8 @@ class _MePage2State extends State<MePage2> {
|
||||
begin: Alignment.topLeft,
|
||||
end: Alignment.bottomRight,
|
||||
colors: [
|
||||
const Color(0xFF0A7D49).withOpacity(0.20),
|
||||
const Color(0xFF031513).withOpacity(0.35),
|
||||
const Color(0xFF0A7D49).withValues(alpha: 0.20),
|
||||
const Color(0xFF031513).withValues(alpha: 0.35),
|
||||
],
|
||||
),
|
||||
),
|
||||
|
||||
@ -56,23 +56,36 @@ class SocialChatUserProfileManager extends ChangeNotifier {
|
||||
editUser!.setCountryName = country.countryName!;
|
||||
}
|
||||
|
||||
void resetEditUserData() {
|
||||
editUser = null;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
Future fetchUserProfileData({
|
||||
bool loadGuardCount = true,
|
||||
bool refreshFamilyData = false,
|
||||
}) async {
|
||||
var us = AccountStorage().getCurrentUser();
|
||||
String userId = us?.userProfile?.id ?? "";
|
||||
var userInfo = await SCAccountRepository().loadUserInfo(userId);
|
||||
userProfile = userInfo;
|
||||
us?.setUserProfile(userInfo);
|
||||
AccountStorage().setCurrentUser(us!);
|
||||
notifyListeners();
|
||||
}
|
||||
void resetEditUserData() {
|
||||
editUser = null;
|
||||
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({
|
||||
bool loadGuardCount = true,
|
||||
bool refreshFamilyData = false,
|
||||
}) async {
|
||||
var us = AccountStorage().getCurrentUser();
|
||||
String userId = us?.userProfile?.id ?? "";
|
||||
if (userId.isEmpty) {
|
||||
return;
|
||||
}
|
||||
var userInfo = await SCAccountRepository().loadUserInfo(userId);
|
||||
syncCurrentUserProfile(userInfo);
|
||||
}
|
||||
|
||||
SCUserIdentityRes? userIdentity;
|
||||
|
||||
|
||||
@ -1,13 +1,13 @@
|
||||
// api.dart
|
||||
import 'dart:convert';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
||||
import 'package:yumi/ui_kit/components/sc_tts.dart';
|
||||
import 'package:yumi/shared/tools/sc_room_utils.dart';
|
||||
import 'package:yumi/shared/data_sources/sources/local/user_manager.dart';
|
||||
import 'dart:convert';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:yumi/app/constants/sc_global_config.dart';
|
||||
import 'package:yumi/ui_kit/components/sc_tts.dart';
|
||||
import 'package:yumi/shared/tools/sc_room_utils.dart';
|
||||
import 'package:yumi/shared/data_sources/sources/local/user_manager.dart';
|
||||
import 'package:yumi/modules/auth/login_route.dart';
|
||||
import 'package:yumi/app/routes/sc_fluro_navigator.dart';
|
||||
import 'package:yumi/shared/tools/sc_loading_manager.dart';
|
||||
@ -20,9 +20,90 @@ export 'package:dio/dio.dart';
|
||||
|
||||
_parseAndDecode(String response) => jsonDecode(response);
|
||||
|
||||
parseJson(String text) => compute(_parseAndDecode, text);
|
||||
|
||||
class BaseNetworkClient {
|
||||
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 {
|
||||
final Dio dio;
|
||||
|
||||
BaseNetworkClient() : dio = Dio() {
|
||||
@ -174,9 +255,9 @@ class BaseNetworkClient {
|
||||
error: '业务错误: ${baseResponse.errorMsg}',
|
||||
);
|
||||
}
|
||||
} on DioException catch (e) {
|
||||
// 网络错误处理
|
||||
throw _hdlErr(e);
|
||||
} on DioException catch (e) {
|
||||
// 网络错误处理
|
||||
throw await _hdlErr(e);
|
||||
} catch (e) {
|
||||
SCLoadingManager.hide();
|
||||
throw Exception('未知错误: $e');
|
||||
@ -184,11 +265,11 @@ class BaseNetworkClient {
|
||||
}
|
||||
|
||||
// 错误处理
|
||||
DioException _hdlErr(DioException e) {
|
||||
SCLoadingManager.hide();
|
||||
switch (e.type) {
|
||||
case DioExceptionType.connectionTimeout:
|
||||
return DioException(requestOptions: e.requestOptions, error: '连接超时');
|
||||
Future<DioException> _hdlErr(DioException e) async {
|
||||
SCLoadingManager.hide();
|
||||
switch (e.type) {
|
||||
case DioExceptionType.connectionTimeout:
|
||||
return DioException(requestOptions: e.requestOptions, error: '连接超时');
|
||||
case DioExceptionType.sendTimeout:
|
||||
return DioException(requestOptions: e.requestOptions, error: '发送超时');
|
||||
case DioExceptionType.receiveTimeout:
|
||||
@ -207,16 +288,17 @@ class BaseNetworkClient {
|
||||
replace: false,
|
||||
);
|
||||
}
|
||||
} else if (errorCode == SCErroCode.authUnauthorized.code) {
|
||||
//token过期
|
||||
BuildContext? context = navigatorKey.currentContext;
|
||||
if (context != null) {
|
||||
if (!inLoginPage) {
|
||||
AccountStorage().logout(context);
|
||||
inLoginPage = true;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
} else if (errorCode == SCErroCode.authUnauthorized.code) {
|
||||
//token过期
|
||||
final shouldLogout =
|
||||
!SCNavigatorUtils.inLoginPage &&
|
||||
!await _isCurrentSessionStillValid(e);
|
||||
final BuildContext? context = navigatorKey.currentContext;
|
||||
if (context != null && shouldLogout) {
|
||||
AccountStorage().logout(context);
|
||||
SCNavigatorUtils.inLoginPage = true;
|
||||
}
|
||||
} else {
|
||||
if (errorMsg.toString().endsWith("balance not made")) {
|
||||
BuildContext? context = navigatorKey.currentContext;
|
||||
if (context != null) {
|
||||
@ -231,11 +313,11 @@ class BaseNetworkClient {
|
||||
response: e.response,
|
||||
error: '服务器错误: ${e.response?.data["errorCode"]}',
|
||||
);
|
||||
case DioExceptionType.cancel:
|
||||
return DioException(requestOptions: e.requestOptions, error: 'Cancel');
|
||||
default:
|
||||
return DioException(
|
||||
requestOptions: e.requestOptions,
|
||||
case DioExceptionType.cancel:
|
||||
return DioException(requestOptions: e.requestOptions, error: 'Cancel');
|
||||
default:
|
||||
return DioException(
|
||||
requestOptions: e.requestOptions,
|
||||
error: 'Net fail',
|
||||
);
|
||||
}
|
||||
|
||||
@ -9,8 +9,7 @@ import 'package:yumi/shared/tools/sc_deviceId_utils.dart';
|
||||
import 'package:yumi/shared/data_sources/sources/remote/net/api.dart';
|
||||
import 'package:yumi/shared/data_sources/sources/remote/net/sc_logger.dart';
|
||||
|
||||
NetworkClient get http => _httpInstance;
|
||||
bool inLoginPage = false;
|
||||
NetworkClient get http => _httpInstance;
|
||||
|
||||
late final NetworkClient _httpInstance = NetworkClient();
|
||||
|
||||
|
||||
@ -431,10 +431,10 @@ class SCAccountRepository implements SocialChatUserRepository {
|
||||
parm["personalPhotos"] = personalPhotos;
|
||||
}
|
||||
|
||||
final result = await http.post<SocialChatUserProfile>(
|
||||
"2fa1d4f56bb726558904ce2a50b83f96365e62b6aa808acde7b56d2d5945fbe4",
|
||||
data: parm,
|
||||
fromJson: (json) => SocialChatUserProfile.fromJson(json),
|
||||
final result = await http.put<SocialChatUserProfile>(
|
||||
"2fa1d4f56bb726558904ce2a50b83f96365e62b6aa808acde7b56d2d5945fbe4",
|
||||
data: parm,
|
||||
fromJson: (json) => SocialChatUserProfile.fromJson(json),
|
||||
);
|
||||
return result;
|
||||
}
|
||||
|
||||
@ -1,8 +1,9 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:yumi/shared/data_sources/sources/repositories/sc_user_repository_impl.dart';
|
||||
|
||||
import '../../shared/data_sources/models/enum/sc_heartbeat_status.dart';
|
||||
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 '../../shared/data_sources/models/enum/sc_heartbeat_status.dart';
|
||||
|
||||
class SCHeartbeatUtils {
|
||||
static Timer? _h;
|
||||
@ -12,23 +13,35 @@ class SCHeartbeatUtils {
|
||||
static bool _u = false;
|
||||
|
||||
///定时发送心跳
|
||||
static void scheduleHeartbeat(
|
||||
String status,
|
||||
bool upMick, {
|
||||
String? roomId,
|
||||
}) async {
|
||||
cancelAnchorTimer();
|
||||
_c = status;
|
||||
_u = upMick;
|
||||
_r = roomId;
|
||||
SCAccountRepository().heartbeat(_c, _u, roomId: _r).whenComplete(() {
|
||||
try {
|
||||
_h ??= Timer.periodic(Duration(seconds: 60), (timer) {
|
||||
SCAccountRepository().heartbeat(_c, _u, roomId: _r);
|
||||
});
|
||||
} catch (e) {}
|
||||
});
|
||||
}
|
||||
static void scheduleHeartbeat(
|
||||
String status,
|
||||
bool upMick, {
|
||||
String? roomId,
|
||||
}) async {
|
||||
cancelTimer();
|
||||
_c = status;
|
||||
_u = upMick;
|
||||
_r = roomId;
|
||||
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 {
|
||||
cancelTimer();
|
||||
} catch (_) {}
|
||||
}
|
||||
}
|
||||
|
||||
static void cancelTimer() {
|
||||
_h?.cancel();
|
||||
@ -37,18 +50,16 @@ class SCHeartbeatUtils {
|
||||
cancelAnchorTimer();
|
||||
}
|
||||
|
||||
///上麦主播发送心跳
|
||||
static void scheduleAnchorHeartbeat(String roomId) async {
|
||||
cancelAnchorTimer();
|
||||
scheduleHeartbeat(_c, true, roomId: _r);
|
||||
SCAccountRepository().anchorHeartbeat(roomId).whenComplete(() {
|
||||
_a ??= Timer.periodic(Duration(seconds: 60), (timer) {
|
||||
try {
|
||||
SCAccountRepository().anchorHeartbeat(roomId);
|
||||
} catch (e) {}
|
||||
});
|
||||
});
|
||||
}
|
||||
///上麦主播发送心跳
|
||||
static void scheduleAnchorHeartbeat(String roomId) async {
|
||||
cancelAnchorTimer();
|
||||
scheduleHeartbeat(_c, true, roomId: roomId);
|
||||
SCAccountRepository().anchorHeartbeat(roomId).whenComplete(() {
|
||||
_a ??= Timer.periodic(Duration(seconds: 60), (timer) {
|
||||
SCAccountRepository().anchorHeartbeat(roomId).catchError((_) => {});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
static void cancelAnchorTimer() {
|
||||
_a?.cancel();
|
||||
|
||||
@ -1,18 +1,17 @@
|
||||
import 'dart:async';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_screenutil/flutter_screenutil.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/business_logic/models/res/login_res.dart';
|
||||
import 'package:yumi/ui_kit/components/sc_debounce_widget.dart';
|
||||
import 'package:yumi/ui_kit/components/sc_compontent.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/services/audio/rtc_manager.dart';
|
||||
import 'package:yumi/app/constants/sc_screen.dart';
|
||||
import 'package:yumi/ui_kit/theme/socialchat_theme.dart';
|
||||
import 'dart:async';
|
||||
import 'package:flutter/material.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/data_sources/sources/local/user_manager.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_compontent.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
import 'package:yumi/shared/business_logic/models/res/join_room_res.dart';
|
||||
import 'package:yumi/services/audio/rtc_manager.dart';
|
||||
import 'package:yumi/app/constants/sc_screen.dart';
|
||||
import 'package:yumi/ui_kit/theme/socialchat_theme.dart';
|
||||
|
||||
// 默认位置
|
||||
Offset kDefaultFloatOffset = Offset(
|
||||
@ -40,11 +39,11 @@ class SCFloatIchart {
|
||||
}
|
||||
var overlayState = Overlay.of(context!);
|
||||
overlayEntry = OverlayEntry(
|
||||
builder: (context) {
|
||||
if (inLoginPage) {
|
||||
remove();
|
||||
return Container();
|
||||
} else {
|
||||
builder: (context) {
|
||||
if (SCNavigatorUtils.inLoginPage) {
|
||||
remove();
|
||||
return Container();
|
||||
} else {
|
||||
return buildToastLayout();
|
||||
}
|
||||
},
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user