更新 devtools_options.yaml 以启用 riverpod 和 shared_preferences 扩展;更新 AuthApi 枚举以添加 playerRegistrationList API;重构 Auth 页面以在用户已登录时直接导航到扫码页面;重构 EventInfoPage 以使用新的状态管理和加载赛事报名信息;更新扫码页面以导航到 EventInfoPage。
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_riverpod/legacy.dart';
|
||||
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';
|
||||
|
||||
final eventInfoProvider =
|
||||
StateNotifierProvider<EventInfoViewModel, EventInfoState>((ref) {
|
||||
return EventInfoViewModel(ref);
|
||||
});
|
||||
|
||||
class EventInfoViewModel extends StateNotifier<EventInfoState> {
|
||||
EventInfoViewModel(this._ref) : super(const EventInfoState());
|
||||
|
||||
static const defaultRegistrationRequest = PlayerRegistrationListReq(
|
||||
userId: '74300708945530955',
|
||||
status: '',
|
||||
);
|
||||
|
||||
static const _fallbackEventId = '10224';
|
||||
static const _fallbackItemId = '2318';
|
||||
static const _fallbackStreamUserId = '74300708949725207';
|
||||
|
||||
final Ref _ref;
|
||||
|
||||
Future<void> loadRegistrationList({
|
||||
PlayerRegistrationListReq request = defaultRegistrationRequest,
|
||||
}) async {
|
||||
state = state.copyWith(isLoading: true, clearErrorMessage: true);
|
||||
try {
|
||||
final result = await _ref
|
||||
.read(eventsServerProvider)
|
||||
.fetchPlayerRegistrationList(request);
|
||||
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);
|
||||
} catch (error) {
|
||||
debugPrint('报名列表请求失败: $error');
|
||||
state = state.copyWith(isLoading: false, errorMessage: '报名列表加载失败');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> requestStreamKey(EventRegistrationItem item) async {
|
||||
state = state.copyWith(
|
||||
isRequestingStreamKey: true,
|
||||
clearErrorMessage: true,
|
||||
);
|
||||
final req = StreamKeyReq(
|
||||
eventId: item.eventId.isNotEmpty ? item.eventId : _fallbackEventId,
|
||||
itemId: item.itemId.isNotEmpty ? item.itemId : _fallbackItemId,
|
||||
userId: item.userId.isNotEmpty ? item.userId : _fallbackStreamUserId,
|
||||
);
|
||||
|
||||
try {
|
||||
final response = await _ref
|
||||
.read(eventsServerProvider)
|
||||
.fetchStreamKey(req);
|
||||
debugPrint('推流 Key 接口响应: $response');
|
||||
state = state.copyWith(
|
||||
isRequestingStreamKey: false,
|
||||
clearErrorMessage: true,
|
||||
);
|
||||
} on ApiException catch (error) {
|
||||
debugPrint('推流 Key 接口请求失败: ${error.message}');
|
||||
state = state.copyWith(
|
||||
isRequestingStreamKey: false,
|
||||
errorMessage: error.message,
|
||||
);
|
||||
} catch (error) {
|
||||
debugPrint('推流 Key 接口请求失败: $error');
|
||||
state = state.copyWith(
|
||||
isRequestingStreamKey: false,
|
||||
errorMessage: '推流 Key 获取失败',
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user