重构事件信息页面,移除不必要的加载状态和错误消息字段,简化状态管理逻辑;在扫码页面中增强选手信息查询功能,添加加载提示和错误处理。

This commit is contained in:
2026-07-17 15:17:08 +08:00
parent 62d717c3ee
commit e08a8ed26b
4 changed files with 46 additions and 54 deletions
+3 -13
View File
@@ -11,8 +11,6 @@ import 'package:recording_tool/shared/widgets/widgets.dart';
class EventInfoPage extends ConsumerStatefulWidget {
const EventInfoPage({super.key, required this.playerId});
final String playerId;
static const mockRtmpUrl =
'rtmp://192.168.1.245:19090/蔡依婷vs夏志豪_空中格斗赛_高中组/蔡依婷vs夏志豪_空中格斗赛_高中组';
@override
ConsumerState<EventInfoPage> createState() => _EventInfoPageState();
@@ -22,15 +20,11 @@ class _EventInfoPageState extends ConsumerState<EventInfoPage> {
@override
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((_) {
if (!mounted) return;
ref.read(eventInfoProvider.notifier).loadRegistrationList();
});
}
Future<void> onItemTap(EventRegistrationItem item) async {
debugPrint('item tapped: ${item.itemName}');
await ref.read(eventInfoProvider.notifier).requestStreamKey(item);
// debugPrint('item tapped: ${item.itemName}');
// await ref.read(eventInfoProvider.notifier).requestStreamKey(item);
if (!mounted) return;
// final profile = ref.read(eventInfoProvider).profile;
@@ -182,17 +176,13 @@ class _ScheduleList extends StatelessWidget {
@override
Widget build(BuildContext context) {
if (state.isLoading) {
return const Center(child: CircularProgressIndicator());
}
if (state.items.isEmpty) {
return Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
Text(
state.errorMessage ?? '暂无赛事报名信息',
'暂无赛事报名信息',
textAlign: TextAlign.center,
style: TextStyle(fontSize: 18.sp, color: const Color(0xFF2F2F2F)),
),
@@ -2,17 +2,13 @@ import 'package:recording_tool/features/events/model/model_event_info.dart';
class EventInfoState {
const EventInfoState({
this.isLoading = false,
this.isRequestingStreamKey = false,
this.errorMessage,
this.profile = const EventProfile(name: '', phone: '', eventTitle: '赛事信息'),
this.total = 0,
this.items = const [],
});
final bool isLoading;
final bool isRequestingStreamKey;
final String? errorMessage;
final EventProfile profile;
final int total;
final List<EventRegistrationItem> items;
@@ -21,21 +17,14 @@ class EventInfoState {
items.isEmpty ? profile.eventTitle : items.first.eventName;
EventInfoState copyWith({
bool? isLoading,
bool? isRequestingStreamKey,
String? errorMessage,
bool clearErrorMessage = false,
EventProfile? profile,
int? total,
List<EventRegistrationItem>? items,
}) {
return EventInfoState(
isLoading: isLoading ?? this.isLoading,
isRequestingStreamKey:
isRequestingStreamKey ?? this.isRequestingStreamKey,
errorMessage: clearErrorMessage
? null
: (errorMessage ?? this.errorMessage),
profile: profile ?? this.profile,
total: total ?? this.total,
items: items ?? this.items,
@@ -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 获取失败');
}
}
}