重构事件信息页面,移除不必要的加载状态和错误消息字段,简化状态管理逻辑;在扫码页面中增强选手信息查询功能,添加加载提示和错误处理。
This commit is contained in:
@@ -5,6 +5,7 @@ import 'package:recording_tool/core/network/api_exception.dart';
|
||||
import 'package:recording_tool/features/events/model/model_event_info.dart';
|
||||
import 'package:recording_tool/features/events/server/server_events.dart';
|
||||
import 'package:recording_tool/features/events/state/state_event_info.dart';
|
||||
import 'package:recording_tool/shared/widgets/app_toast.dart';
|
||||
|
||||
final eventInfoProvider =
|
||||
StateNotifierProvider<EventInfoViewModel, EventInfoState>((ref) {
|
||||
@@ -15,44 +16,42 @@ class EventInfoViewModel extends StateNotifier<EventInfoState> {
|
||||
EventInfoViewModel(this._ref) : super(const EventInfoState());
|
||||
|
||||
static const defaultRegistrationRequest = PlayerRegistrationListReq(
|
||||
userId: '74300708945530955',
|
||||
userId: '',
|
||||
status: '',
|
||||
);
|
||||
|
||||
static const _fallbackEventId = '10224';
|
||||
static const _fallbackItemId = '2318';
|
||||
static const _fallbackStreamUserId = '74300708949725207';
|
||||
static const _fallbackEventId = '';
|
||||
static const _fallbackItemId = '';
|
||||
static const _fallbackStreamUserId = '';
|
||||
|
||||
final Ref _ref;
|
||||
|
||||
Future<void> loadRegistrationList({
|
||||
Future<bool> loadRegistrationList({
|
||||
PlayerRegistrationListReq request = defaultRegistrationRequest,
|
||||
}) async {
|
||||
state = state.copyWith(isLoading: true, clearErrorMessage: true);
|
||||
if (request.userId.isEmpty) {
|
||||
return false;
|
||||
}
|
||||
try {
|
||||
final result = await _ref
|
||||
.read(eventsServerProvider)
|
||||
.fetchPlayerRegistrationList(request);
|
||||
debugPrint('报名列表请求成功: $result');
|
||||
state = state.copyWith(
|
||||
isLoading: false,
|
||||
profile: result.toProfile(),
|
||||
total: result.total,
|
||||
items: result.items,
|
||||
clearErrorMessage: true,
|
||||
);
|
||||
} on ApiException catch (error) {
|
||||
state = state.copyWith(isLoading: false, errorMessage: error.message);
|
||||
return true;
|
||||
} catch (error) {
|
||||
debugPrint('报名列表请求失败: $error');
|
||||
state = state.copyWith(isLoading: false, errorMessage: '报名列表加载失败');
|
||||
AppToast.show('报名列表加载失败');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> requestStreamKey(EventRegistrationItem item) async {
|
||||
state = state.copyWith(
|
||||
isRequestingStreamKey: true,
|
||||
clearErrorMessage: true,
|
||||
);
|
||||
state = state.copyWith(isRequestingStreamKey: true);
|
||||
final req = StreamKeyReq(
|
||||
eventId: item.eventId.isNotEmpty ? item.eventId : _fallbackEventId,
|
||||
itemId: item.itemId.isNotEmpty ? item.itemId : _fallbackItemId,
|
||||
@@ -64,22 +63,15 @@ class EventInfoViewModel extends StateNotifier<EventInfoState> {
|
||||
.read(eventsServerProvider)
|
||||
.fetchStreamKey(req);
|
||||
debugPrint('推流 Key 接口响应: $response');
|
||||
state = state.copyWith(
|
||||
isRequestingStreamKey: false,
|
||||
clearErrorMessage: true,
|
||||
);
|
||||
state = state.copyWith(isRequestingStreamKey: false);
|
||||
} on ApiException catch (error) {
|
||||
debugPrint('推流 Key 接口请求失败: ${error.message}');
|
||||
state = state.copyWith(
|
||||
isRequestingStreamKey: false,
|
||||
errorMessage: error.message,
|
||||
);
|
||||
state = state.copyWith(isRequestingStreamKey: false);
|
||||
AppToast.show(error.message);
|
||||
} catch (error) {
|
||||
debugPrint('推流 Key 接口请求失败: $error');
|
||||
state = state.copyWith(
|
||||
isRequestingStreamKey: false,
|
||||
errorMessage: '推流 Key 获取失败',
|
||||
);
|
||||
state = state.copyWith(isRequestingStreamKey: false);
|
||||
AppToast.show('推流 Key 获取失败');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user