mirror of
https://github.com/StarCitizenToolBox/app.git
synced 2026-01-15 12:40:28 +00:00
feat: Add user profile refresh
This commit is contained in:
parent
724f7d8242
commit
1d59acff2d
@ -277,6 +277,24 @@ class PartyRoom extends _$PartyRoom {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// 刷新用户资料
|
||||||
|
Future<void> refreshUserProfile() async {
|
||||||
|
try {
|
||||||
|
final client = state.client.authClient;
|
||||||
|
if (client == null) throw Exception('Not connected to server');
|
||||||
|
|
||||||
|
final response = await client.refreshUserProfile(auth.RefreshUserProfileRequest(), options: getAuthCallOptions());
|
||||||
|
|
||||||
|
if (response.success && response.hasUserInfo()) {
|
||||||
|
state = state.copyWith(auth: state.auth.copyWith(userInfo: response.userInfo));
|
||||||
|
dPrint('[PartyRoom] User profile refreshed: ${response.userInfo.gameUserId}');
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
dPrint('[PartyRoom] RefreshUserProfile error: $e');
|
||||||
|
rethrow;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// ========== 房间相关方法 ==========
|
// ========== 房间相关方法 ==========
|
||||||
|
|
||||||
/// 加载标签和信号类型
|
/// 加载标签和信号类型
|
||||||
|
|||||||
@ -5,6 +5,7 @@ import 'package:starcitizen_doctor/provider/party_room.dart';
|
|||||||
import 'package:starcitizen_doctor/ui/party_room/party_room_ui_model.dart';
|
import 'package:starcitizen_doctor/ui/party_room/party_room_ui_model.dart';
|
||||||
import 'package:starcitizen_doctor/ui/party_room/utils/party_room_utils.dart';
|
import 'package:starcitizen_doctor/ui/party_room/utils/party_room_utils.dart';
|
||||||
import 'package:starcitizen_doctor/widgets/widgets.dart';
|
import 'package:starcitizen_doctor/widgets/widgets.dart';
|
||||||
|
import 'package:grpc/grpc.dart';
|
||||||
|
|
||||||
class UserAvatarWidget extends HookConsumerWidget {
|
class UserAvatarWidget extends HookConsumerWidget {
|
||||||
final VoidCallback onTapNavigateToPartyRoom;
|
final VoidCallback onTapNavigateToPartyRoom;
|
||||||
@ -85,6 +86,14 @@ class UserAvatarWidget extends HookConsumerWidget {
|
|||||||
barrierDismissible: true,
|
barrierDismissible: true,
|
||||||
barrierColor: Colors.transparent,
|
barrierColor: Colors.transparent,
|
||||||
builder: (BuildContext dialogContext) {
|
builder: (BuildContext dialogContext) {
|
||||||
|
return Consumer(
|
||||||
|
builder: (context, ref, child) {
|
||||||
|
final partyRoomState = ref.watch(partyRoomProvider);
|
||||||
|
final userInfo = partyRoomState.auth.userInfo;
|
||||||
|
final displayUserName = userInfo?.gameUserId ?? userName;
|
||||||
|
final displayAvatarUrl = PartyRoomUtils.getAvatarUrl(userInfo?.avatarUrl);
|
||||||
|
final displayEnlistedDate = userInfo?.enlistedDate ?? enlistedDate;
|
||||||
|
|
||||||
return Stack(
|
return Stack(
|
||||||
children: [
|
children: [
|
||||||
// 透明遮罩,点击关闭
|
// 透明遮罩,点击关闭
|
||||||
@ -99,13 +108,15 @@ class UserAvatarWidget extends HookConsumerWidget {
|
|||||||
child: Container(
|
child: Container(
|
||||||
width: 360,
|
width: 360,
|
||||||
decoration: BoxDecoration(
|
decoration: BoxDecoration(
|
||||||
color: FluentTheme
|
color: FluentTheme.of(context).micaBackgroundColor,
|
||||||
.of(context)
|
|
||||||
.micaBackgroundColor,
|
|
||||||
borderRadius: BorderRadius.circular(8),
|
borderRadius: BorderRadius.circular(8),
|
||||||
border: Border.all(color: Colors.white.withValues(alpha: .1), width: 1),
|
border: Border.all(color: Colors.white.withValues(alpha: .1), width: 1),
|
||||||
boxShadow: [
|
boxShadow: [
|
||||||
BoxShadow(color: Colors.black.withValues(alpha: .3), blurRadius: 20, offset: const Offset(0, 8)),
|
BoxShadow(
|
||||||
|
color: Colors.black.withValues(alpha: .3),
|
||||||
|
blurRadius: 20,
|
||||||
|
offset: const Offset(0, 8),
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
child: Padding(
|
child: Padding(
|
||||||
@ -123,8 +134,8 @@ class UserAvatarWidget extends HookConsumerWidget {
|
|||||||
decoration: BoxDecoration(color: Colors.blue, borderRadius: BorderRadius.circular(24)),
|
decoration: BoxDecoration(color: Colors.blue, borderRadius: BorderRadius.circular(24)),
|
||||||
child: ClipRRect(
|
child: ClipRRect(
|
||||||
borderRadius: BorderRadius.circular(24),
|
borderRadius: BorderRadius.circular(24),
|
||||||
child: avatarUrl != null
|
child: displayAvatarUrl != null
|
||||||
? CacheNetImage(url: avatarUrl, fit: BoxFit.cover)
|
? CacheNetImage(url: displayAvatarUrl, fit: BoxFit.cover)
|
||||||
: const Center(child: Icon(FluentIcons.contact, size: 24, color: Colors.white)),
|
: const Center(child: Icon(FluentIcons.contact, size: 24, color: Colors.white)),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -134,14 +145,14 @@ class UserAvatarWidget extends HookConsumerWidget {
|
|||||||
crossAxisAlignment: CrossAxisAlignment.start,
|
crossAxisAlignment: CrossAxisAlignment.start,
|
||||||
children: [
|
children: [
|
||||||
Text(
|
Text(
|
||||||
userName,
|
displayUserName,
|
||||||
style: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
|
style: const TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
|
||||||
maxLines: 1,
|
maxLines: 1,
|
||||||
overflow: TextOverflow.ellipsis,
|
overflow: TextOverflow.ellipsis,
|
||||||
),
|
),
|
||||||
const SizedBox(height: 4),
|
const SizedBox(height: 4),
|
||||||
Text(
|
Text(
|
||||||
'注册时间:${PartyRoomUtils.formatDateTime(enlistedDate)}',
|
'注册时间:${PartyRoomUtils.formatDateTime(displayEnlistedDate)}',
|
||||||
style: TextStyle(fontSize: 12, color: Colors.white.withValues(alpha: .6)),
|
style: TextStyle(fontSize: 12, color: Colors.white.withValues(alpha: .6)),
|
||||||
),
|
),
|
||||||
],
|
],
|
||||||
@ -152,18 +163,51 @@ class UserAvatarWidget extends HookConsumerWidget {
|
|||||||
const SizedBox(height: 16),
|
const SizedBox(height: 16),
|
||||||
const Divider(),
|
const Divider(),
|
||||||
const SizedBox(height: 8),
|
const SizedBox(height: 8),
|
||||||
|
// 按钮组
|
||||||
|
Row(
|
||||||
|
children: [
|
||||||
|
// 刷新按钮
|
||||||
|
Expanded(
|
||||||
|
child: Tooltip(
|
||||||
|
message: '每小时仅可刷新一次',
|
||||||
|
child: FilledButton(
|
||||||
|
onPressed: () async {
|
||||||
|
try {
|
||||||
|
await ref.read(partyRoomProvider.notifier).refreshUserProfile();
|
||||||
|
if (context.mounted) {
|
||||||
|
showToast(context, '刷新成功');
|
||||||
|
}
|
||||||
|
} catch (e) {
|
||||||
|
if (context.mounted) {
|
||||||
|
if (e is GrpcError && e.code == StatusCode.resourceExhausted) {
|
||||||
|
showToast(context, '资料刷新过于频繁,请一小时后再试');
|
||||||
|
} else {
|
||||||
|
showToast(context, '刷新失败: $e');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
child: const Text('刷新资料'),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
const SizedBox(width: 8),
|
||||||
// 注销按钮
|
// 注销按钮
|
||||||
SizedBox(
|
Expanded(
|
||||||
width: double.infinity,
|
|
||||||
child: FilledButton(
|
child: FilledButton(
|
||||||
onPressed: () async {
|
onPressed: () async {
|
||||||
Navigator.of(dialogContext).pop();
|
Navigator.of(dialogContext).pop();
|
||||||
await _handleUnregister(context, ref);
|
await _handleUnregister(context, ref);
|
||||||
},
|
},
|
||||||
style: ButtonStyle(backgroundColor: WidgetStateProperty.all(Colors.red)),
|
style: ButtonStyle(backgroundColor: WidgetStateProperty.all(Colors.red)),
|
||||||
child: Text(S.current.user_action_unregister, style: const TextStyle(color: Colors.white)),
|
child: Text(
|
||||||
|
S.current.user_action_unregister,
|
||||||
|
style: const TextStyle(color: Colors.white),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
],
|
],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
@ -173,6 +217,8 @@ class UserAvatarWidget extends HookConsumerWidget {
|
|||||||
);
|
);
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<void> _handleUnregister(BuildContext context, WidgetRef ref) async {
|
Future<void> _handleUnregister(BuildContext context, WidgetRef ref) async {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user