修复重复登录,头像无法更换问题
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,
|
||||||
@ -44,4 +52,4 @@
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"configuration_version": "1"
|
"configuration_version": "1"
|
||||||
}
|
}
|
||||||
@ -1,11 +1,10 @@
|
|||||||
import 'dart:io';
|
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';
|
|
||||||
|
|
||||||
/// 安卓页面切换时长
|
/// 安卓页面切换时长
|
||||||
const Duration kAndroidTransitionDuration = Duration(milliseconds: 375);
|
const Duration kAndroidTransitionDuration = Duration(milliseconds: 375);
|
||||||
|
|||||||
@ -1,21 +1,18 @@
|
|||||||
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:yumi/app_localizations.dart';
|
||||||
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
import 'package:yumi/ui_kit/components/sc_compontent.dart';
|
||||||
import 'package:yumi/app_localizations.dart';
|
import 'package:yumi/ui_kit/components/text/sc_text.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/ui_kit/components/sc_tts.dart';
|
||||||
import 'package:yumi/shared/tools/sc_loading_manager.dart';
|
import 'package:yumi/shared/tools/sc_loading_manager.dart';
|
||||||
import 'package:yumi/shared/tools/sc_pick_utils.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/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';
|
|
||||||
import 'package:yumi/shared/tools/sc_date_utils.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/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';
|
||||||
@ -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/rtc_manager.dart';
|
||||||
import 'package:yumi/services/audio/rtm_manager.dart';
|
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';
|
|
||||||
|
|
||||||
///编辑个人信息
|
///编辑个人信息
|
||||||
class SCEditProfilePage extends StatefulWidget {
|
class SCEditProfilePage extends StatefulWidget {
|
||||||
@ -37,7 +33,7 @@ class SCEditProfilePage extends StatefulWidget {
|
|||||||
_SCEditProfilePageState createState() => _SCEditProfilePageState();
|
_SCEditProfilePageState createState() => _SCEditProfilePageState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _SCEditProfilePageState extends State<SCEditProfilePage> {
|
class _SCEditProfilePageState extends State<SCEditProfilePage> {
|
||||||
///默认女
|
///默认女
|
||||||
int type = 0;
|
int type = 0;
|
||||||
DateTime birthdayDate = DateTime(2006);
|
DateTime birthdayDate = DateTime(2006);
|
||||||
@ -488,7 +484,7 @@ class _SCEditProfilePageState extends State<SCEditProfilePage> {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
DateTime _getBefor18() {
|
DateTime _getBefor18() {
|
||||||
DateTime currentDate = DateTime.now();
|
DateTime currentDate = DateTime.now();
|
||||||
DateTime eighteenYearsAgo = DateTime(
|
DateTime eighteenYearsAgo = DateTime(
|
||||||
currentDate.year - 18,
|
currentDate.year - 18,
|
||||||
@ -500,11 +496,31 @@ class _SCEditProfilePageState extends State<SCEditProfilePage> {
|
|||||||
currentDate.millisecond,
|
currentDate.millisecond,
|
||||||
currentDate.microsecond,
|
currentDate.microsecond,
|
||||||
);
|
);
|
||||||
return eighteenYearsAgo;
|
return eighteenYearsAgo;
|
||||||
}
|
}
|
||||||
|
|
||||||
///提交数据
|
String? _preferNonEmpty(String? primary, String? fallback) {
|
||||||
void _submitUserProfile() async {
|
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) {
|
if (nicknameController.text.isEmpty) {
|
||||||
SCTts.show(SCAppLocalizations.of(context)!.pleaseEnterNickname);
|
SCTts.show(SCAppLocalizations.of(context)!.pleaseEnterNickname);
|
||||||
return;
|
return;
|
||||||
@ -539,22 +555,67 @@ class _SCEditProfilePageState extends State<SCEditProfilePage> {
|
|||||||
context,
|
context,
|
||||||
listen: false,
|
listen: false,
|
||||||
).uid;
|
).uid;
|
||||||
SocialChatLoginRes user = await SCAccountRepository().regist(
|
SocialChatLoginRes user = await SCAccountRepository().regist(
|
||||||
authType,
|
authType,
|
||||||
idToken,
|
idToken,
|
||||||
userProvider!.editUser!,
|
userProvider!.editUser!,
|
||||||
);
|
);
|
||||||
if (!mounted) {
|
final submittedProfile = userProvider?.editUser;
|
||||||
return;
|
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(
|
await Provider.of<RtcProvider>(context, listen: false).resetLocalRoomState(
|
||||||
fallbackRtmProvider: Provider.of<RtmProvider>(context, listen: false),
|
fallbackRtmProvider: Provider.of<RtmProvider>(context, listen: false),
|
||||||
);
|
);
|
||||||
if (!mounted) {
|
if (!mounted) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
AccountStorage().setCurrentUser(user);
|
AccountStorage().setCurrentUser(user);
|
||||||
SCLoadingManager.hide();
|
userProvider?.syncCurrentUserProfile(user.userProfile);
|
||||||
SCNavigatorUtils.push(context, SCRoutes.home, clearStack: true);
|
SCLoadingManager.hide();
|
||||||
}
|
SCNavigatorUtils.push(context, SCRoutes.home, clearStack: true);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -323,24 +323,32 @@ class _EditUserInfoPage2State extends State<EditUserInfoPage2>
|
|||||||
int bTime = DateTime.now().millisecondsSinceEpoch;
|
int bTime = DateTime.now().millisecondsSinceEpoch;
|
||||||
if (bTime - sTime > 5000) {
|
if (bTime - sTime > 5000) {
|
||||||
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,
|
||||||
age: age,
|
age: age,
|
||||||
bornDay: birthdayDate?.day,
|
bornDay: birthdayDate?.day,
|
||||||
bornMonth: birthdayDate?.month,
|
bornMonth: birthdayDate?.month,
|
||||||
bornYear: birthdayDate?.year,
|
bornYear: birthdayDate?.year,
|
||||||
hobby: hobby,
|
hobby: hobby,
|
||||||
autograph: autograph,
|
autograph: autograph,
|
||||||
countryId: country?.id,
|
countryId: country?.id,
|
||||||
);
|
);
|
||||||
Provider.of<RtcProvider>(context, listen: false).needUpDataUserInfo =
|
if (!mounted) {
|
||||||
true;
|
SCLoadingManager.hide();
|
||||||
SCTts.show(SCAppLocalizations.of(context)!.operationSuccessful);
|
return;
|
||||||
} catch (e) {
|
}
|
||||||
|
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());
|
debugPrint(e.toString());
|
||||||
SCLoadingManager.hide();
|
SCLoadingManager.hide();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -60,19 +60,19 @@ class _MePage2State extends State<MePage2> {
|
|||||||
} catch (_) {}
|
} catch (_) {}
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return SafeArea(
|
return SafeArea(
|
||||||
top: true,
|
top: true,
|
||||||
bottom: false,
|
bottom: false,
|
||||||
child: Consumer<SocialChatUserProfileManager>(
|
child: Consumer<SocialChatUserProfileManager>(
|
||||||
builder: (context, profileManager, child) {
|
builder: (context, profileManager, child) {
|
||||||
return SingleChildScrollView(
|
return SingleChildScrollView(
|
||||||
physics: const BouncingScrollPhysics(),
|
physics: const BouncingScrollPhysics(),
|
||||||
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),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|||||||
@ -56,23 +56,36 @@ class SocialChatUserProfileManager extends ChangeNotifier {
|
|||||||
editUser!.setCountryName = country.countryName!;
|
editUser!.setCountryName = country.countryName!;
|
||||||
}
|
}
|
||||||
|
|
||||||
void resetEditUserData() {
|
void resetEditUserData() {
|
||||||
editUser = null;
|
editUser = null;
|
||||||
notifyListeners();
|
notifyListeners();
|
||||||
}
|
}
|
||||||
|
|
||||||
Future fetchUserProfileData({
|
void syncCurrentUserProfile(SocialChatUserProfile? profile) {
|
||||||
bool loadGuardCount = true,
|
if (profile == null) {
|
||||||
bool refreshFamilyData = false,
|
return;
|
||||||
}) async {
|
}
|
||||||
var us = AccountStorage().getCurrentUser();
|
userProfile = profile;
|
||||||
String userId = us?.userProfile?.id ?? "";
|
final currentUser = AccountStorage().getCurrentUser();
|
||||||
var userInfo = await SCAccountRepository().loadUserInfo(userId);
|
if (currentUser != null) {
|
||||||
userProfile = userInfo;
|
currentUser.setUserProfile(profile);
|
||||||
us?.setUserProfile(userInfo);
|
AccountStorage().setCurrentUser(currentUser);
|
||||||
AccountStorage().setCurrentUser(us!);
|
}
|
||||||
notifyListeners();
|
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;
|
SCUserIdentityRes? userIdentity;
|
||||||
|
|
||||||
|
|||||||
@ -1,13 +1,13 @@
|
|||||||
// api.dart
|
// api.dart
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'package:dio/dio.dart';
|
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';
|
||||||
import 'package:yumi/modules/auth/login_route.dart';
|
import 'package:yumi/modules/auth/login_route.dart';
|
||||||
import 'package:yumi/app/routes/sc_fluro_navigator.dart';
|
import 'package:yumi/app/routes/sc_fluro_navigator.dart';
|
||||||
import 'package:yumi/shared/tools/sc_loading_manager.dart';
|
import 'package:yumi/shared/tools/sc_loading_manager.dart';
|
||||||
@ -20,9 +20,90 @@ export 'package:dio/dio.dart';
|
|||||||
|
|
||||||
_parseAndDecode(String response) => jsonDecode(response);
|
_parseAndDecode(String response) => jsonDecode(response);
|
||||||
|
|
||||||
parseJson(String text) => compute(_parseAndDecode, text);
|
parseJson(String text) => compute(_parseAndDecode, text);
|
||||||
|
|
||||||
class BaseNetworkClient {
|
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;
|
final Dio dio;
|
||||||
|
|
||||||
BaseNetworkClient() : dio = Dio() {
|
BaseNetworkClient() : dio = Dio() {
|
||||||
@ -174,9 +255,9 @@ class BaseNetworkClient {
|
|||||||
error: '业务错误: ${baseResponse.errorMsg}',
|
error: '业务错误: ${baseResponse.errorMsg}',
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} 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,11 +265,11 @@ 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:
|
||||||
return DioException(requestOptions: e.requestOptions, error: '连接超时');
|
return DioException(requestOptions: e.requestOptions, error: '连接超时');
|
||||||
case DioExceptionType.sendTimeout:
|
case DioExceptionType.sendTimeout:
|
||||||
return DioException(requestOptions: e.requestOptions, error: '发送超时');
|
return DioException(requestOptions: e.requestOptions, error: '发送超时');
|
||||||
case DioExceptionType.receiveTimeout:
|
case DioExceptionType.receiveTimeout:
|
||||||
@ -207,16 +288,17 @@ class BaseNetworkClient {
|
|||||||
replace: false,
|
replace: false,
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
} 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")) {
|
||||||
BuildContext? context = navigatorKey.currentContext;
|
BuildContext? context = navigatorKey.currentContext;
|
||||||
if (context != null) {
|
if (context != null) {
|
||||||
@ -231,11 +313,11 @@ class BaseNetworkClient {
|
|||||||
response: e.response,
|
response: e.response,
|
||||||
error: '服务器错误: ${e.response?.data["errorCode"]}',
|
error: '服务器错误: ${e.response?.data["errorCode"]}',
|
||||||
);
|
);
|
||||||
case DioExceptionType.cancel:
|
case DioExceptionType.cancel:
|
||||||
return DioException(requestOptions: e.requestOptions, error: 'Cancel');
|
return DioException(requestOptions: e.requestOptions, error: 'Cancel');
|
||||||
default:
|
default:
|
||||||
return DioException(
|
return DioException(
|
||||||
requestOptions: e.requestOptions,
|
requestOptions: e.requestOptions,
|
||||||
error: 'Net fail',
|
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/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,10 +431,10 @@ 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),
|
||||||
);
|
);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,8 +1,9 @@
|
|||||||
import 'dart:async';
|
import 'dart:async';
|
||||||
|
|
||||||
import 'package:yumi/shared/data_sources/sources/repositories/sc_user_repository_impl.dart';
|
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';
|
|
||||||
|
import '../../shared/data_sources/models/enum/sc_heartbeat_status.dart';
|
||||||
|
|
||||||
class SCHeartbeatUtils {
|
class SCHeartbeatUtils {
|
||||||
static Timer? _h;
|
static Timer? _h;
|
||||||
@ -12,23 +13,35 @@ class SCHeartbeatUtils {
|
|||||||
static bool _u = false;
|
static bool _u = false;
|
||||||
|
|
||||||
///定时发送心跳
|
///定时发送心跳
|
||||||
static void scheduleHeartbeat(
|
static void scheduleHeartbeat(
|
||||||
String status,
|
String status,
|
||||||
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) {
|
||||||
try {
|
return;
|
||||||
_h ??= Timer.periodic(Duration(seconds: 60), (timer) {
|
}
|
||||||
SCAccountRepository().heartbeat(_c, _u, roomId: _r);
|
try {
|
||||||
});
|
await SCAccountRepository().heartbeat(_c, _u, roomId: _r);
|
||||||
} catch (e) {}
|
_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() {
|
static void cancelTimer() {
|
||||||
_h?.cancel();
|
_h?.cancel();
|
||||||
@ -37,18 +50,16 @@ class SCHeartbeatUtils {
|
|||||||
cancelAnchorTimer();
|
cancelAnchorTimer();
|
||||||
}
|
}
|
||||||
|
|
||||||
///上麦主播发送心跳
|
///上麦主播发送心跳
|
||||||
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) {}
|
});
|
||||||
});
|
}
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
static void cancelAnchorTimer() {
|
static void cancelAnchorTimer() {
|
||||||
_a?.cancel();
|
_a?.cancel();
|
||||||
|
|||||||
@ -1,18 +1,17 @@
|
|||||||
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';
|
import 'package:yumi/ui_kit/theme/socialchat_theme.dart';
|
||||||
import 'package:yumi/ui_kit/theme/socialchat_theme.dart';
|
|
||||||
|
|
||||||
// 默认位置
|
// 默认位置
|
||||||
Offset kDefaultFloatOffset = Offset(
|
Offset kDefaultFloatOffset = Offset(
|
||||||
@ -40,11 +39,11 @@ 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 {
|
||||||
return buildToastLayout();
|
return buildToastLayout();
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user